telegruby 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/telegruby.rb +98 -21
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4744f23e0ac76fdbb1a66569aae506d9341c71f
|
4
|
+
data.tar.gz: 98ab4caddcbd8519580230568361b67ddaed4acf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d30ffe118c4e320a2122bfe517722859d0b3c3e660a8deb413d475cedbafb27d39f1e81537facc82094d4971f245c4955c3a0f29d8af4d010602506e48b29645
|
7
|
+
data.tar.gz: e1ad5cfa3245c652fd9921a6bf36638462c9ce3738b6ccf9affac4db863e0b907b282419458e1b9a3f8463f9a0a55cbfdef329057115272af79a74364c844043
|
data/lib/telegruby.rb
CHANGED
@@ -13,16 +13,19 @@ module Telegruby
|
|
13
13
|
|
14
14
|
# See https://core.telegram.org/bots/api for the full method list
|
15
15
|
|
16
|
-
def get_updates(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
21
|
-
end
|
16
|
+
def get_updates(on_error: nil)
|
17
|
+
options = {
|
18
|
+
:offset => @id
|
19
|
+
}
|
22
20
|
|
23
21
|
request = self.get_request("getUpdates", options)
|
24
22
|
if request.code != 200
|
25
|
-
|
23
|
+
if on_error.nil?
|
24
|
+
puts "Failed to get updates: #{request}"
|
25
|
+
return nil
|
26
|
+
else
|
27
|
+
return on_error(request)
|
28
|
+
end
|
26
29
|
end
|
27
30
|
update = Update.new(JSON.parse(request.body, object_class: OpenStruct))
|
28
31
|
|
@@ -35,20 +38,25 @@ module Telegruby
|
|
35
38
|
end
|
36
39
|
|
37
40
|
# Send a plaintext message to a chat id
|
38
|
-
def send_message(id, text, reply: nil, parse_mode: nil)
|
41
|
+
def send_message(id, text, reply: nil, parse_mode: nil, disable_preview: nil, reply_markup: nil)
|
39
42
|
options = {
|
40
43
|
:chat_id => id,
|
41
44
|
:text => text
|
42
45
|
}
|
43
46
|
|
47
|
+
if !parse_mode.nil?
|
48
|
+
options.merge!(:parse_mode => parse_mode)
|
49
|
+
end
|
50
|
+
if !disable_preview.nil?
|
51
|
+
options.merge!(:disable_preview => disable_preview)
|
52
|
+
end
|
44
53
|
if !reply.nil?
|
45
54
|
options.merge!(:reply_to_message_id => reply)
|
46
55
|
end
|
47
|
-
|
48
|
-
|
49
|
-
options.merge!(:parse_mode => parse_mode)
|
56
|
+
if !reply_markup.nil?
|
57
|
+
options.merge!(:reply_markup => reply_markup)
|
50
58
|
end
|
51
|
-
|
59
|
+
|
52
60
|
self.get_request("sendMessage", options)
|
53
61
|
end
|
54
62
|
|
@@ -63,7 +71,7 @@ module Telegruby
|
|
63
71
|
end
|
64
72
|
|
65
73
|
# Sends a photo message to a chat id
|
66
|
-
def send_photo(id, filename: nil, file_id: nil, reply: nil)
|
74
|
+
def send_photo(id, filename: nil, file_id: nil, reply: nil, caption: nil, reply_markup: nil)
|
67
75
|
options = {
|
68
76
|
:chat_id => id,
|
69
77
|
}
|
@@ -77,6 +85,14 @@ module Telegruby
|
|
77
85
|
options.merge!(:reply_to_message_id => reply)
|
78
86
|
end
|
79
87
|
|
88
|
+
if !caption.nil?
|
89
|
+
options.merge!(:caption => caption)
|
90
|
+
end
|
91
|
+
|
92
|
+
if !reply_markup.nil?
|
93
|
+
options.merge!(:reply_markup => reply_markup)
|
94
|
+
end
|
95
|
+
|
80
96
|
self.post_request("sendPhoto", options)
|
81
97
|
end
|
82
98
|
|
@@ -90,7 +106,7 @@ module Telegruby
|
|
90
106
|
}
|
91
107
|
end
|
92
108
|
|
93
|
-
def send_voice(id, filename: nil, file_id: nil, reply: nil)
|
109
|
+
def send_voice(id, filename: nil, file_id: nil, reply: nil, reply_markup: nil)
|
94
110
|
options = {
|
95
111
|
:chat_id => id,
|
96
112
|
}
|
@@ -104,10 +120,14 @@ module Telegruby
|
|
104
120
|
options.merge!(:reply_to_message_id => reply)
|
105
121
|
end
|
106
122
|
|
123
|
+
if !reply_markup.nil?
|
124
|
+
options.merge!(:reply_markup => reply_markup)
|
125
|
+
end
|
126
|
+
|
107
127
|
self.post_request("sendVoice", options)
|
108
128
|
end
|
109
129
|
|
110
|
-
def send_sticker(id, file_id: nil, filename: nil, reply: nil)
|
130
|
+
def send_sticker(id, file_id: nil, filename: nil, reply: nil, reply_markup: nil)
|
111
131
|
options = {
|
112
132
|
:chat_id => id,
|
113
133
|
}
|
@@ -121,10 +141,14 @@ module Telegruby
|
|
121
141
|
options.merge!(:reply_to_message_id => reply)
|
122
142
|
end
|
123
143
|
|
144
|
+
if !reply_markup.nil?
|
145
|
+
options.merge!(:reply_markup => reply_markup)
|
146
|
+
end
|
147
|
+
|
124
148
|
self.post_request("sendSticker", options)
|
125
149
|
end
|
126
150
|
|
127
|
-
def send_audio(id, filename: nil, file_id: nil, reply: nil)
|
151
|
+
def send_audio(id, filename: nil, file_id: nil, reply: nil, reply_markup: nil)
|
128
152
|
options = {
|
129
153
|
:chat_id => id,
|
130
154
|
}
|
@@ -138,10 +162,14 @@ module Telegruby
|
|
138
162
|
options.merge!(:reply_to_message_id => reply)
|
139
163
|
end
|
140
164
|
|
165
|
+
if !reply_markup.nil?
|
166
|
+
options.merge!(:reply_markup => reply_markup)
|
167
|
+
end
|
168
|
+
|
141
169
|
self.post_request("sendAudio", options)
|
142
170
|
end
|
143
171
|
|
144
|
-
def send_video(id, filename: nil, file_id: nil, reply: nil)
|
172
|
+
def send_video(id, filename: nil, file_id: nil, reply: nil, reply_markup: nil)
|
145
173
|
options = {
|
146
174
|
:chat_id => id,
|
147
175
|
}
|
@@ -155,10 +183,14 @@ module Telegruby
|
|
155
183
|
options.merge!(:reply_to_message_id => reply)
|
156
184
|
end
|
157
185
|
|
186
|
+
if !reply_markup.nil?
|
187
|
+
options.merge!(:reply_markup => reply_markup)
|
188
|
+
end
|
189
|
+
|
158
190
|
self.post_request("sendVideo", options)
|
159
191
|
end
|
160
192
|
|
161
|
-
def send_location(id, lat, long, reply: nil)
|
193
|
+
def send_location(id, lat, long, reply: nil, reply_markup: nil)
|
162
194
|
options = {
|
163
195
|
:chat_id => id,
|
164
196
|
:latitude => lat,
|
@@ -169,6 +201,10 @@ module Telegruby
|
|
169
201
|
options.merge!(:reply_to_message_id => reply)
|
170
202
|
end
|
171
203
|
|
204
|
+
if !reply_markup.nil?
|
205
|
+
options.merge!(:reply_markup => reply_markup)
|
206
|
+
end
|
207
|
+
|
172
208
|
self.post_request("sendLocation", options)
|
173
209
|
end
|
174
210
|
|
@@ -182,7 +218,7 @@ module Telegruby
|
|
182
218
|
end
|
183
219
|
|
184
220
|
# Sends a document by filename or file ID
|
185
|
-
def send_document(id, filename: nil, file_id: nil, reply: nil)
|
221
|
+
def send_document(id, filename: nil, file_id: nil, reply: nil, reply_markup: nil)
|
186
222
|
options = {
|
187
223
|
:chat_id => id
|
188
224
|
}
|
@@ -197,10 +233,14 @@ module Telegruby
|
|
197
233
|
options.merge!(:reply_to_message_id => reply)
|
198
234
|
end
|
199
235
|
|
236
|
+
if !reply_markup.nil?
|
237
|
+
options.merge!(:reply_markup => reply_markup)
|
238
|
+
end
|
239
|
+
|
200
240
|
return self.post_request("sendDocument", options)
|
201
241
|
end
|
202
242
|
|
203
|
-
def
|
243
|
+
def get_userphotos(id, offset: nil, limit: nil)
|
204
244
|
options = {
|
205
245
|
:user_id => id,
|
206
246
|
:offset => offset,
|
@@ -221,6 +261,26 @@ module Telegruby
|
|
221
261
|
return self.get_request("setWebhook", options)
|
222
262
|
end
|
223
263
|
|
264
|
+
def get_file(file_id)
|
265
|
+
options = {
|
266
|
+
:file_id => file_id
|
267
|
+
}
|
268
|
+
return self.get_request("getFile", options)
|
269
|
+
end
|
270
|
+
|
271
|
+
def answer_inline_query(id, results, cache_time: 300, is_personal: false, next_offset: nil)
|
272
|
+
options = {
|
273
|
+
:inline_query_id => id,
|
274
|
+
:results => results,
|
275
|
+
:cache_time => cache_time,
|
276
|
+
:is_personal => is_personal,
|
277
|
+
}
|
278
|
+
if !next_offset.nil?
|
279
|
+
options.merge!(:next_offset => next_offset)
|
280
|
+
end
|
281
|
+
return self.get_request("answerInlineQuery", options)
|
282
|
+
end
|
283
|
+
|
224
284
|
protected
|
225
285
|
|
226
286
|
# Provides a generic method for GET requests.
|
@@ -232,6 +292,7 @@ module Telegruby
|
|
232
292
|
def post_request(name, options = {})
|
233
293
|
HTTMultiParty::post(@endpoint + name, query: options).body
|
234
294
|
end
|
295
|
+
|
235
296
|
end
|
236
297
|
|
237
298
|
module_function
|
@@ -252,7 +313,7 @@ module Telegruby
|
|
252
313
|
return false
|
253
314
|
end
|
254
315
|
end
|
255
|
-
|
316
|
+
|
256
317
|
# Given an Update object, gets messages as structs.
|
257
318
|
def collect_msgs(update)
|
258
319
|
update.result.map { |msg|
|
@@ -288,6 +349,22 @@ module Telegruby
|
|
288
349
|
self.message.chat.id
|
289
350
|
end
|
290
351
|
|
352
|
+
def added?(username)
|
353
|
+
if self.message.new_chat_participant.nil?
|
354
|
+
false
|
355
|
+
else
|
356
|
+
self.message.new_chat_participant.username == username
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
def left?(username)
|
361
|
+
if self.message.left_chat_participant.nil?
|
362
|
+
false
|
363
|
+
else
|
364
|
+
self.message.left_chat_participant.username == username
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
291
368
|
def body
|
292
369
|
self.message.text
|
293
370
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: telegruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '"Lain"'
|
@@ -9,16 +9,16 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-02-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: Telegram Bot API library, https://core.telegram.org/bots/api.
|
15
15
|
email: lain@lain.org.uk
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/telegruby.rb
|
21
|
-
homepage: https://github.com/
|
21
|
+
homepage: https://github.com/webgiorno/telegruby
|
22
22
|
licenses:
|
23
23
|
- MIT
|
24
24
|
metadata: {}
|
@@ -41,5 +41,5 @@ rubyforge_project:
|
|
41
41
|
rubygems_version: 2.4.8
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
|
-
summary:
|
44
|
+
summary: Telegram Bot API library.
|
45
45
|
test_files: []
|