telefy 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +2 -2
- data/lib/telefy/cli.rb +5 -8
- data/lib/telefy/client.rb +18 -9
- data/lib/telefy/config.rb +2 -1
- data/lib/telefy/version.rb +1 -1
- data/lib/telefy.rb +1 -2
- data/sig/telefy.rbs +0 -1
- metadata +3 -6
- data/CLAUDE.md +0 -31
- data/CODE_OF_CONDUCT.md +0 -10
- data/Rakefile +0 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3eda1c537cc2f6cb96f25345e64a26f2970be86de456dda89589065e974e8af
|
|
4
|
+
data.tar.gz: daf415beee8dd9326e158bc5bede27afec807f1ac6df2b06cd57b227d25562c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7356a618557e10de7cf32c604b78d19892eb3303f47a75d53dcdeb56f376f56e0e6787e5567a2384d38218c863c785cee1f1d73cef8bfe5ed226066e5527557b
|
|
7
|
+
data.tar.gz: 1bf775370ffa1b25c9f151389e9ae84feb15067810e8cd428055080ebc296a38e6f9b6de431e5a7f073ea719ae6e674793f0389483924ab043860dad330e6725
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.2.0] - 2026-11-26
|
|
4
|
+
|
|
5
|
+
- Require Ruby 3.4 or later
|
|
6
|
+
- Save the config file readable by its owner only (`0600`)
|
|
7
|
+
- Show API failures as `Telegram API: <code> <description>`, with the description Telegram returns and never the raw response body
|
|
8
|
+
- Print CLI errors without a stack trace
|
|
9
|
+
- Report API failures when resolving the chat ID; before, any failure said "No messages found"
|
|
10
|
+
- Resolve the chat ID from the first update that has a message
|
|
11
|
+
- Package only the library, the executable, the signatures and the documents
|
|
12
|
+
|
|
3
13
|
## [0.1.0] - 2026-02-26
|
|
4
14
|
|
|
5
15
|
- Initial release
|
data/README.md
CHANGED
|
@@ -17,7 +17,7 @@ gem install telefy
|
|
|
17
17
|
telefy --setup
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
3.
|
|
20
|
+
3. Open your bot in Telegram and press **Start** (or send `/start`).
|
|
21
21
|
4. Send your first message:
|
|
22
22
|
|
|
23
23
|
```bash
|
|
@@ -48,7 +48,7 @@ Stored at `~/.config/telefy/config.yml` (respects `XDG_CONFIG_HOME`):
|
|
|
48
48
|
|
|
49
49
|
```yaml
|
|
50
50
|
bot_token: "123456:ABC-DEF..."
|
|
51
|
-
chat_id:
|
|
51
|
+
chat_id: 789012345
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
## Development
|
data/lib/telefy/cli.rb
CHANGED
|
@@ -21,6 +21,8 @@ module Telefy
|
|
|
21
21
|
when "--help", nil then puts USAGE
|
|
22
22
|
else send_message(@argv.join(" "))
|
|
23
23
|
end
|
|
24
|
+
rescue Error => error
|
|
25
|
+
abort error.message
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
private
|
|
@@ -35,15 +37,10 @@ module Telefy
|
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
def send_message(text)
|
|
38
|
-
|
|
40
|
+
chat_id_was_saved = @config.chat_id
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
@config.chat_id = chat_id
|
|
43
|
-
puts "Chat ID resolved and saved: #{chat_id}"
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
client.send_message(chat_id: @config.chat_id, text: text)
|
|
42
|
+
Telefy.send_message(text, config: @config)
|
|
43
|
+
puts "Chat ID resolved and saved: #{@config.chat_id}" unless chat_id_was_saved
|
|
47
44
|
end
|
|
48
45
|
end
|
|
49
46
|
end
|
data/lib/telefy/client.rb
CHANGED
|
@@ -13,23 +13,32 @@ module Telefy
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def send_message(chat_id:, text:)
|
|
16
|
-
|
|
17
|
-
raise Error, "Failed to send message: #{response.body}" unless response.is_a?(Net::HTTPSuccess)
|
|
18
|
-
|
|
19
|
-
JSON.parse(response.body)
|
|
16
|
+
parse(post("sendMessage", chat_id: chat_id, text: text))
|
|
20
17
|
end
|
|
21
18
|
|
|
22
19
|
def resolve_chat_id
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
raise Error, "No messages found. Message your bot first, then retry." unless chat
|
|
20
|
+
updates = parse(Net::HTTP.get_response(api_uri("getUpdates"))).fetch("result")
|
|
21
|
+
chat_id = updates.filter_map { |update| update.dig("message", "chat", "id") }.first
|
|
22
|
+
raise Error, "No messages found. Message your bot first, then retry." unless chat_id
|
|
27
23
|
|
|
28
|
-
|
|
24
|
+
chat_id
|
|
29
25
|
end
|
|
30
26
|
|
|
31
27
|
private
|
|
32
28
|
|
|
29
|
+
def parse(response)
|
|
30
|
+
body = parse_json(response.body)
|
|
31
|
+
return body if body && response.is_a?(Net::HTTPSuccess)
|
|
32
|
+
|
|
33
|
+
raise Error, "Telegram API: #{response.code} #{body&.dig("description") || response.message}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def parse_json(text)
|
|
37
|
+
Hash.try_convert(JSON.parse(text))
|
|
38
|
+
rescue JSON::ParserError, TypeError
|
|
39
|
+
nil
|
|
40
|
+
end
|
|
41
|
+
|
|
33
42
|
def post(method, params)
|
|
34
43
|
Net::HTTP.post_form(api_uri(method), params)
|
|
35
44
|
end
|
data/lib/telefy/config.rb
CHANGED
|
@@ -22,7 +22,8 @@ module Telefy
|
|
|
22
22
|
|
|
23
23
|
def save(data)
|
|
24
24
|
FileUtils.mkdir_p(File.dirname(path))
|
|
25
|
-
File.write(path, YAML.dump(data.transform_keys(&:to_s)))
|
|
25
|
+
File.write(path, YAML.dump(data.transform_keys(&:to_s)), perm: 0o600)
|
|
26
|
+
File.chmod(0o600, path)
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
def bot_token
|
data/lib/telefy/version.rb
CHANGED
data/lib/telefy.rb
CHANGED
|
@@ -12,8 +12,7 @@ module Telefy
|
|
|
12
12
|
client = Client.new(config.bot_token)
|
|
13
13
|
|
|
14
14
|
unless config.chat_id
|
|
15
|
-
chat_id = client.resolve_chat_id
|
|
16
|
-
config.chat_id = chat_id
|
|
15
|
+
config.chat_id = client.resolve_chat_id
|
|
17
16
|
end
|
|
18
17
|
|
|
19
18
|
client.send_message(chat_id: config.chat_id, text: text)
|
data/sig/telefy.rbs
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: telefy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ariel Rzezak
|
|
@@ -18,11 +18,8 @@ extensions: []
|
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
20
|
- CHANGELOG.md
|
|
21
|
-
- CLAUDE.md
|
|
22
|
-
- CODE_OF_CONDUCT.md
|
|
23
21
|
- LICENSE.txt
|
|
24
22
|
- README.md
|
|
25
|
-
- Rakefile
|
|
26
23
|
- exe/telefy
|
|
27
24
|
- lib/telefy.rb
|
|
28
25
|
- lib/telefy/cli.rb
|
|
@@ -44,14 +41,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
44
41
|
requirements:
|
|
45
42
|
- - ">="
|
|
46
43
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 3.
|
|
44
|
+
version: 3.4.0
|
|
48
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
46
|
requirements:
|
|
50
47
|
- - ">="
|
|
51
48
|
- !ruby/object:Gem::Version
|
|
52
49
|
version: '0'
|
|
53
50
|
requirements: []
|
|
54
|
-
rubygems_version: 4.0.
|
|
51
|
+
rubygems_version: 4.0.20
|
|
55
52
|
specification_version: 4
|
|
56
53
|
summary: Send Telegram messages from the command line
|
|
57
54
|
test_files: []
|
data/CLAUDE.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## Commands
|
|
6
|
-
|
|
7
|
-
- `bundle exec rake` — run tests + lint (default task)
|
|
8
|
-
- `bundle exec rake test` — tests only (minitest)
|
|
9
|
-
- `bundle exec rake standard` — lint only (StandardRB)
|
|
10
|
-
- `bin/console` — IRB REPL with gem loaded
|
|
11
|
-
|
|
12
|
-
## Architecture
|
|
13
|
-
|
|
14
|
-
Ruby gem (no runtime deps, stdlib only) for sending Telegram messages via Bot API.
|
|
15
|
-
|
|
16
|
-
**Entry point**: `exe/telefy` → `Telefy::CLI.new(ARGV).run`
|
|
17
|
-
|
|
18
|
-
**Core classes** (all under `lib/telefy/`):
|
|
19
|
-
- `Config` — YAML persistence at `~/.config/telefy/config.yml` (XDG-aware). Lazy load/save of `bot_token` and `chat_id`.
|
|
20
|
-
- `Client` — Telegram Bot API HTTP wrapper using `net/http`. `send_message` and `resolve_chat_id`.
|
|
21
|
-
- `CLI` — Arg parsing. `--setup` for config, otherwise joins args as message text and sends.
|
|
22
|
-
|
|
23
|
-
**Public API**: `Telefy.send_message(text, config:)` in `lib/telefy.rb` for library use.
|
|
24
|
-
|
|
25
|
-
## Testing
|
|
26
|
-
|
|
27
|
-
Minitest in `test/`. Uses `Dir.mktmpdir` for filesystem isolation and inline `.stub` for HTTP mocking. No fixtures or factories.
|
|
28
|
-
|
|
29
|
-
## Style
|
|
30
|
-
|
|
31
|
-
StandardRB (`.standard.yml`, targets Ruby 3.2). No custom RuboCop overrides.
|
data/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# Code of Conduct
|
|
2
|
-
|
|
3
|
-
"telefy" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
-
|
|
5
|
-
* Participants will be tolerant of opposing views.
|
|
6
|
-
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
-
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
-
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
-
|
|
10
|
-
If you have any concerns about behaviour within this project, please contact us at ["arzezak@gmail.com"](mailto:"arzezak@gmail.com").
|