gruubY 0.2.2 → 0.2.3
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/LICENSE +21 -21
- data/README.md +11 -6
- data/Rakefile +51 -51
- data/example/bot.rb +120 -1
- data/example/generate_user_session.rb +81 -81
- data/example/tdlib.rb +77 -77
- data/example/userbot.rb +133 -133
- data/lib/gruubY/api.rb +540 -363
- data/lib/gruubY/async.rb +13 -13
- data/lib/gruubY/bot.rb +104 -90
- data/lib/gruubY/bound.rb +14 -14
- data/lib/gruubY/client.rb +310 -296
- data/lib/gruubY/context.rb +296 -242
- data/lib/gruubY/dispatcher.rb +60 -60
- data/lib/gruubY/enums.rb +57 -62
- data/lib/gruubY/exception.rb +5 -5
- data/lib/gruubY/file_stream.rb +17 -17
- data/lib/gruubY/filters.rb +292 -292
- data/lib/gruubY/group_manager.rb +213 -213
- data/lib/gruubY/handlers.rb +225 -170
- data/lib/gruubY/keyboard.rb +49 -49
- data/lib/gruubY/media.rb +38 -38
- data/lib/gruubY/middleware.rb +18 -18
- data/lib/gruubY/plugin.rb +26 -26
- data/lib/gruubY/raw.rb +25 -25
- data/lib/gruubY/retry.rb +14 -14
- data/lib/gruubY/server.rb +18 -18
- data/lib/gruubY/session.rb +30 -30
- data/lib/gruubY/tdlib/client.rb +565 -565
- data/lib/gruubY/tdlib/client_manager.rb +37 -37
- data/lib/gruubY/tdlib/decorators.rb +17 -17
- data/lib/gruubY/tdlib/errors.rb +6 -6
- data/lib/gruubY/tdlib/group_manager.rb +58 -58
- data/lib/gruubY/tdlib/native.rb +72 -72
- data/lib/gruubY/tdlib/schema_builder.rb +237 -237
- data/lib/gruubY/tdlib/tdjson.rb +49 -49
- data/lib/gruubY/tdlib/user_session.rb +69 -69
- data/lib/gruubY/types/base_object.rb +72 -72
- data/lib/gruubY/types/bound_entities.rb +289 -245
- data/lib/gruubY/types/chat.rb +93 -93
- data/lib/gruubY/types/chat_info.rb +32 -31
- data/lib/gruubY/types/extra.rb +289 -251
- data/lib/gruubY/types/message.rb +301 -295
- data/lib/gruubY/types/message_entity.rb +14 -14
- data/lib/gruubY/types/registry.rb +86 -67
- data/lib/gruubY/types/user.rb +47 -31
- data/lib/gruubY/webapp.rb +22 -22
- data/lib/gruubY.rb +39 -41
- data/plugins/logger.rb +7 -7
- metadata +3 -9
- data/example/ntgcalls.rb +0 -80
- data/lib/gruubY/ntgcalls/native.rb +0 -100
- data/lib/gruubY/ntgcalls.rb +0 -478
- data/lib/gruubY/raw_types.rb +0 -57
- data/plugins/media_tools.rb +0 -13
data/lib/gruubY/types/message.rb
CHANGED
|
@@ -1,295 +1,301 @@
|
|
|
1
|
-
require_relative "base_object"
|
|
2
|
-
require_relative "user"
|
|
3
|
-
require_relative "chat"
|
|
4
|
-
require_relative "message_entity"
|
|
5
|
-
require_relative "extra"
|
|
6
|
-
|
|
7
|
-
module GrubY
|
|
8
|
-
class Message < BaseObject
|
|
9
|
-
fields :message_id, :message_thread_id, :direct_messages_topic, :from,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
:
|
|
14
|
-
:
|
|
15
|
-
:
|
|
16
|
-
:
|
|
17
|
-
:
|
|
18
|
-
:
|
|
19
|
-
:
|
|
20
|
-
:
|
|
21
|
-
:
|
|
22
|
-
:
|
|
23
|
-
:
|
|
24
|
-
:
|
|
25
|
-
:
|
|
26
|
-
:
|
|
27
|
-
:
|
|
28
|
-
:
|
|
29
|
-
:
|
|
30
|
-
:
|
|
31
|
-
:
|
|
32
|
-
:
|
|
33
|
-
:
|
|
34
|
-
:
|
|
35
|
-
:
|
|
36
|
-
:
|
|
37
|
-
:
|
|
38
|
-
:
|
|
39
|
-
:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
@
|
|
48
|
-
@
|
|
49
|
-
@
|
|
50
|
-
@
|
|
51
|
-
@
|
|
52
|
-
@
|
|
53
|
-
@
|
|
54
|
-
@
|
|
55
|
-
@
|
|
56
|
-
@
|
|
57
|
-
@
|
|
58
|
-
@
|
|
59
|
-
@
|
|
60
|
-
@
|
|
61
|
-
@
|
|
62
|
-
@
|
|
63
|
-
@
|
|
64
|
-
@
|
|
65
|
-
@
|
|
66
|
-
@
|
|
67
|
-
@
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def
|
|
89
|
-
call_api("
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
def
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
define_method("
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
when :
|
|
264
|
-
params.merge(
|
|
265
|
-
when :
|
|
266
|
-
params.merge(payload.is_a?(Hash) ? payload : {})
|
|
267
|
-
when :
|
|
268
|
-
params.merge(
|
|
269
|
-
when :
|
|
270
|
-
params.merge(payload.is_a?(Hash) ? payload : {})
|
|
271
|
-
when :
|
|
272
|
-
params.merge(payload.is_a?(Hash) ? payload : {})
|
|
273
|
-
when :
|
|
274
|
-
params.merge(
|
|
275
|
-
when :
|
|
276
|
-
params.merge(
|
|
277
|
-
when :
|
|
278
|
-
params.merge(
|
|
279
|
-
|
|
280
|
-
params
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
1
|
+
require_relative "base_object"
|
|
2
|
+
require_relative "user"
|
|
3
|
+
require_relative "chat"
|
|
4
|
+
require_relative "message_entity"
|
|
5
|
+
require_relative "extra"
|
|
6
|
+
|
|
7
|
+
module GrubY
|
|
8
|
+
class Message < BaseObject
|
|
9
|
+
fields :message_id, :message_thread_id, :direct_messages_topic, :from,
|
|
10
|
+
:sender_chat, :sender_boost_count, :sender_business_bot, :sender_tag,
|
|
11
|
+
:guest_query_id, :guest_bot_caller_user, :guest_bot_caller_chat,
|
|
12
|
+
:date, :business_connection_id, :chat, :forward_origin, :is_topic_message,
|
|
13
|
+
:is_automatic_forward, :reply_to_message, :external_reply, :quote,
|
|
14
|
+
:reply_to_story, :reply_to_checklist_task_id, :reply_to_poll_option_id,
|
|
15
|
+
:via_bot, :edit_date, :has_protected_content, :is_from_offline,
|
|
16
|
+
:is_paid_post, :media_group_id, :author_signature, :paid_star_count,
|
|
17
|
+
:text, :entities, :link_preview_options, :suggested_post_info, :effect_id,
|
|
18
|
+
:rich_message,
|
|
19
|
+
:animation, :audio, :document, :paid_media, :photo, :sticker, :story,
|
|
20
|
+
:video, :video_note, :voice, :caption, :caption_entities,
|
|
21
|
+
:show_caption_above_media, :has_media_spoiler, :checklist, :contact, :dice,
|
|
22
|
+
:game, :poll, :venue, :location, :new_chat_members, :left_chat_member,
|
|
23
|
+
:chat_owner_left, :chat_owner_changed, :new_chat_title, :new_chat_photo,
|
|
24
|
+
:delete_chat_photo, :group_chat_created, :supergroup_chat_created,
|
|
25
|
+
:channel_chat_created, :message_auto_delete_timer_changed,
|
|
26
|
+
:migrate_to_chat_id, :migrate_from_chat_id, :pinned_message, :invoice,
|
|
27
|
+
:successful_payment, :refunded_payment, :users_shared, :chat_shared, :gift,
|
|
28
|
+
:unique_gift, :gift_upgrade_sent, :connected_website,
|
|
29
|
+
:write_access_allowed, :passport_data, :proximity_alert_triggered,
|
|
30
|
+
:boost_added, :chat_background_set, :checklist_tasks_done,
|
|
31
|
+
:checklist_tasks_added, :direct_message_price_changed,
|
|
32
|
+
:forum_topic_created, :forum_topic_edited, :forum_topic_closed,
|
|
33
|
+
:forum_topic_reopened, :general_forum_topic_hidden,
|
|
34
|
+
:general_forum_topic_unhidden, :giveaway_created, :giveaway,
|
|
35
|
+
:giveaway_winners, :giveaway_completed, :managed_bot_created,
|
|
36
|
+
:paid_message_price_changed, :poll_option_added, :poll_option_deleted,
|
|
37
|
+
:suggested_post_approved, :suggested_post_approval_failed,
|
|
38
|
+
:suggested_post_declined, :suggested_post_paid,
|
|
39
|
+
:suggested_post_refunded, :video_chat_scheduled, :video_chat_started,
|
|
40
|
+
:video_chat_ended, :video_chat_participants_invited, :web_app_data,
|
|
41
|
+
:reply_markup, :widget, :receiver_user, :ephemeral_message_id,
|
|
42
|
+
:community_chat_added, :community_chat_joined, :community_chat_removed,
|
|
43
|
+
:paid_messages_waived, :ton_wallet_transfer
|
|
44
|
+
|
|
45
|
+
def initialize(data, api: nil, client: nil)
|
|
46
|
+
super(data, api: api, client: client)
|
|
47
|
+
@from = User.new(@from, api: api, client: client) if @from.is_a?(Hash)
|
|
48
|
+
@chat = Chat.new(@chat, api: api, client: client) if @chat.is_a?(Hash)
|
|
49
|
+
@sender_chat = Chat.new(@sender_chat, api: api, client: client) if @sender_chat.is_a?(Hash)
|
|
50
|
+
@sender_business_bot = User.new(@sender_business_bot, api: api, client: client) if @sender_business_bot.is_a?(Hash)
|
|
51
|
+
@guest_bot_caller_user = User.new(@guest_bot_caller_user, api: api, client: client) if @guest_bot_caller_user.is_a?(Hash)
|
|
52
|
+
@guest_bot_caller_chat = Chat.new(@guest_bot_caller_chat, api: api, client: client) if @guest_bot_caller_chat.is_a?(Hash)
|
|
53
|
+
@via_bot = User.new(@via_bot, api: api, client: client) if @via_bot.is_a?(Hash)
|
|
54
|
+
@reply_to_message = Message.new(@reply_to_message, api: api, client: client) if @reply_to_message.is_a?(Hash)
|
|
55
|
+
@external_reply = ExternalReplyInfo.new(@external_reply) if @external_reply.is_a?(Hash)
|
|
56
|
+
@quote = TextQuote.new(@quote) if @quote.is_a?(Hash)
|
|
57
|
+
@reply_to_story = Story.new(@reply_to_story) if @reply_to_story.is_a?(Hash)
|
|
58
|
+
@entities = Array(@entities).map { |e| MessageEntity.new(e) }
|
|
59
|
+
@caption_entities = Array(@caption_entities).map { |e| MessageEntity.new(e) }
|
|
60
|
+
@photo = Array(@photo).map { |p| PhotoSize.new(p) }
|
|
61
|
+
@animation = Animation.new(@animation) if @animation.is_a?(Hash)
|
|
62
|
+
@audio = Audio.new(@audio) if @audio.is_a?(Hash)
|
|
63
|
+
@document = Document.new(@document) if @document.is_a?(Hash)
|
|
64
|
+
@story = Story.new(@story) if @story.is_a?(Hash)
|
|
65
|
+
@video = Video.new(@video) if @video.is_a?(Hash)
|
|
66
|
+
@video_note = VideoNote.new(@video_note) if @video_note.is_a?(Hash)
|
|
67
|
+
@voice = Voice.new(@voice) if @voice.is_a?(Hash)
|
|
68
|
+
@paid_media = PaidMediaInfo.new(@paid_media) if @paid_media.is_a?(Hash)
|
|
69
|
+
@contact = Contact.new(@contact) if @contact.is_a?(Hash)
|
|
70
|
+
@dice = Dice.new(@dice) if @dice.is_a?(Hash)
|
|
71
|
+
@poll = Poll.new(@poll) if @poll.is_a?(Hash)
|
|
72
|
+
@new_chat_members = Array(@new_chat_members).map { |u| User.new(u, api: api, client: client) }
|
|
73
|
+
@left_chat_member = User.new(@left_chat_member, api: api, client: client) if @left_chat_member.is_a?(Hash)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def reply(text = nil, **opts)
|
|
77
|
+
call_api("sendMessage", { chat_id: chat_id!, text: text.to_s, reply_to_message_id: message_id }.merge(opts))
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def reply_text(text = nil, **opts)
|
|
81
|
+
reply(text, **opts)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def answer(text = nil, **opts)
|
|
85
|
+
reply(text, **opts)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def edit_text(text, **opts)
|
|
89
|
+
call_api("editMessageText", { chat_id: chat_id!, message_id: message_id, text: text.to_s }.merge(opts))
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
alias edit edit_text
|
|
93
|
+
|
|
94
|
+
def edit_caption(caption, **opts)
|
|
95
|
+
call_api("editMessageCaption", { chat_id: chat_id!, message_id: message_id, caption: caption.to_s }.merge(opts))
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def edit_media(media, **opts)
|
|
99
|
+
call_api("editMessageMedia", { chat_id: chat_id!, message_id: message_id, media: media }.merge(opts))
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def edit_checklist(checklist, **opts)
|
|
103
|
+
call_api("editMessageChecklist", { chat_id: chat_id!, message_id: message_id, checklist: checklist }.merge(opts))
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def edit_reply_markup(reply_markup = nil, **opts)
|
|
107
|
+
call_api("editMessageReplyMarkup", { chat_id: chat_id!, message_id: message_id, reply_markup: reply_markup }.merge(opts))
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def edit_live_location(latitude:, longitude:, **opts)
|
|
111
|
+
call_api("editMessageLiveLocation", { chat_id: chat_id!, message_id: message_id, latitude: latitude, longitude: longitude }.merge(opts))
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def stop_live_location(**opts)
|
|
115
|
+
call_api("stopMessageLiveLocation", { chat_id: chat_id!, message_id: message_id }.merge(opts))
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def forward(to_chat_id:, from_chat_id: chat_id!, **opts)
|
|
119
|
+
call_api("forwardMessage", { chat_id: to_chat_id, from_chat_id: from_chat_id, message_id: message_id }.merge(opts))
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def copy(to_chat_id:, from_chat_id: chat_id!, **opts)
|
|
123
|
+
call_api("copyMessage", { chat_id: to_chat_id, from_chat_id: from_chat_id, message_id: message_id }.merge(opts))
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def copy_media_group(to_chat_id:, from_chat_id: chat_id!, **opts)
|
|
127
|
+
call_api("copyMessages", { chat_id: to_chat_id, from_chat_id: from_chat_id, message_ids: [message_id] }.merge(opts))
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def delete(**opts)
|
|
131
|
+
call_api("deleteMessage", { chat_id: chat_id!, message_id: message_id }.merge(opts))
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def react(reaction:, is_big: false)
|
|
135
|
+
call_api("setMessageReaction", { chat_id: chat_id!, message_id: message_id, reaction: reaction, is_big: is_big })
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def retract_vote(**opts)
|
|
139
|
+
call_api("stopPoll", { chat_id: chat_id!, message_id: message_id }.merge(opts))
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def vote(option_ids, **opts)
|
|
143
|
+
call_api("sendPoll", { chat_id: chat_id!, options: option_ids }.merge(opts))
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def pin(**opts)
|
|
147
|
+
call_api("pinChatMessage", { chat_id: chat_id!, message_id: message_id }.merge(opts))
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def unpin(**opts)
|
|
151
|
+
call_api("unpinChatMessage", { chat_id: chat_id!, message_id: message_id }.merge(opts))
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def read
|
|
155
|
+
call_raw_api("readChatHistory", { chat_id: chat_id! })
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def view
|
|
159
|
+
call_raw_api("viewMessages", { chat_id: chat_id!, message_ids: [message_id] })
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def pay(**opts)
|
|
163
|
+
call_raw_api("sendPaymentForm", { chat_id: chat_id!, message_id: message_id }.merge(opts))
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def accept_gift_purchase_offer(**opts)
|
|
167
|
+
call_raw_api("processGiftPurchaseOffer", { message_id: message_id, accept: true }.merge(opts))
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def reject_gift_purchase_offer(**opts)
|
|
171
|
+
call_raw_api("processGiftPurchaseOffer", { message_id: message_id, accept: false }.merge(opts))
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def summarize(summary_language_code: "en")
|
|
175
|
+
call_raw_api("summarizeMessage", { chat_id: chat_id!, message_id: message_id, summary_language_code: summary_language_code })
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def fix_text_with_ai(**opts)
|
|
179
|
+
call_raw_api("fixTextWithAi", { chat_id: chat_id!, message_id: message_id }.merge(opts))
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def compose_text_with_ai(**opts)
|
|
183
|
+
call_raw_api("composeTextWithAi", { chat_id: chat_id!, message_id: message_id }.merge(opts))
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def reply_inline_bot_result(result_id:, query_id:, **opts)
|
|
187
|
+
call_raw_api("sendInlineBotResult", { chat_id: chat_id!, query_id: query_id, result_id: result_id }.merge(opts))
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def answer_inline_bot_result(result_id:, query_id:, **opts)
|
|
191
|
+
reply_inline_bot_result(result_id: result_id, query_id: query_id, **opts)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def get_media_group
|
|
195
|
+
return nil if media_group_id.to_s.empty?
|
|
196
|
+
|
|
197
|
+
call_raw_api("getMediaGroup", { chat_id: chat_id!, message_id: message_id })
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def reply_chat_action(action)
|
|
201
|
+
call_api("sendChatAction", { chat_id: chat_id!, action: action })
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def click
|
|
205
|
+
raise NotImplementedError, "click() requires callback query context"
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def download(file_name = "file.dat")
|
|
209
|
+
file_id = resolve_file_id
|
|
210
|
+
raise ArgumentError, "message has no downloadable media" if file_id.nil?
|
|
211
|
+
|
|
212
|
+
f = call_api("getFile", { file_id: file_id })
|
|
213
|
+
call_raw_api("getFile", { file_id: file_id }) unless f
|
|
214
|
+
file_path = f && f["file_path"]
|
|
215
|
+
raise ArgumentError, "file_path not found for file_id=#{file_id}" if file_path.to_s.empty?
|
|
216
|
+
|
|
217
|
+
@api.download_file(file_path, file_name)
|
|
218
|
+
file_name
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
SENDERS = {
|
|
222
|
+
animation: "sendAnimation",
|
|
223
|
+
audio: "sendAudio",
|
|
224
|
+
contact: "sendContact",
|
|
225
|
+
document: "sendDocument",
|
|
226
|
+
game: "sendGame",
|
|
227
|
+
invoice: "sendInvoice",
|
|
228
|
+
location: "sendLocation",
|
|
229
|
+
media_group: "sendMediaGroup",
|
|
230
|
+
photo: "sendPhoto",
|
|
231
|
+
poll: "sendPoll",
|
|
232
|
+
dice: "sendDice",
|
|
233
|
+
sticker: "sendSticker",
|
|
234
|
+
venue: "sendVenue",
|
|
235
|
+
video: "sendVideo",
|
|
236
|
+
video_note: "sendVideoNote",
|
|
237
|
+
voice: "sendVoice",
|
|
238
|
+
paid_media: "sendPaidMedia",
|
|
239
|
+
cached_media: "sendDocument",
|
|
240
|
+
checklist: "sendChecklist"
|
|
241
|
+
}.freeze
|
|
242
|
+
|
|
243
|
+
SENDERS.each do |name, method_name|
|
|
244
|
+
define_method("reply_#{name}") do |payload = nil, **opts|
|
|
245
|
+
params = { chat_id: chat_id!, reply_to_message_id: message_id }.merge(opts)
|
|
246
|
+
params = attach_payload(name, params, payload)
|
|
247
|
+
call_api(method_name, params)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
define_method("answer_#{name}") do |payload = nil, **opts|
|
|
251
|
+
public_send("reply_#{name}", payload, **opts)
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
private
|
|
256
|
+
|
|
257
|
+
def chat_id!
|
|
258
|
+
@chat&.id || self["chat"]&.dig("id") || raise(ArgumentError, "message has no chat id")
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def attach_payload(kind, params, payload)
|
|
262
|
+
case kind
|
|
263
|
+
when :animation, :audio, :document, :photo, :sticker, :video, :video_note, :voice
|
|
264
|
+
params.merge(kind => payload)
|
|
265
|
+
when :contact
|
|
266
|
+
params.merge(payload.is_a?(Hash) ? payload : {})
|
|
267
|
+
when :game
|
|
268
|
+
params.merge(game_short_name: payload)
|
|
269
|
+
when :invoice
|
|
270
|
+
params.merge(payload.is_a?(Hash) ? payload : {})
|
|
271
|
+
when :location
|
|
272
|
+
params.merge(payload.is_a?(Hash) ? payload : {})
|
|
273
|
+
when :media_group
|
|
274
|
+
params.merge(media: payload)
|
|
275
|
+
when :poll
|
|
276
|
+
params.merge(payload.is_a?(Hash) ? payload : {})
|
|
277
|
+
when :venue
|
|
278
|
+
params.merge(payload.is_a?(Hash) ? payload : {})
|
|
279
|
+
when :paid_media
|
|
280
|
+
params.merge(payload.is_a?(Hash) ? payload : {})
|
|
281
|
+
when :cached_media
|
|
282
|
+
params.merge(document: payload)
|
|
283
|
+
when :checklist
|
|
284
|
+
params.merge(checklist: payload)
|
|
285
|
+
else
|
|
286
|
+
params
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def resolve_file_id
|
|
291
|
+
return @document.file_id if @document&.respond_to?(:file_id)
|
|
292
|
+
return @audio.file_id if @audio&.respond_to?(:file_id)
|
|
293
|
+
return @video.file_id if @video&.respond_to?(:file_id)
|
|
294
|
+
return @voice.file_id if @voice&.respond_to?(:file_id)
|
|
295
|
+
return @animation.file_id if @animation&.respond_to?(:file_id)
|
|
296
|
+
return @photo.last.file_id if @photo.is_a?(Array) && @photo.last&.respond_to?(:file_id)
|
|
297
|
+
|
|
298
|
+
nil
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
end
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
require_relative "base_object"
|
|
2
|
-
require_relative "user"
|
|
3
|
-
|
|
4
|
-
module GrubY
|
|
5
|
-
class MessageEntity < BaseObject
|
|
6
|
-
fields :type, :offset, :length, :url, :user, :language, :custom_emoji_id,
|
|
7
|
-
:unix_time, :date_time_format
|
|
8
|
-
|
|
9
|
-
def initialize(data)
|
|
10
|
-
super(data)
|
|
11
|
-
@user = User.new(@user) if @user.is_a?(Hash)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
1
|
+
require_relative "base_object"
|
|
2
|
+
require_relative "user"
|
|
3
|
+
|
|
4
|
+
module GrubY
|
|
5
|
+
class MessageEntity < BaseObject
|
|
6
|
+
fields :type, :offset, :length, :url, :user, :language, :custom_emoji_id,
|
|
7
|
+
:unix_time, :date_time_format
|
|
8
|
+
|
|
9
|
+
def initialize(data)
|
|
10
|
+
super(data)
|
|
11
|
+
@user = User.new(@user) if @user.is_a?(Hash)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|