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.
- checksums.yaml +4 -4
- data/LICENSE.md +9 -0
- data/README.md +398 -0
- data/lib/api/all.rb +12 -0
- data/lib/api/delete_apis.rb +55 -0
- data/lib/api/get_apis.rb +162 -0
- data/lib/api/nstandard.rb +26 -0
- data/lib/api/other_apis.rb +225 -0
- data/lib/api/send_apis.rb +191 -0
- data/lib/api/set_apis.rb +130 -0
- data/lib/core_api.rb +41 -0
- data/lib/objects/all.rb +42 -0
- data/lib/objects/animation.rb +38 -0
- data/lib/objects/audio.rb +37 -0
- data/lib/objects/bot_command.rb +24 -0
- data/lib/objects/callback_query.rb +64 -0
- data/lib/objects/chat.rb +158 -0
- data/lib/objects/chat_member.rb +142 -0
- data/lib/objects/chat_permissions.rb +59 -0
- data/lib/objects/chat_photo.rb +37 -0
- data/lib/objects/chosen_inline_result.rb +43 -0
- data/lib/objects/contact.rb +37 -0
- data/lib/objects/dice.rb +21 -0
- data/lib/objects/document.rb +27 -0
- data/lib/objects/file.rb +32 -0
- data/lib/objects/game.rb +65 -0
- data/lib/objects/inline_query.rb +42 -0
- data/lib/objects/inlinekeyboardbutton.rb +59 -0
- data/lib/objects/inlinekeyboardmarkup.rb +30 -0
- data/lib/objects/location.rb +21 -0
- data/lib/objects/mask_position.rb +35 -0
- data/lib/objects/message.rb +378 -0
- data/lib/objects/message_entity.rb +93 -0
- data/lib/objects/order_info.rb +34 -0
- data/lib/objects/photo_size.rb +14 -0
- data/lib/objects/poll.rb +97 -0
- data/lib/objects/poll_answer.rb +29 -0
- data/lib/objects/poll_option.rb +22 -0
- data/lib/objects/pre_checkout_query.rb +48 -0
- data/lib/objects/same/common.rb +37 -0
- data/lib/objects/same/common_2.rb +38 -0
- data/lib/objects/shipping_address.rb +39 -0
- data/lib/objects/shipping_query.rb +32 -0
- data/lib/objects/sticker.rb +55 -0
- data/lib/objects/update.rb +174 -0
- data/lib/objects/user.rb +66 -0
- data/lib/objects/user_profile_photos.rb +35 -0
- data/lib/objects/venue.rb +40 -0
- data/lib/objects/video.rb +37 -0
- data/lib/objects/video_note.rb +48 -0
- data/lib/objects/voice.rb +20 -0
- data/lib/teleruby.rb +4 -40
- data/lib/teleruby/all_apis.rb +22 -0
- data/lib/teleruby/api/delete_apis.rb +58 -0
- data/lib/teleruby/api/get_apis.rb +172 -0
- data/lib/teleruby/api/nstandard.rb +27 -0
- data/lib/teleruby/api/other_apis.rb +241 -0
- data/lib/teleruby/api/send_apis.rb +206 -0
- data/lib/teleruby/api/set_apis.rb +137 -0
- data/lib/teleruby/core_api.rb +52 -0
- data/lib/teleruby/objects/all.rb +42 -0
- data/lib/teleruby/objects/animation.rb +40 -0
- data/lib/teleruby/objects/audio.rb +39 -0
- data/lib/teleruby/objects/bot_command.rb +24 -0
- data/lib/teleruby/objects/callback_query.rb +66 -0
- data/lib/teleruby/objects/chat.rb +164 -0
- data/lib/teleruby/objects/chat_member.rb +142 -0
- data/lib/teleruby/objects/chat_permissions.rb +59 -0
- data/lib/teleruby/objects/chat_photo.rb +37 -0
- data/lib/teleruby/objects/chosen_inline_result.rb +45 -0
- data/lib/teleruby/objects/contact.rb +37 -0
- data/lib/teleruby/objects/dice.rb +21 -0
- data/lib/teleruby/objects/document.rb +29 -0
- data/lib/teleruby/objects/file.rb +32 -0
- data/lib/teleruby/objects/game.rb +65 -0
- data/lib/teleruby/objects/inline_query.rb +44 -0
- data/lib/teleruby/objects/inlinekeyboardbutton.rb +59 -0
- data/lib/teleruby/objects/inlinekeyboardmarkup.rb +31 -0
- data/lib/teleruby/objects/location.rb +21 -0
- data/lib/teleruby/objects/mask_position.rb +35 -0
- data/lib/teleruby/objects/message.rb +400 -0
- data/lib/teleruby/objects/message_entity.rb +95 -0
- data/lib/teleruby/objects/order_info.rb +36 -0
- data/lib/teleruby/objects/photo_size.rb +14 -0
- data/lib/teleruby/objects/poll.rb +97 -0
- data/lib/teleruby/objects/poll_answer.rb +29 -0
- data/lib/teleruby/objects/poll_option.rb +22 -0
- data/lib/teleruby/objects/pre_checkout_query.rb +50 -0
- data/lib/teleruby/objects/same/common.rb +31 -0
- data/lib/teleruby/objects/same/common_2.rb +32 -0
- data/lib/teleruby/objects/shipping_address.rb +39 -0
- data/lib/teleruby/objects/shipping_query.rb +32 -0
- data/lib/teleruby/objects/sticker.rb +59 -0
- data/lib/teleruby/objects/update.rb +207 -0
- data/lib/teleruby/objects/user.rb +66 -0
- data/lib/teleruby/objects/user_profile_photos.rb +36 -0
- data/lib/teleruby/objects/venue.rb +40 -0
- data/lib/teleruby/objects/video.rb +39 -0
- data/lib/teleruby/objects/video_note.rb +50 -0
- data/lib/teleruby/objects/voice.rb +20 -0
- data/lib/teleruby/version.rb +3 -0
- data/msg.png +0 -0
- data/rdoc.png +0 -0
- data/teleruby.gemspec +9 -7
- metadata +109 -6
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative 'same/common_2'
|
5
|
+
|
6
|
+
##
|
7
|
+
# +Monday+, +August+ +24+ +2020+ +EAT+
|
8
|
+
# ===This object represents a voice note.
|
9
|
+
# Extends Common2 class.
|
10
|
+
|
11
|
+
class Voice < Common2
|
12
|
+
def initialize(obj) # :nodoc:
|
13
|
+
super(obj)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Duration of the audio in seconds as defined by sender.
|
17
|
+
def duration
|
18
|
+
@obj.duration
|
19
|
+
end
|
20
|
+
end
|
data/lib/teleruby.rb
CHANGED
@@ -1,50 +1,14 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
-
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require_relative '
|
5
|
-
|
6
|
-
##
|
7
|
-
# @lee_crey (Solomon Boloshe)
|
8
|
-
#
|
9
|
-
# @teleruby_support
|
3
|
+
require_relative 'api/all'
|
10
4
|
|
11
5
|
module Telegram
|
12
|
-
#
|
13
|
-
class
|
14
|
-
|
15
|
-
# Raise when chat_id, and user_id are incorrect,
|
16
|
-
class IdError < Error; end
|
17
|
-
|
18
|
-
# Raise when bot token is incorrect.
|
19
|
-
class TokenError < Error; end
|
20
|
-
|
21
|
-
# Raise when bot has not appropriate admin right in supergroups.
|
22
|
-
class PermissionError < Error; end
|
23
|
-
|
24
|
-
# Raise when one of optional parameters is incorrect and telegram
|
25
|
-
# unalbe to do the requested operation.
|
26
|
-
class TelegramError < Error; end
|
27
|
-
|
28
|
-
class FatalError < Error; end
|
29
|
-
class BadRequestError < Error; end
|
30
|
-
class UndefinedMethod < Error; end
|
31
|
-
|
32
|
-
# === Bot class
|
33
|
-
class Client < TGClient
|
6
|
+
# Telegram CLient(bot)
|
7
|
+
class Client
|
34
8
|
include AllApis
|
35
|
-
def initialize(token)
|
9
|
+
def initialize(token: )
|
36
10
|
@token = token
|
37
11
|
@last_update = 0
|
38
12
|
end
|
39
|
-
|
40
|
-
# for getting updates
|
41
|
-
# long polling
|
42
|
-
def run!(&block)
|
43
|
-
(fail LocalJumpError, 'block is not given' unless block_given?)
|
44
|
-
loop do
|
45
|
-
block.call
|
46
|
-
end
|
47
|
-
end
|
48
13
|
end
|
49
14
|
end
|
50
|
-
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: false
|
3
|
+
|
4
|
+
# APIs
|
5
|
+
require_relative 'api/send_apis'
|
6
|
+
require_relative 'api/set_apis'
|
7
|
+
require_relative 'api/delete_apis'
|
8
|
+
require_relative 'api/other_apis'
|
9
|
+
require_relative 'api/get_apis'
|
10
|
+
require_relative 'api/nstandard'
|
11
|
+
|
12
|
+
module Telegram
|
13
|
+
module AllApis
|
14
|
+
# directory => api
|
15
|
+
include SendApis # send_apis.rb
|
16
|
+
include SetApis # set_apis.rb
|
17
|
+
include DeleteApis # delete_apis.rb
|
18
|
+
include OtherApis # other_apis.rb
|
19
|
+
include GetApis # get_apis.rb
|
20
|
+
include NonStandard # nstandard.rb
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../core_api'
|
5
|
+
|
6
|
+
module Telegram
|
7
|
+
module DeleteApis
|
8
|
+
##
|
9
|
+
# Use this method to delete a chat photo.
|
10
|
+
def delete_chat_photo(chat_id)
|
11
|
+
unless chat_id.to_i.negative?
|
12
|
+
fail BadRequestError, %{can't delete private chat photo}
|
13
|
+
end
|
14
|
+
|
15
|
+
hash = { chat_id: chat_id }
|
16
|
+
response = post('deleteChatPhoto', hash)
|
17
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
18
|
+
fail PermissionError, response.description
|
19
|
+
end
|
20
|
+
|
21
|
+
response.result
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Use this method to delete a group sticker set from a supergroup.
|
26
|
+
def delete_chat_sticker_set(chat_id)
|
27
|
+
unless chat_id.to_i.negative?
|
28
|
+
fail BadRequestError, %{can' delete sticker set of private chat}
|
29
|
+
end
|
30
|
+
|
31
|
+
hash = { chat_id: chat_id }
|
32
|
+
response = post('deleteChatStickerSet', hash)
|
33
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
34
|
+
fail PermissionError, response.description
|
35
|
+
end
|
36
|
+
|
37
|
+
response.result
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Use this method to delete a message, including service messages.
|
42
|
+
def delete_message(chat_id, message_id)
|
43
|
+
hash = { chat_id: chat_id, message_id: message_id }
|
44
|
+
response = post('deleteMessage', hash)
|
45
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
46
|
+
fail TelegramError, response.description
|
47
|
+
end
|
48
|
+
|
49
|
+
response.result
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Use this method to delete a sticker from a set created by the bot.
|
54
|
+
def delete_sticker_from_set(sticker)
|
55
|
+
throw NotImplementedError, 'currently not supported'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,172 @@
|
|
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
|
+
##
|
13
|
+
# Use this method to receive incoming updates using long polling.
|
14
|
+
def get_updates(limit = 10, &block) # rubocop:disable Metrics/MethodLength
|
15
|
+
blok = {}
|
16
|
+
if block_given?
|
17
|
+
blok = block.call
|
18
|
+
unless blok.instance_of? Hash # rubocop:disable Style/IfUnlessModifier
|
19
|
+
fail ArgumentError, 'expected object is hash'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
hash = { 'timeout': 0, 'limit': limit, 'offset': @last_update }
|
24
|
+
hash.merge!(blok)
|
25
|
+
response = get('getUpdates', hash)
|
26
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
27
|
+
fail TelegramError, response.desciption
|
28
|
+
end
|
29
|
+
|
30
|
+
result = response.result
|
31
|
+
if result.instance_of? Array
|
32
|
+
@last_update = result.last.update_id + 1 if result.last
|
33
|
+
end
|
34
|
+
|
35
|
+
updates = []
|
36
|
+
result.each do |update|
|
37
|
+
updates << Update.new(update)
|
38
|
+
end
|
39
|
+
updates
|
40
|
+
end
|
41
|
+
# rubocop:enalbe Metrics/MethodLength
|
42
|
+
|
43
|
+
# A simple method for testing your bot's authentication token.
|
44
|
+
def get_me
|
45
|
+
response = get('getMe')
|
46
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
47
|
+
fail TokenError, 'incorrect bot token'
|
48
|
+
end
|
49
|
+
BotUser.new(response.result)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Use this method to get basic info about a file.
|
53
|
+
# Returns TFile object
|
54
|
+
def get_file(file_id)
|
55
|
+
hash = { file_id: file_id }
|
56
|
+
response = get('getFile', hash)
|
57
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
58
|
+
fail IdError, 'incorrect file id'
|
59
|
+
end
|
60
|
+
TFile.new(response.result)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Use this method to get a list of profile pictures for a user.
|
64
|
+
def get_profile_photos(user_id, params = {}) # rubocop:disable Metrics/MethodLength
|
65
|
+
if user_id.to_i.negative? # rubocop:disable Style/IfUnlessModifier
|
66
|
+
fail IdError, 'id must be private chat\'s id'
|
67
|
+
end
|
68
|
+
|
69
|
+
hash = { uesr_id: user_id }.merge!(params)
|
70
|
+
response = get('getProfilePhotos', hash)
|
71
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
72
|
+
fails TelegramError, response.description
|
73
|
+
end
|
74
|
+
|
75
|
+
result = response.result
|
76
|
+
if result.instance_of? Array
|
77
|
+
profile = []
|
78
|
+
result.each do |e|
|
79
|
+
profile << ProfilePhoto.new(e)
|
80
|
+
end
|
81
|
+
return profile
|
82
|
+
end
|
83
|
+
ProfilePhoto.new(result)
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Use this method to get a list of administrators in a chat.
|
88
|
+
def get_chat_admins(chat_id)
|
89
|
+
unless chat_id.to_i.negative? # rubocop:disable Style/IfUnlessModifier
|
90
|
+
fail IdError, 'chat id must be supergroup id'
|
91
|
+
end
|
92
|
+
hash = { chat_id: chat_id }
|
93
|
+
response = get('getChatAdministrators', hash)
|
94
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
95
|
+
fail FatalError, 'fatal error'
|
96
|
+
end
|
97
|
+
|
98
|
+
result = response.result
|
99
|
+
users = []
|
100
|
+
result.each do |user|
|
101
|
+
users << ChatMember.new(user)
|
102
|
+
end
|
103
|
+
users
|
104
|
+
end
|
105
|
+
# rubocop:enable Metrics/MethodLength
|
106
|
+
|
107
|
+
##
|
108
|
+
# Use this method to get the number of members in a chat.
|
109
|
+
def get_chat_members_count(chat_id)
|
110
|
+
hash = { chat_id: chat_id }
|
111
|
+
response = get('getChatMemebersCount', hash)
|
112
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
113
|
+
raise IdError, %{don't use private chat id}
|
114
|
+
end
|
115
|
+
response.result
|
116
|
+
end
|
117
|
+
|
118
|
+
# Use this method to get information about a member of a chat.
|
119
|
+
def get_chat_member(chat_id, user_id)
|
120
|
+
hash = { chat_id: chat_id, user_id: user_id }
|
121
|
+
response = get('getChatMember', hash)
|
122
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
123
|
+
fail FatalError, response.description
|
124
|
+
end
|
125
|
+
ChatMember.new(response.result)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Use this method to get a sticker set.
|
129
|
+
def get_sticker_set_name(name)
|
130
|
+
hash = { name: name }
|
131
|
+
response = get('getStickerSetName', hash)
|
132
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
133
|
+
fail Error, %{incorrect sticker set name}
|
134
|
+
end
|
135
|
+
StickerSet.new(response.result)
|
136
|
+
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# Use this method to get up to date information about the chat.
|
140
|
+
def get_chat(chat_id) # rubocop:disable Metrics/MethodLength
|
141
|
+
hash = { chat_id: chat_id }
|
142
|
+
response = get('getChat', hash)
|
143
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
144
|
+
fail IdError, %{incorrect chat id}
|
145
|
+
end
|
146
|
+
|
147
|
+
if chat_id.negative?
|
148
|
+
return GetChat.new(response.result)
|
149
|
+
end
|
150
|
+
PrivateChat.new(response.result)
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# Use this method to get the current list of the bot's commands.
|
155
|
+
def get_my_commands # rubocop:disable Metrics/MethodLength
|
156
|
+
response = get('getMyCommands')
|
157
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
158
|
+
fail TokenError, %{seems bot token error}
|
159
|
+
end
|
160
|
+
|
161
|
+
commands = []
|
162
|
+
result = response.result
|
163
|
+
result.each do |command|
|
164
|
+
commands << BotCommand.new(command)
|
165
|
+
end
|
166
|
+
commands
|
167
|
+
end
|
168
|
+
end
|
169
|
+
# rubocop:enable Metrics/MethodLength
|
170
|
+
|
171
|
+
# The End!
|
172
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
+
d = Dir.new(dir)
|
10
|
+
end
|
11
|
+
|
12
|
+
def download_file_from(uri, dir = Dir.pwd)
|
13
|
+
uri = URI.parse(uri)
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
# use 'markdown'
|
18
|
+
def create_user_link(name, user_id)
|
19
|
+
"[#{name}](tg://user?id=#{id})"
|
20
|
+
end
|
21
|
+
|
22
|
+
# use 'markdow' for parse_mode
|
23
|
+
def create_text_link(message, url)
|
24
|
+
"[#{message}](#{url})"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,241 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../core_api'
|
5
|
+
|
6
|
+
module Telegram
|
7
|
+
module OtherApis
|
8
|
+
##
|
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 = post('forwardMessage', hash)
|
15
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
16
|
+
fail TelegramError, data.description
|
17
|
+
end
|
18
|
+
data.result
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Use this method to kick a user from a group, a supergroup
|
23
|
+
# or a channel.
|
24
|
+
def kick_chat_member(chat_id, user_id, params = {})
|
25
|
+
hash = { chat_id: chat_id, user_id: user_id }.merge!(params)
|
26
|
+
data = post('kickChatMember', hash)
|
27
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
28
|
+
fail TelegramError, data.description
|
29
|
+
end
|
30
|
+
data.result
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Use this method to unban a previously kicked user in a
|
35
|
+
# supergroup or channel.
|
36
|
+
def unban_chat_member(chat_id, user_id)
|
37
|
+
hash = { chat_id: chat_id, user_id: user_id }
|
38
|
+
data = post('unbanChatMember', hash)
|
39
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
40
|
+
fail TelegramError, data.description
|
41
|
+
end
|
42
|
+
data.result
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Use this method to restrict a user in a supergroup.
|
47
|
+
def restrict_chat_member(chat_id, user_id, permissions, params = {})
|
48
|
+
hash = { chat_id: chat_id, user_id: user_id }
|
49
|
+
hash2 = { permissions: permissions }
|
50
|
+
hash.merge!(hash2)
|
51
|
+
data = post('restrictChatMember', hash)
|
52
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
53
|
+
fail TelegramError, data.description
|
54
|
+
end
|
55
|
+
data.result
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Use this method to promote or demote a user in a supergroup or
|
60
|
+
# a channel.
|
61
|
+
def promote_chat_member(chat_id, user_id, params = {})
|
62
|
+
hash = { chat_id: chat_id, user_id: user_id }.merge!(params)
|
63
|
+
data = post('promoteChatMember', hash)
|
64
|
+
unless data.ok # rubocop:disable Style/IfUnlessModifier
|
65
|
+
fail TelegramError, data.description
|
66
|
+
end
|
67
|
+
data.result
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Use this method to generate a new invite link for a chat.
|
72
|
+
def export_chat_link(chat_id)
|
73
|
+
hash = { chat_id: chat_id }
|
74
|
+
response = post('exportChatInviteLink', hash)
|
75
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
76
|
+
fail TelegramError, response.description
|
77
|
+
end
|
78
|
+
response.result
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Use this method to pin a message in a group, a supergroup,
|
83
|
+
# or a channel.
|
84
|
+
def pin_chat_message(chat_id, message_id, params = {})
|
85
|
+
hash = { chat_id: chat_id, message_id: message_id }.merge!(params)
|
86
|
+
response = post('pinChatMessage', hash)
|
87
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
88
|
+
fail SecurityError, response.description
|
89
|
+
end
|
90
|
+
response.result
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Use this method to stop a poll which was sent by the bot.
|
95
|
+
def stop_poll(chat_id, message_id, params = {})
|
96
|
+
hash = { chat_id: chat_id, message_id: message_id }.merge!(params)
|
97
|
+
response = post('stopPoll', hash)
|
98
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
99
|
+
fail Error, response.description
|
100
|
+
end
|
101
|
+
response.result
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Use this method to upload a .PNG file with a sticker for later use
|
106
|
+
# in createNewStickerSet and addStickerToSet methods
|
107
|
+
# (can be used multiple times).
|
108
|
+
def upload_sticker_file(user_id, png_sticker)
|
109
|
+
hash = { user_id: user_id, png_sticker: png_sticker }
|
110
|
+
response = post('uploadStickerFile', hash)
|
111
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
112
|
+
fail Error, response.description
|
113
|
+
end
|
114
|
+
response.result
|
115
|
+
end
|
116
|
+
|
117
|
+
##
|
118
|
+
# Use this method to create a new sticker set owned by a user.
|
119
|
+
# The bot will be able to edit the sticker set thus created.
|
120
|
+
# You must use exactly one of the fields png_sticker or tgs_sticker.
|
121
|
+
def create_new_stricker_set(user_id, name, title, params = {})
|
122
|
+
hash = { user_id: user_id, name: name, title: title }.merge!(params)
|
123
|
+
response = post('createNewStickerSet', hash)
|
124
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
125
|
+
fail Error, response.description
|
126
|
+
end
|
127
|
+
response.result
|
128
|
+
end
|
129
|
+
|
130
|
+
##
|
131
|
+
# Use this method to add a new sticker to a set created by the bot.
|
132
|
+
def add_sticker_to_set(user_id, name, emojis, params = {})
|
133
|
+
hash = { user_id: user_id, name: name, emojis: emojis }.merge!(params)
|
134
|
+
response = post('addStickerToSet', hash)
|
135
|
+
unless response.ok # rubocop:disable Style/IfUnlessModifier
|
136
|
+
throw StandardError, response.description
|
137
|
+
end
|
138
|
+
response.result
|
139
|
+
end
|
140
|
+
|
141
|
+
def edit_message_live_location
|
142
|
+
fail NotImplementedError, 'not implemented'
|
143
|
+
end
|
144
|
+
|
145
|
+
##
|
146
|
+
# Use this method to send answers to callback queries sent from inline
|
147
|
+
# keyboards. The answer will be displayed to the user as a notification
|
148
|
+
# at the top of the chat screen or as an alert. On success, True is
|
149
|
+
# returned.
|
150
|
+
def answer_callback_query(callback_query_id, params = {})
|
151
|
+
hash = { callback_query_id: callback_query_id }.merge!(params)
|
152
|
+
response = post('answerCallbackQuery', hash)
|
153
|
+
unless response.ok
|
154
|
+
raise FatalError, response.description
|
155
|
+
end
|
156
|
+
response.result
|
157
|
+
end
|
158
|
+
|
159
|
+
def delete_webhook
|
160
|
+
fail NotImplementedError, 'not support for now'
|
161
|
+
end
|
162
|
+
|
163
|
+
##
|
164
|
+
# Use this method to edit text and game messages. On success,
|
165
|
+
# if edited message is sent by the bot, the edited Message is returned,
|
166
|
+
# otherwise True is returned.
|
167
|
+
def edit_message_text(text, params = {})
|
168
|
+
hash = { text: text }.merge!(params)
|
169
|
+
response = post('editMessageText', hash)
|
170
|
+
unless response.ok
|
171
|
+
fail FatalError, response.description
|
172
|
+
end
|
173
|
+
if response.result == true
|
174
|
+
return true
|
175
|
+
end
|
176
|
+
Message.new(response.result)
|
177
|
+
end
|
178
|
+
|
179
|
+
##
|
180
|
+
# Use this method to edit captions of messages. On success, if edited
|
181
|
+
# message is sent by the bot, the edited Message is returned, otherwise
|
182
|
+
# True is returned.
|
183
|
+
def edit_message_caption(params = {})
|
184
|
+
response = post('editMessageCaption', params)
|
185
|
+
unless response.ok
|
186
|
+
fail FatalError, response.description
|
187
|
+
end
|
188
|
+
if response.result == true
|
189
|
+
return true
|
190
|
+
end
|
191
|
+
Message.new(response.result)
|
192
|
+
end
|
193
|
+
|
194
|
+
##
|
195
|
+
# Use this method to edit animation, audio, document, photo, or video
|
196
|
+
# messages. If a message is a part of a message album, then it can be
|
197
|
+
# edited only to a photo or a video. Otherwise, message type can be
|
198
|
+
# changed arbitrarily. When inline message is edited, new file can't
|
199
|
+
# be uploaded. Use previously uploaded file via its file_id or specify
|
200
|
+
# a URL. On success, if the edited message was sent by the bot, the edited
|
201
|
+
# Message is returned, otherwise True is returned.
|
202
|
+
def edit_message_media(media, params = {})
|
203
|
+
hash = { media: media }.merge!(params)
|
204
|
+
response = post('editMessageMedia', hash)
|
205
|
+
unless response.ok
|
206
|
+
fail FatalError, response.description
|
207
|
+
end
|
208
|
+
if response.result == true
|
209
|
+
return true
|
210
|
+
end
|
211
|
+
Message.new(response.result)
|
212
|
+
end
|
213
|
+
|
214
|
+
##
|
215
|
+
# Use this method to edit only the reply markup of messages.
|
216
|
+
# On success, if edited message is sent by the bot, the edited Message
|
217
|
+
# is returned, otherwise True is returned.
|
218
|
+
def edit_message_reply_markup(params = {})
|
219
|
+
response = post('editMessageReplyMarkup', params)
|
220
|
+
unless response.ok
|
221
|
+
fail FatalError, response.description
|
222
|
+
end
|
223
|
+
if response.result == true
|
224
|
+
return true
|
225
|
+
end
|
226
|
+
Message.new(response.result)
|
227
|
+
end
|
228
|
+
|
229
|
+
##
|
230
|
+
# Use this method to send answers to an inline query. On success, True
|
231
|
+
# is returned. No more than 50 results per query are allowed.
|
232
|
+
def answer_inline_query(inline_query_id, result, params = {})
|
233
|
+
hash = { inline_query_id: inline_query_id, result: result }.merge!(params)
|
234
|
+
response = post('answerInlineQuery', hash)
|
235
|
+
unless response.ok
|
236
|
+
fail FatalError, response.description
|
237
|
+
end
|
238
|
+
response.result
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|