huginn_telegrambis_agent 0.1.0 → 0.1.1
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/lib/huginn_telegrambis_agent/telegrambis_agent.rb +149 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 776d9c1ae365a5f471c2a135062bf16bfc2916b29e4c3fe4fc4d1b1336b765eb
|
4
|
+
data.tar.gz: 80033fce4df89a10befdb4de1546b5a62b931fa460e651a5d96e02dfcc6452ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '010104867d21d02ff918764704d25a4ceb98031ca258609a368603a51ffdadf83b8f4281096ebd2147c06d21be9d2801f7c1aaa440f6b047fee1a6d9717b3d0f'
|
7
|
+
data.tar.gz: 8fdc0bed43e7d0bf9b19aa14db26b0d29fc22db36bfd39b2f1af2d61f96814353df75a42e9b56d679350d015d8871eb6b5ea43695de4dcb90c1181d4f4a43322
|
@@ -9,6 +9,8 @@ module Agents
|
|
9
9
|
<<-MD
|
10
10
|
The Telegrambis Agent complements the very good telegram agent, it adds other interactions with the Telegram api.
|
11
11
|
|
12
|
+
The `type` can be like pinned a message for example.
|
13
|
+
|
12
14
|
`chat_id` for the target channel.
|
13
15
|
|
14
16
|
`message_id` is needed to select the message for possible interactions like pinned message.
|
@@ -33,6 +35,10 @@ module Agents
|
|
33
35
|
{
|
34
36
|
'chat_id' => '',
|
35
37
|
'message_id' => '',
|
38
|
+
'question' => '',
|
39
|
+
'options' => '',
|
40
|
+
'is_anonymous' => 'false',
|
41
|
+
'poll_type' => 'regular',
|
36
42
|
'debug' => 'false',
|
37
43
|
'emit_events' => 'true',
|
38
44
|
'expected_receive_period_in_days' => '7',
|
@@ -42,23 +48,43 @@ module Agents
|
|
42
48
|
|
43
49
|
form_configurable :chat_id, type: :string
|
44
50
|
form_configurable :message_id, type: :string
|
51
|
+
form_configurable :question, type: :string
|
52
|
+
form_configurable :options, type: :string
|
53
|
+
form_configurable :is_anonymous, type: :boolean
|
54
|
+
form_configurable :poll_type, type: :string
|
45
55
|
form_configurable :debug, type: :boolean
|
46
56
|
form_configurable :emit_events, type: :boolean
|
47
57
|
form_configurable :token, type: :string
|
48
58
|
form_configurable :expected_receive_period_in_days, type: :string
|
49
|
-
form_configurable :type, type: :array, values: ['pin_chat_message', 'unpin_chat_message']
|
59
|
+
form_configurable :type, type: :array, values: ['pin_chat_message', 'unpin_chat_message', 'send_poll', 'stop_poll']
|
50
60
|
|
51
61
|
def validate_options
|
52
|
-
errors.add(:base, "type has invalid value: should be 'pin_chat_message', 'unpin_chat_message'") if interpolated['type'].present? && !%w(pin_chat_message unpin_chat_message).include?(interpolated['type'])
|
62
|
+
errors.add(:base, "type has invalid value: should be 'pin_chat_message', 'unpin_chat_message', 'send_poll', 'stop_poll'") if interpolated['type'].present? && !%w(pin_chat_message unpin_chat_message send_poll stop_poll).include?(interpolated['type'])
|
53
63
|
|
54
|
-
unless options['chat_id'].present? || !['pin_chat_message' 'unpin_chat_message'].include?(options['type'])
|
64
|
+
unless options['chat_id'].present? || !['pin_chat_message' 'unpin_chat_message' 'send_poll' 'stop_poll'].include?(options['type'])
|
55
65
|
errors.add(:base, "chat_id is a required field")
|
56
66
|
end
|
57
67
|
|
58
|
-
unless options['message_id'].present? || !['pin_chat_message' 'unpin_chat_message'].include?(options['type'])
|
68
|
+
unless options['message_id'].present? || !['pin_chat_message' 'unpin_chat_message' 'stop_poll'].include?(options['type'])
|
59
69
|
errors.add(:base, "message_id is a required field")
|
60
70
|
end
|
61
71
|
|
72
|
+
unless options['question'].present? || !['send_poll'].include?(options['type'])
|
73
|
+
errors.add(:base, "question is a required field")
|
74
|
+
end
|
75
|
+
|
76
|
+
unless options['options'].present? || !['send_poll'].include?(options['type'])
|
77
|
+
errors.add(:base, "options is a required field")
|
78
|
+
end
|
79
|
+
|
80
|
+
unless options['is_anonymous'].present? || !['send_poll'].include?(options['type'])
|
81
|
+
errors.add(:base, "is_anonymous is a required field")
|
82
|
+
end
|
83
|
+
|
84
|
+
unless options['poll_type'].present? || !['send_poll'].include?(options['type'])
|
85
|
+
errors.add(:base, "poll_type is a required field")
|
86
|
+
end
|
87
|
+
|
62
88
|
if options.has_key?('debug') && boolify(options['debug']).nil?
|
63
89
|
errors.add(:base, "if provided, debug must be true or false")
|
64
90
|
end
|
@@ -167,6 +193,119 @@ module Agents
|
|
167
193
|
end
|
168
194
|
|
169
195
|
end
|
196
|
+
#
|
197
|
+
# def set_message_reaction
|
198
|
+
#
|
199
|
+
# log JSON.dump({
|
200
|
+
# "chat_id" => interpolated['chat_id'],
|
201
|
+
# "message_id" => interpolated['message_id'],
|
202
|
+
# "reaction" => [
|
203
|
+
# {
|
204
|
+
# "type" => "emoji",
|
205
|
+
# "emoji" => interpolated['reaction']
|
206
|
+
# }
|
207
|
+
# ]
|
208
|
+
# })
|
209
|
+
#
|
210
|
+
#
|
211
|
+
# uri = URI.parse("https://api.telegram.org/bot#{interpolated['token']}/setMessageReaction")
|
212
|
+
# request = Net::HTTP::Post.new(uri)
|
213
|
+
# request.content_type = "application/json"
|
214
|
+
# request.body = JSON.dump({
|
215
|
+
# "chat_id" => interpolated['chat_id'],
|
216
|
+
# "message_id" => interpolated['message_id'],
|
217
|
+
# "reaction" => [
|
218
|
+
# {
|
219
|
+
# "type" => "emoji",
|
220
|
+
# "emoji" => interpolated['reaction']
|
221
|
+
# }
|
222
|
+
# ]
|
223
|
+
# })
|
224
|
+
#
|
225
|
+
# req_options = {
|
226
|
+
# use_ssl: uri.scheme == "https",
|
227
|
+
# }
|
228
|
+
#
|
229
|
+
# response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
230
|
+
# http.request(request)
|
231
|
+
# end
|
232
|
+
#
|
233
|
+
# log_curl_output(response.code,response.body)
|
234
|
+
#
|
235
|
+
# payload = JSON.parse(response.body)
|
236
|
+
#
|
237
|
+
# if interpolated['emit_events'] == 'true'
|
238
|
+
# payload['action'] = 'setMessageReaction'
|
239
|
+
# payload['chat_id'] = interpolated['chat_id']
|
240
|
+
# payload['message_id'] = interpolated['message_id']
|
241
|
+
# create_event payload: payload
|
242
|
+
# end
|
243
|
+
#
|
244
|
+
# end
|
245
|
+
|
246
|
+
def send_poll
|
247
|
+
|
248
|
+
uri = URI.parse("https://api.telegram.org/bot#{interpolated['token']}/sendPoll")
|
249
|
+
request = Net::HTTP::Post.new(uri)
|
250
|
+
request.content_type = "application/json"
|
251
|
+
request.body = JSON.dump({
|
252
|
+
"chat_id" => interpolated['chat_id'],
|
253
|
+
"question" => interpolated['question'],
|
254
|
+
"options" => JSON.parse(interpolated['options']),
|
255
|
+
"is_anonymous" => interpolated['is_anonymous'],
|
256
|
+
"type" => interpolated['poll_type'],
|
257
|
+
})
|
258
|
+
|
259
|
+
req_options = {
|
260
|
+
use_ssl: uri.scheme == "https",
|
261
|
+
}
|
262
|
+
|
263
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
264
|
+
http.request(request)
|
265
|
+
end
|
266
|
+
|
267
|
+
log_curl_output(response.code,response.body)
|
268
|
+
|
269
|
+
payload = JSON.parse(response.body)
|
270
|
+
|
271
|
+
if interpolated['emit_events'] == 'true'
|
272
|
+
payload['action'] = 'sendPoll'
|
273
|
+
payload['chat_id'] = interpolated['chat_id']
|
274
|
+
create_event payload: payload
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
def stop_poll
|
280
|
+
|
281
|
+
uri = URI.parse("https://api.telegram.org/bot#{interpolated['token']}/stopPoll")
|
282
|
+
request = Net::HTTP::Post.new(uri)
|
283
|
+
request.content_type = "application/json"
|
284
|
+
request.body = JSON.dump({
|
285
|
+
"chat_id" => interpolated['chat_id'],
|
286
|
+
"message_id" => interpolated['message_id']
|
287
|
+
})
|
288
|
+
|
289
|
+
req_options = {
|
290
|
+
use_ssl: uri.scheme == "https",
|
291
|
+
}
|
292
|
+
|
293
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
294
|
+
http.request(request)
|
295
|
+
end
|
296
|
+
|
297
|
+
log_curl_output(response.code,response.body)
|
298
|
+
|
299
|
+
payload = JSON.parse(response.body)
|
300
|
+
|
301
|
+
if interpolated['emit_events'] == 'true'
|
302
|
+
payload['action'] = 'stopPoll'
|
303
|
+
payload['chat_id'] = interpolated['chat_id']
|
304
|
+
payload['message_id'] = interpolated['message_id']
|
305
|
+
create_event payload: payload
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|
170
309
|
|
171
310
|
def trigger_action
|
172
311
|
|
@@ -175,6 +314,12 @@ module Agents
|
|
175
314
|
pin_chat_message()
|
176
315
|
when "unpin_chat_message"
|
177
316
|
unpin_chat_message()
|
317
|
+
# when "set_message_reaction"
|
318
|
+
# set_message_reaction()
|
319
|
+
when "send_poll"
|
320
|
+
send_poll()
|
321
|
+
when "stop_poll"
|
322
|
+
stop_poll()
|
178
323
|
else
|
179
324
|
log "Error: type has an invalid value (#{interpolated['type']})"
|
180
325
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huginn_telegrambis_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Germain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|