telefy 0.2.0 → 0.3.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 +6 -0
- data/README.md +2 -0
- data/lib/telefy/cli.rb +20 -3
- data/lib/telefy/client.rb +8 -4
- data/lib/telefy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0b836ae57b387402adbbc95ee082b93bc31193088bccb78ebf9fb225697e7b28
|
|
4
|
+
data.tar.gz: 9a44d4ba85fd50c3bd11bf27d39d4302cc570bd3bd30f84ce93c0babf0cafa42
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2799d0775fd3c7f85fb560e9b7b1a6d13341c2fb5d3961f78f290f6fd625f0bc38b8b6a85b2a19e9f2f7931e51087b05cef59fb678b7433b419306b04b1cc8aa
|
|
7
|
+
data.tar.gz: 3c38bf53f2a4290e72bdf8fb553b251690e265f5b0753793e01dc2b602952e29eb89f2e5f53a780984c791d405344d295e65bdbbf0b2d36682264387fa0eb340
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.3.0] - 2026-11-26
|
|
4
|
+
|
|
5
|
+
- Add `--version` and `-v`
|
|
6
|
+
- Show whose chat was saved when the chat ID is resolved, so a wrong recipient is visible at once
|
|
7
|
+
- Reject unknown options, which were sent as messages; `telefy -- "-text"` sends a message that starts with a dash
|
|
8
|
+
|
|
3
9
|
## [0.2.0] - 2026-11-26
|
|
4
10
|
|
|
5
11
|
- Require Ruby 3.4 or later
|
data/README.md
CHANGED
|
@@ -30,8 +30,10 @@ The chat ID is resolved automatically and saved for future use.
|
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
telefy "Deploy finished" # send a message
|
|
33
|
+
telefy -- "-5 degrees" # send a message that starts with a dash
|
|
33
34
|
telefy --setup # configure bot token
|
|
34
35
|
telefy --help # show usage
|
|
36
|
+
telefy --version # show the version
|
|
35
37
|
```
|
|
36
38
|
|
|
37
39
|
### As a library
|
data/lib/telefy/cli.rb
CHANGED
|
@@ -7,7 +7,9 @@ module Telefy
|
|
|
7
7
|
|
|
8
8
|
telefy --setup Configure bot token
|
|
9
9
|
telefy "message" Send a message (auto-resolves chat ID on first use)
|
|
10
|
+
telefy -- "-text" Send a message that starts with a dash
|
|
10
11
|
telefy --help Show this help
|
|
12
|
+
telefy --version Show the version
|
|
11
13
|
TEXT
|
|
12
14
|
|
|
13
15
|
def initialize(argv, config: Config.new)
|
|
@@ -19,6 +21,9 @@ module Telefy
|
|
|
19
21
|
case @argv.first
|
|
20
22
|
when "--setup" then setup
|
|
21
23
|
when "--help", nil then puts USAGE
|
|
24
|
+
when "--version", "-v" then puts VERSION
|
|
25
|
+
when "--" then send_message(@argv.drop(1).join(" "))
|
|
26
|
+
when /\A-/ then abort "Unknown option: #{@argv.first}\n\n#{USAGE}"
|
|
22
27
|
else send_message(@argv.join(" "))
|
|
23
28
|
end
|
|
24
29
|
rescue Error => error
|
|
@@ -37,10 +42,22 @@ module Telefy
|
|
|
37
42
|
end
|
|
38
43
|
|
|
39
44
|
def send_message(text)
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
save_chat unless @config.chat_id
|
|
42
46
|
Telefy.send_message(text, config: @config)
|
|
43
|
-
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def save_chat
|
|
50
|
+
chat = Client.new(@config.bot_token).resolve_chat
|
|
51
|
+
@config.chat_id = chat.fetch("id")
|
|
52
|
+
puts "Chat ID resolved and saved: #{describe(chat)}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def describe(chat)
|
|
56
|
+
name = chat["title"] || chat.values_at("first_name", "last_name").compact.join(" ")
|
|
57
|
+
username = "@#{chat["username"]}" if chat["username"]
|
|
58
|
+
owner = [name, username].compact.reject(&:empty?).join(", ").gsub(/[[:cntrl:]]/, "")
|
|
59
|
+
|
|
60
|
+
owner.empty? ? chat.fetch("id").to_s : "#{chat.fetch("id")} (#{owner})"
|
|
44
61
|
end
|
|
45
62
|
end
|
|
46
63
|
end
|
data/lib/telefy/client.rb
CHANGED
|
@@ -16,12 +16,16 @@ module Telefy
|
|
|
16
16
|
parse(post("sendMessage", chat_id: chat_id, text: text))
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def
|
|
19
|
+
def resolve_chat
|
|
20
20
|
updates = parse(Net::HTTP.get_response(api_uri("getUpdates"))).fetch("result")
|
|
21
|
-
|
|
22
|
-
raise Error, "No messages found. Message your bot first, then retry." unless
|
|
21
|
+
chat = updates.filter_map { |update| update.dig("message", "chat") }.first
|
|
22
|
+
raise Error, "No messages found. Message your bot first, then retry." unless chat
|
|
23
|
+
|
|
24
|
+
chat
|
|
25
|
+
end
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
def resolve_chat_id
|
|
28
|
+
resolve_chat.fetch("id")
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
private
|
data/lib/telefy/version.rb
CHANGED