chat_sdk-telegram 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58370e45b0bd2e2b95b7e855bf5ad495ca5d1fdd5308762acccbd6d225768977
4
- data.tar.gz: ff900b05aeb9fe7dfc0246bbc8ed67d7eacf902a465c95b55498096f39f4de8a
3
+ metadata.gz: a14fedc4aa2b77c45981da8147e152cb78770d131e1bbe234468655d0b171173
4
+ data.tar.gz: 3b35d0c60617dc93afa0b706b70e80f21d5672a4a00e0f7d0db374f49c6318c4
5
5
  SHA512:
6
- metadata.gz: 61967c1e0462b9f65b5bf2ce8f79850942c118cff494c8a75286d8b490d52e1cd90c4d331ea6d10d2590be63d3c25195a702ea322fcffdf28e95550a1f9d6244
7
- data.tar.gz: ab68df93fede82b187ccfcbc0aeedcddd86781aa7c5a3575d58f3ede4bb3c59c753e9f61b48de05205aa5fb0963d33704eaa16184bc54035d210ae08dd558c42
6
+ metadata.gz: b3da00035b7d571f92a05ec573212754999cf553f71608a6cf3473b9410f060951e3324a10ef520faa393dd16a17fe397d77794cdab8b175ab86909c0fc90501
7
+ data.tar.gz: fb63c59d2e3a750530ff211f392b35b3003b5afa8e7bb7f7c277149bebc6d32ca4cc69f85c473428be9419359b1162a6d7ed7843472343069cbeef503b6255f7
@@ -108,6 +108,19 @@ module ChatSDK
108
108
  )
109
109
  end
110
110
 
111
+ def get_user(user_id)
112
+ data = @client.get_chat(chat_id: user_id)
113
+ return nil unless data && data["id"]
114
+
115
+ ChatSDK::Author.new(
116
+ id: data["id"].to_s,
117
+ name: data["username"] || data["first_name"],
118
+ platform: :telegram,
119
+ bot: data["type"] == "bot",
120
+ raw: data
121
+ )
122
+ end
123
+
111
124
  def open_dm(user_id)
112
125
  user_id
113
126
  end
@@ -128,6 +141,21 @@ module ChatSDK
128
141
  end
129
142
  end
130
143
 
144
+ # Telegram-specific: long-poll for updates instead of using webhooks.
145
+ # Useful for local development. Not part of the base adapter contract.
146
+ def poll(timeout: 30, &block)
147
+ offset = nil
148
+ loop do
149
+ updates = @client.get_updates(offset: offset, timeout: timeout)
150
+ updates = updates.is_a?(Array) ? updates : []
151
+ updates.each do |update|
152
+ offset = update["update_id"] + 1
153
+ events = EventParser.parse(update, bot_username: @bot_username)
154
+ events.each { |event| block.call(event) }
155
+ end
156
+ end
157
+ end
158
+
131
159
  private
132
160
 
133
161
  def prepare_message_payload(message)
@@ -10,14 +10,14 @@ module ChatSDK
10
10
  end
11
11
 
12
12
  def send_message(chat_id:, text:, reply_markup: nil, reply_to_message_id: nil)
13
- body = {"chat_id" => chat_id, "text" => text, "parse_mode" => "Markdown"}
13
+ body = {"chat_id" => chat_id, "text" => text, "parse_mode" => "MarkdownV2"}
14
14
  body["reply_markup"] = reply_markup if reply_markup
15
15
  body["reply_to_message_id"] = reply_to_message_id if reply_to_message_id
16
16
  request(:post, "sendMessage", body)
17
17
  end
18
18
 
19
19
  def edit_message_text(chat_id:, message_id:, text:, reply_markup: nil)
20
- body = {"chat_id" => chat_id, "message_id" => message_id, "text" => text, "parse_mode" => "Markdown"}
20
+ body = {"chat_id" => chat_id, "message_id" => message_id, "text" => text, "parse_mode" => "MarkdownV2"}
21
21
  body["reply_markup"] = reply_markup if reply_markup
22
22
  request(:post, "editMessageText", body)
23
23
  end
@@ -50,6 +50,16 @@ module ChatSDK
50
50
  request(:post, "sendChatAction", {"chat_id" => chat_id, "action" => action})
51
51
  end
52
52
 
53
+ def get_chat(chat_id:)
54
+ request(:post, "getChat", {"chat_id" => chat_id})
55
+ end
56
+
57
+ def get_updates(offset: nil, timeout: 30)
58
+ body = {"timeout" => timeout}
59
+ body["offset"] = offset if offset
60
+ request(:post, "getUpdates", body)
61
+ end
62
+
53
63
  private
54
64
 
55
65
  def api_path(method)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chat_sdk-telegram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quentin Rousseau