teleruby 1.5.1 → 1.5.4

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.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +9 -0
  3. data/README.md +398 -0
  4. data/lib/api/all.rb +12 -0
  5. data/lib/api/delete_apis.rb +55 -0
  6. data/lib/api/get_apis.rb +162 -0
  7. data/lib/api/nstandard.rb +26 -0
  8. data/lib/api/other_apis.rb +225 -0
  9. data/lib/api/send_apis.rb +191 -0
  10. data/lib/api/set_apis.rb +130 -0
  11. data/lib/core_api.rb +41 -0
  12. data/lib/objects/all.rb +42 -0
  13. data/lib/objects/animation.rb +38 -0
  14. data/lib/objects/audio.rb +37 -0
  15. data/lib/objects/bot_command.rb +24 -0
  16. data/lib/objects/callback_query.rb +64 -0
  17. data/lib/objects/chat.rb +158 -0
  18. data/lib/objects/chat_member.rb +142 -0
  19. data/lib/objects/chat_permissions.rb +59 -0
  20. data/lib/objects/chat_photo.rb +37 -0
  21. data/lib/objects/chosen_inline_result.rb +43 -0
  22. data/lib/objects/contact.rb +37 -0
  23. data/lib/objects/dice.rb +21 -0
  24. data/lib/objects/document.rb +27 -0
  25. data/lib/objects/file.rb +32 -0
  26. data/lib/objects/game.rb +65 -0
  27. data/lib/objects/inline_query.rb +42 -0
  28. data/lib/objects/inlinekeyboardbutton.rb +59 -0
  29. data/lib/objects/inlinekeyboardmarkup.rb +30 -0
  30. data/lib/objects/location.rb +21 -0
  31. data/lib/objects/mask_position.rb +35 -0
  32. data/lib/objects/message.rb +378 -0
  33. data/lib/objects/message_entity.rb +93 -0
  34. data/lib/objects/order_info.rb +34 -0
  35. data/lib/objects/photo_size.rb +14 -0
  36. data/lib/objects/poll.rb +97 -0
  37. data/lib/objects/poll_answer.rb +29 -0
  38. data/lib/objects/poll_option.rb +22 -0
  39. data/lib/objects/pre_checkout_query.rb +48 -0
  40. data/lib/objects/same/common.rb +37 -0
  41. data/lib/objects/same/common_2.rb +38 -0
  42. data/lib/objects/shipping_address.rb +39 -0
  43. data/lib/objects/shipping_query.rb +32 -0
  44. data/lib/objects/sticker.rb +55 -0
  45. data/lib/objects/update.rb +174 -0
  46. data/lib/objects/user.rb +66 -0
  47. data/lib/objects/user_profile_photos.rb +35 -0
  48. data/lib/objects/venue.rb +40 -0
  49. data/lib/objects/video.rb +37 -0
  50. data/lib/objects/video_note.rb +48 -0
  51. data/lib/objects/voice.rb +20 -0
  52. data/lib/teleruby.rb +4 -40
  53. data/lib/teleruby/all_apis.rb +22 -0
  54. data/lib/teleruby/api/delete_apis.rb +58 -0
  55. data/lib/teleruby/api/get_apis.rb +172 -0
  56. data/lib/teleruby/api/nstandard.rb +27 -0
  57. data/lib/teleruby/api/other_apis.rb +241 -0
  58. data/lib/teleruby/api/send_apis.rb +206 -0
  59. data/lib/teleruby/api/set_apis.rb +137 -0
  60. data/lib/teleruby/core_api.rb +52 -0
  61. data/lib/teleruby/objects/all.rb +42 -0
  62. data/lib/teleruby/objects/animation.rb +40 -0
  63. data/lib/teleruby/objects/audio.rb +39 -0
  64. data/lib/teleruby/objects/bot_command.rb +24 -0
  65. data/lib/teleruby/objects/callback_query.rb +66 -0
  66. data/lib/teleruby/objects/chat.rb +164 -0
  67. data/lib/teleruby/objects/chat_member.rb +142 -0
  68. data/lib/teleruby/objects/chat_permissions.rb +59 -0
  69. data/lib/teleruby/objects/chat_photo.rb +37 -0
  70. data/lib/teleruby/objects/chosen_inline_result.rb +45 -0
  71. data/lib/teleruby/objects/contact.rb +37 -0
  72. data/lib/teleruby/objects/dice.rb +21 -0
  73. data/lib/teleruby/objects/document.rb +29 -0
  74. data/lib/teleruby/objects/file.rb +32 -0
  75. data/lib/teleruby/objects/game.rb +65 -0
  76. data/lib/teleruby/objects/inline_query.rb +44 -0
  77. data/lib/teleruby/objects/inlinekeyboardbutton.rb +59 -0
  78. data/lib/teleruby/objects/inlinekeyboardmarkup.rb +31 -0
  79. data/lib/teleruby/objects/location.rb +21 -0
  80. data/lib/teleruby/objects/mask_position.rb +35 -0
  81. data/lib/teleruby/objects/message.rb +400 -0
  82. data/lib/teleruby/objects/message_entity.rb +95 -0
  83. data/lib/teleruby/objects/order_info.rb +36 -0
  84. data/lib/teleruby/objects/photo_size.rb +14 -0
  85. data/lib/teleruby/objects/poll.rb +97 -0
  86. data/lib/teleruby/objects/poll_answer.rb +29 -0
  87. data/lib/teleruby/objects/poll_option.rb +22 -0
  88. data/lib/teleruby/objects/pre_checkout_query.rb +50 -0
  89. data/lib/teleruby/objects/same/common.rb +31 -0
  90. data/lib/teleruby/objects/same/common_2.rb +32 -0
  91. data/lib/teleruby/objects/shipping_address.rb +39 -0
  92. data/lib/teleruby/objects/shipping_query.rb +32 -0
  93. data/lib/teleruby/objects/sticker.rb +59 -0
  94. data/lib/teleruby/objects/update.rb +207 -0
  95. data/lib/teleruby/objects/user.rb +66 -0
  96. data/lib/teleruby/objects/user_profile_photos.rb +36 -0
  97. data/lib/teleruby/objects/venue.rb +40 -0
  98. data/lib/teleruby/objects/video.rb +39 -0
  99. data/lib/teleruby/objects/video_note.rb +50 -0
  100. data/lib/teleruby/objects/voice.rb +20 -0
  101. data/lib/teleruby/version.rb +3 -0
  102. data/msg.png +0 -0
  103. data/rdoc.png +0 -0
  104. data/teleruby.gemspec +9 -7
  105. metadata +109 -6
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../core_api'
5
+
6
+ ##
7
+ # Solomon Boloshe(Lee Crey)
8
+ # Friday, August 21 2020 04:52:49 PM +0300
9
+
10
+ module Telegram
11
+ module GetApis # rubocop:disable Metrics/ModuleLength
12
+ include CoreApi
13
+ # Use this method to receive incoming updates using long polling.
14
+ def get_updates(limit: 10, type: nil) # rubocop:disable Metrics/MethodLength
15
+ hash = { 'timeout': 0, 'limit': limit, 'offset': @last_update }
16
+ if type and (type.instance_of? Array)
17
+ hash.merge!({ allowed_updates: type })
18
+ end
19
+ response = http_get('getUpdates', hash)
20
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
21
+ raise TelegramError, response.desciption
22
+ end
23
+
24
+ result = response.result
25
+ if result.instance_of? Array
26
+ @last_update = result.last.update_id + 1 if result.last
27
+ end
28
+
29
+ updates = []
30
+ result.each do |update|
31
+ updates << Update.new(update)
32
+ end
33
+ updates
34
+ end
35
+ # rubocop:enalbe Metrics/MethodLength
36
+
37
+ # A simple method for testing your bot's authentication token.
38
+ def get_me
39
+ response = http_get('getMe')
40
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
41
+ raise TokenError, 'incorrect bot token'
42
+ end
43
+ BotUser.new(response.result)
44
+ end
45
+
46
+ # Use this method to get basic info about a file.
47
+ # Returns TFile object
48
+ def get_file(file_id)
49
+ hash = { file_id: file_id }
50
+ response = http_get('getFile', hash)
51
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
52
+ raise IdError, 'incorrect file id'
53
+ end
54
+ TFile.new(response.result)
55
+ end
56
+
57
+ # Use this method to get a list of profile pictures for a user.
58
+ def get_profile_photos(user_id, params = {}) # rubocop:disable Metrics/MethodLength
59
+ if user_id.to_i.negative? # rubocop:disable Style/IfUnlessModifier
60
+ raise IdError, 'id must be private chat\'s id'
61
+ end
62
+
63
+ hash = { uesr_id: user_id }.merge!(params)
64
+ response = http_get('getProfilePhotos', hash)
65
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
66
+ raise TelegramError, response.description
67
+ end
68
+
69
+ result = response.result
70
+ if result.instance_of? Array
71
+ profile = []
72
+ result.each do |e|
73
+ profile << ProfilePhoto.new(e)
74
+ end
75
+ return profile
76
+ end
77
+ ProfilePhoto.new(result)
78
+ end
79
+
80
+ # Use this method to get a list of administrators in a chat.
81
+ def get_chat_admins(chat_id)
82
+ unless chat_id.to_i.negative? # rubocop:disable Style/IfUnlessModifier
83
+ raise IdError, 'chat id must be supergroup id'
84
+ end
85
+ hash = { chat_id: chat_id }
86
+ response = http_get('getChatAdministrators', hash)
87
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
88
+ raise FatalError, 'fatal error'
89
+ end
90
+
91
+ result = response.result
92
+ users = []
93
+ result.each do |user|
94
+ users << ChatMember.new(user)
95
+ end
96
+ users
97
+ end
98
+ # rubocop:enable Metrics/MethodLength
99
+
100
+ # Use this method to get the number of members in a chat.
101
+ def get_chat_members_count(chat_id)
102
+ hash = { chat_id: chat_id }
103
+ response = http_get('getChatMemebersCount', hash)
104
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
105
+ raise IdError, %{don't use private chat id}
106
+ end
107
+ response.result
108
+ end
109
+
110
+ # Use this method to get information about a member of a chat.
111
+ def get_chat_member(chat_id, user_id)
112
+ hash = { chat_id: chat_id, user_id: user_id }
113
+ response = http_get('getChatMember', hash)
114
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
115
+ raise FatalError, response.description
116
+ end
117
+ ChatMember.new(response.result)
118
+ end
119
+
120
+ # Use this method to get a sticker set.
121
+ def get_sticker_set_name(name)
122
+ hash = { name: name }
123
+ response = http_get('getStickerSetName', hash)
124
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
125
+ raise Error, %{incorrect sticker set name}
126
+ end
127
+ StickerSet.new(response.result)
128
+ end
129
+
130
+ # Use this method to get up to date information about the chat.
131
+ def get_chat(chat_id) # rubocop:disable Metrics/MethodLength
132
+ hash = { chat_id: chat_id }
133
+ response = http_get('getChat', hash)
134
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
135
+ raise IdError, %{incorrect chat id}
136
+ end
137
+
138
+ if chat_id.negative?
139
+ return GetChat.new(response.result)
140
+ end
141
+ PrivateChat.new(response.result)
142
+ end
143
+
144
+ # Use this method to get the current list of the bot's commands.
145
+ def get_my_commands # rubocop:disable Metrics/MethodLength
146
+ response = http_get('getMyCommands')
147
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
148
+ raise TokenError, %{seems bot token error}
149
+ end
150
+
151
+ commands = []
152
+ result = response.result
153
+ result.each do |command|
154
+ commands << BotCommand.new(command)
155
+ end
156
+ commands
157
+ end
158
+ end
159
+ # rubocop:enable Metrics/ModuleLength
160
+
161
+ # The End!
162
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'open-uri'
5
+
6
+ module Telegram
7
+ module NonStandard
8
+ def download_file(file_d, dir = Dir.pwd)
9
+ raise NotImplementedError, 'not implemented'
10
+ end
11
+
12
+ def download_file_from(uri, dir = Dir.pwd)
13
+ uri = URI.parse(uri)
14
+ end
15
+
16
+ # use 'markdown'
17
+ def create_user_link(name, user_id)
18
+ "[#{name}](tg://user?id=#{id})"
19
+ end
20
+
21
+ # use 'markdow' for parse_mode
22
+ def create_text_link(message, url)
23
+ "[#{message}](#{url})"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,225 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../core_api'
5
+
6
+ module Telegram
7
+ module OtherApis
8
+ include CoreApi
9
+ # Use this method to forward messages of any kind.
10
+ def forward_message(from_chat_id, to_chat_id, message_id, params = {})
11
+ hash = { chat_id: to_chat_id, from_chat_id: from_chat_id }
12
+ hash2 = { message_id: message_id }.merge!(params)
13
+ hash.merge!(hash2)
14
+ data = http_post('forwardMessage', hash)
15
+ unless data.ok # rubocop:disable Style/IfUnlessModifier
16
+ raise TelegramError, data.description
17
+ end
18
+ data.result
19
+ end
20
+
21
+ # Use this method to kick a user from a group, a supergroup
22
+ # or a channel.
23
+ def kick_chat_member(chat_id, user_id, params = {})
24
+ hash = { chat_id: chat_id, user_id: user_id }.merge!(params)
25
+ data = http_post('kickChatMember', hash)
26
+ unless data.ok # rubocop:disable Style/IfUnlessModifier
27
+ raise TelegramError, data.description
28
+ end
29
+ data.result
30
+ end
31
+
32
+ # Use this method to unban a previously kicked user in a
33
+ # supergroup or channel.
34
+ def unban_chat_member(chat_id, user_id)
35
+ hash = { chat_id: chat_id, user_id: user_id }
36
+ data = http_post('unbanChatMember', hash)
37
+ unless data.ok # rubocop:disable Style/IfUnlessModifier
38
+ raise TelegramError, data.description
39
+ end
40
+ data.result
41
+ end
42
+
43
+ # Use this method to restrict a user in a supergroup.
44
+ def restrict_chat_member(chat_id, user_id, permissions, params = {})
45
+ hash = { chat_id: chat_id, user_id: user_id }
46
+ hash2 = { permissions: permissions }
47
+ hash.merge!(hash2)
48
+ data = http_post('restrictChatMember', hash)
49
+ unless data.ok # rubocop:disable Style/IfUnlessModifier
50
+ raise TelegramError, data.description
51
+ end
52
+ data.result
53
+ end
54
+
55
+ # Use this method to promote or demote a user in a supergroup or
56
+ # a channel.
57
+ def promote_chat_member(chat_id, user_id, params = {})
58
+ hash = { chat_id: chat_id, user_id: user_id }.merge!(params)
59
+ data = http_post('promoteChatMember', hash)
60
+ unless data.ok # rubocop:disable Style/IfUnlessModifier
61
+ raise TelegramError, data.description
62
+ end
63
+ data.result
64
+ end
65
+
66
+ # Use this method to generate a new invite link for a chat.
67
+ def export_chat_link(chat_id)
68
+ hash = { chat_id: chat_id }
69
+ response = http_post('exportChatInviteLink', hash)
70
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
71
+ raise TelegramError, response.description
72
+ end
73
+ response.result
74
+ end
75
+
76
+ # Use this method to pin a message in a group, a supergroup,
77
+ # or a channel.
78
+ def pin_chat_message(chat_id, message_id, params = {})
79
+ hash = { chat_id: chat_id, message_id: message_id }.merge!(params)
80
+ response = http_post('pinChatMessage', hash)
81
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
82
+ raise SecurityError, response.description
83
+ end
84
+ response.result
85
+ end
86
+
87
+ # Use this method to stop a poll which was sent by the bot.
88
+ def stop_poll(chat_id, message_id, params = {})
89
+ hash = { chat_id: chat_id, message_id: message_id }.merge!(params)
90
+ response = http_post('stopPoll', hash)
91
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
92
+ raise Error, response.description
93
+ end
94
+ response.result
95
+ end
96
+
97
+ # Use this method to upload a .PNG file with a sticker for later use
98
+ # in createNewStickerSet and addStickerToSet methods
99
+ # (can be used multiple times).
100
+ def upload_sticker_file(user_id, png_sticker)
101
+ hash = { user_id: user_id, png_sticker: png_sticker }
102
+ response = http_post('uploadStickerFile', hash)
103
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
104
+ raise Error, response.description
105
+ end
106
+ response.result
107
+ end
108
+
109
+ # Use this method to create a new sticker set owned by a user.
110
+ # The bot will be able to edit the sticker set thus created.
111
+ # You must use exactly one of the fields png_sticker or tgs_sticker.
112
+ def create_new_stricker_set(user_id, name, title, params = {})
113
+ hash = { user_id: user_id, name: name, title: title }.merge!(params)
114
+ response = http_post('createNewStickerSet', hash)
115
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
116
+ raise Error, response.description
117
+ end
118
+ response.result
119
+ end
120
+
121
+ # Use this method to add a new sticker to a set created by the bot.
122
+ def add_sticker_to_set(user_id, name, emojis, params = {})
123
+ hash = { user_id: user_id, name: name, emojis: emojis }.merge!(params)
124
+ response = http_post('addStickerToSet', hash)
125
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
126
+ raise StandardError, response.description
127
+ end
128
+ response.result
129
+ end
130
+
131
+ def edit_message_live_location
132
+ raise NotImplementedError, 'not implemented'
133
+ end
134
+
135
+ # Use this method to send answers to callback queries sent from inline
136
+ # keyboards. The answer will be displayed to the user as a notification
137
+ # at the top of the chat screen or as an alert. On success, True is
138
+ # returned.
139
+ def answer_callback_query(callback_query_id, params = {})
140
+ hash = { callback_query_id: callback_query_id }.merge!(params)
141
+ response = http_post('answerCallbackQuery', hash)
142
+ unless response.ok
143
+ raise FatalError, response.description
144
+ end
145
+ response.result
146
+ end
147
+
148
+ def delete_webhook
149
+ raise NotImplementedError, 'not support for now'
150
+ end
151
+
152
+ # Use this method to edit text and game messages. On success,
153
+ # if edited message is sent by the bot, the edited Message is returned,
154
+ # otherwise True is returned.
155
+ def edit_message_text(text, params = {})
156
+ hash = { text: text }.merge!(params)
157
+ response = http_post('editMessageText', hash)
158
+ unless response.ok
159
+ raise FatalError, response.description
160
+ end
161
+ if response.result == true
162
+ return true
163
+ end
164
+ Message.new(response.result)
165
+ end
166
+
167
+ # Use this method to edit captions of messages. On success, if edited
168
+ # message is sent by the bot, the edited Message is returned, otherwise
169
+ # True is returned.
170
+ def edit_message_caption(params = {})
171
+ response = http_post('editMessageCaption', params)
172
+ unless response.ok
173
+ raise FatalError, response.description
174
+ end
175
+ if response.result == true
176
+ return true
177
+ end
178
+ Message.new(response.result)
179
+ end
180
+
181
+ # Use this method to edit animation, audio, document, photo, or video
182
+ # messages. If a message is a part of a message album, then it can be
183
+ # edited only to a photo or a video. Otherwise, message type can be
184
+ # changed arbitrarily. When inline message is edited, new file can't
185
+ # be uploaded. Use previously uploaded file via its file_id or specify
186
+ # a URL. On success, if the edited message was sent by the bot, the edited
187
+ # Message is returned, otherwise True is returned.
188
+ def edit_message_media(media, params = {})
189
+ hash = { media: media }.merge!(params)
190
+ response = http_post('editMessageMedia', hash)
191
+ unless response.ok
192
+ raise FatalError, response.description
193
+ end
194
+ if response.result == true
195
+ return true
196
+ end
197
+ Message.new(response.result)
198
+ end
199
+
200
+ # Use this method to edit only the reply markup of messages.
201
+ # On success, if edited message is sent by the bot, the edited Message
202
+ # is returned, otherwise True is returned.
203
+ def edit_message_reply_markup(params = {})
204
+ response = http_post('editMessageReplyMarkup', params)
205
+ unless response.ok
206
+ raise FatalError, response.description
207
+ end
208
+ if response.result == true
209
+ return true
210
+ end
211
+ Message.new(response.result)
212
+ end
213
+
214
+ # Use this method to send answers to an inline query. On success, True
215
+ # is returned. No more than 50 results per query are allowed.
216
+ def answer_inline_query(inline_query_id, result, params = {})
217
+ hash = { inline_query_id: inline_query_id, result: result }.merge!(params)
218
+ response = http_post('answerInlineQuery', hash)
219
+ unless response.ok
220
+ raise FatalError, response.description
221
+ end
222
+ response.result
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../core_api'
5
+
6
+ # Solomon Boloshe(Lee Crey)
7
+ # Friday, August 21 2020 05:35:05 PM +0300
8
+
9
+ module Telegram
10
+ module SendApis # rubocop:disable Metrics/ModuleLength
11
+ include CoreApi
12
+ # Use this method to send text messages.
13
+ def send_message(chat_id, text, params = {})
14
+ hash = { chat_id: chat_id, text: text }.merge!(params)
15
+ response = http_post('sendMessage', hash)
16
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
17
+ raise FatalError, response.description
18
+ end
19
+ Message.new(response.result)
20
+ end
21
+
22
+ # Use this method to send photos.
23
+ def send_photo(chat_id, photo, params = {})
24
+ hash = { chat_id: chat_id, photo: photo }.merge!(params)
25
+ response = http_post('sendPhoto', hash)
26
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
27
+ raise FatalError, response.description
28
+ end
29
+ Message.new(response.result)
30
+ end
31
+
32
+ # Use this method to send audio files.
33
+ def send_audio(chat_id, audio, params = {})
34
+ hash = { chat_id: chat_id, audio: audio }.merge!(params)
35
+ response = http_post('sendAudio', hash)
36
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
37
+ raise FatalError, response.description
38
+ end
39
+ Message.new(response.result)
40
+ end
41
+
42
+ # Use this method to send general files.
43
+ def send_document(chat_id, document, params = {})
44
+ hash = { chat_id: chat_id, document: document }.merge!(params)
45
+ response = http_post('sendDocument', hash)
46
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
47
+ raise FatalError, response.description
48
+ end
49
+ Message.new(response.result)
50
+ end
51
+
52
+ # Use this method to send video files, Telegram clients support
53
+ # mp4 videos (other formats may be sent as Document).
54
+ def send_video(chat_id, video, params = {})
55
+ hash = { chat_id: chat_id, video: video }.merge!(params)
56
+ response = http_post('sendVideo', hash)
57
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
58
+ raise FatalError, response.description
59
+ end
60
+ Message.new(response.result)
61
+ end
62
+
63
+ # Use this method to send animation files (GIF or H.264/MPEG-4
64
+ # AVC video without sound).
65
+ def send_animation(chat_id, animation, params = {})
66
+ hash = { chat_id: chat_id, animation: animation }.merge!(params)
67
+ response = http_post('sendAnimation', hash)
68
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
69
+ raise FatalError, response.description
70
+ end
71
+ Message.new(response.result)
72
+ end
73
+
74
+ # Use this method to send voice file
75
+ def send_voice(chat_id, voice, params = {})
76
+ hash = { chat_id: chat_id, voice: voice }.merge!(params)
77
+ response = http_post('sendVoice', hash)
78
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
79
+ raise FatalError, response.description
80
+ end
81
+ Message.new(response.result)
82
+ end
83
+
84
+ # Use this methods to send video note file
85
+ def send_video_note(chat_id, video_note, params = {})
86
+ hash = { chat_id: chat_id, video_note: video_note }.merge!(params)
87
+ response = http_post('sendVideoNote', hash)
88
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
89
+ raise FatalError, response.description
90
+ end
91
+ Message.new(response.result)
92
+ end
93
+
94
+ # Use this method to send a group of photos or videos as an album.
95
+ def send_media_group(chat_id, media, params = {})
96
+ hash = { chat_id: chat_id, media: media }.merge!(params)
97
+ response = http_post('sendMediaGroup', hash)
98
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
99
+ raise FatalError, response.description
100
+ end
101
+ Message.new(response.result)
102
+ end
103
+
104
+ # Use this method to send point on the map.
105
+ def send_location(chat_id, latitude, longitude, params = {})
106
+ hash = { chat_id: chat_id, latitude: latitude, longitude: longitude}
107
+ hash.merge!(params)
108
+ response = http_post('sendLocation', hash)
109
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
110
+ raise FatalError, response.description
111
+ end
112
+ Message.new(response.result)
113
+ end
114
+
115
+ # Use this method to send information about a venue.
116
+ def send_venue(chat_id, latitude, longitude, title, address, params = {})
117
+ hash = { chat_id: chat_id, latitude: latitude, longitude: longitude }
118
+ hash2 = { title: title, address: address}.merge!(params)
119
+ hash.merge!(hash2)
120
+ response = http_post('sendVenue', hash)
121
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
122
+ raise FatalError, response.description
123
+ end
124
+ Message.new(response.result)
125
+ end
126
+
127
+ # Use this method to send phone contacts.
128
+ def send_contact(chat_id, phone_number, first_name, params = {})
129
+ hash = { chat_id: chat_id, phone_number: phone_number }
130
+ hash2 = { first_name: first_name }.merge!(params)
131
+ hash.merge!(hash2)
132
+ response = http_post('sendContact', hash)
133
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
134
+ raise FatalError, response.description
135
+ end
136
+ Message.new(response.result)
137
+ end
138
+
139
+ # Use this method to send a native poll.
140
+ def send_poll(chat_id, question, options, params = {})
141
+ hash = { chat_id: chat_id, question: question }
142
+ hash2 = { options: options }.merge!(params)
143
+ hash.merge!(hash2)
144
+ response = http_post('sendPoll', hash)
145
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
146
+ raise FatalError, response.description
147
+ end
148
+ Message.new(response.result)
149
+ end
150
+
151
+ # Use this method to send an animated emoji that will display a
152
+ # random value.
153
+ def send_dice(chat_id, params = {})
154
+ hash = { chat_id: chat_id}.merge!(params)
155
+ response = http_post('sendDice', hash)
156
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
157
+ raise FatalError, response.description
158
+ end
159
+ Message.new(response.description)
160
+ end
161
+
162
+ # Use this methods to send chat actions
163
+ # actions may be typing upload_photo record_video upload_video
164
+ # upload_audio upload_document find_location record_video_note
165
+ # upload_video_note
166
+ def send_chat_action(chat_id, action) # rubocop:disable: Metrics/MethodLength
167
+ actions = %w{ typing upload_photo record_video upload_video
168
+ upload_audio upload_document find_location record_video_note
169
+ upload_video_note }
170
+ unless actions.include? action # rubocop:disable Style/IfUnlessModifier
171
+ raise Error, 'invalid chat action'
172
+ end
173
+ hash = { chat_id: chat_id, action: action }
174
+ response = http_post('sendChatAction', hash)
175
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
176
+ raise IdError, 'incorrect chat id'
177
+ end
178
+ response.result
179
+ end
180
+
181
+ # Use this method to send sticker file
182
+ def send_sticker(chat_id, file, params = {})
183
+ hash = { chat_id: chat_id, sticker: file }.merge!(params)
184
+ response = http_post('sendSticker', hash)
185
+ unless response.ok # rubocop:disable Style/IfUnlessModifier
186
+ raise FatalError, response.description
187
+ end
188
+ Message.new(response.result)
189
+ end
190
+ end
191
+ end