chatbot_helper-telegram 0.1.0
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 +7 -0
- data/.gitignore +129 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +128 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/chatbot_helper-telegram.gemspec +43 -0
- data/lib/chatbot_helper/exceptions.rb +27 -0
- data/lib/chatbot_helper/telegram.rb +47 -0
- data/lib/chatbot_helper/telegram/animation.rb +22 -0
- data/lib/chatbot_helper/telegram/audio.rb +16 -0
- data/lib/chatbot_helper/telegram/base_resource.rb +254 -0
- data/lib/chatbot_helper/telegram/callback_game.rb +11 -0
- data/lib/chatbot_helper/telegram/callback_query.rb +29 -0
- data/lib/chatbot_helper/telegram/chat.rb +16 -0
- data/lib/chatbot_helper/telegram/chat_member.rb +18 -0
- data/lib/chatbot_helper/telegram/chosen_inline_result.rb +29 -0
- data/lib/chatbot_helper/telegram/collection_resource.rb +50 -0
- data/lib/chatbot_helper/telegram/contact.rb +16 -0
- data/lib/chatbot_helper/telegram/document.rb +22 -0
- data/lib/chatbot_helper/telegram/file.rb +16 -0
- data/lib/chatbot_helper/telegram/force_reply.rb +16 -0
- data/lib/chatbot_helper/telegram/game.rb +35 -0
- data/lib/chatbot_helper/telegram/inline_keyboard_button.rb +36 -0
- data/lib/chatbot_helper/telegram/inline_keyboard_markup.rb +16 -0
- data/lib/chatbot_helper/telegram/inline_query.rb +24 -0
- data/lib/chatbot_helper/telegram/keyboard_button.rb +69 -0
- data/lib/chatbot_helper/telegram/location.rb +12 -0
- data/lib/chatbot_helper/telegram/message.rb +55 -0
- data/lib/chatbot_helper/telegram/message_entity.rb +23 -0
- data/lib/chatbot_helper/telegram/photo_size.rb +25 -0
- data/lib/chatbot_helper/telegram/reply_keyboard_markup.rb +20 -0
- data/lib/chatbot_helper/telegram/reply_keyboard_remove.rb +17 -0
- data/lib/chatbot_helper/telegram/response_parameters.rb +13 -0
- data/lib/chatbot_helper/telegram/sticker.rb +22 -0
- data/lib/chatbot_helper/telegram/toolbox.rb +27 -0
- data/lib/chatbot_helper/telegram/update.rb +28 -0
- data/lib/chatbot_helper/telegram/user.rb +16 -0
- data/lib/chatbot_helper/telegram/user_profile_photos.rb +20 -0
- data/lib/chatbot_helper/telegram/venue.rb +22 -0
- data/lib/chatbot_helper/telegram/version.rb +5 -0
- data/lib/chatbot_helper/telegram/video.rb +22 -0
- data/lib/chatbot_helper/telegram/voice.rb +16 -0
- metadata +176 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The contact resource which represents a Telegram bot API contact
|
4
|
+
class Contact < ChatbotHelper::Telegram::BaseResource
|
5
|
+
class << self
|
6
|
+
def required_fields
|
7
|
+
%w[phone_number first_name]
|
8
|
+
end
|
9
|
+
|
10
|
+
def optional_fields
|
11
|
+
%w[last_name user_id]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The document resource which represents a Telegram bot API document
|
4
|
+
class Document < ChatbotHelper::Telegram::BaseResource
|
5
|
+
class << self
|
6
|
+
def required_fields
|
7
|
+
%w[file_id]
|
8
|
+
end
|
9
|
+
|
10
|
+
def optional_fields
|
11
|
+
%w[file_name mime_type file_size]
|
12
|
+
end
|
13
|
+
|
14
|
+
def optional_objects
|
15
|
+
[
|
16
|
+
{ name: 'thumb', type: ChatbotHelper::Telegram::PhotoSize }
|
17
|
+
]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The file resource which represents a Telegram bot API file
|
4
|
+
class File < ChatbotHelper::Telegram::BaseResource
|
5
|
+
class << self
|
6
|
+
def required_fields
|
7
|
+
%w[file_id]
|
8
|
+
end
|
9
|
+
|
10
|
+
def optional_fields
|
11
|
+
%w[file_size file_path]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The force_reply resource which represents a Telegram bot API force_reply
|
4
|
+
class ForceReply < ChatbotHelper::Telegram::BaseResource
|
5
|
+
class << self
|
6
|
+
def required_fields
|
7
|
+
%w[force_reply]
|
8
|
+
end
|
9
|
+
|
10
|
+
def optional_fields
|
11
|
+
%w[selective]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The game resource which represents a Telegram bot API game
|
4
|
+
class Game < ChatbotHelper::Telegram::BaseResource
|
5
|
+
class << self
|
6
|
+
def required_fields
|
7
|
+
%w[title description]
|
8
|
+
end
|
9
|
+
|
10
|
+
def optional_fields
|
11
|
+
%w[text]
|
12
|
+
end
|
13
|
+
|
14
|
+
def optional_objects
|
15
|
+
[
|
16
|
+
{ name: 'animation', type: ChatbotHelper::Telegram::Animation }
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
def required_arrays
|
21
|
+
[
|
22
|
+
{ name: 'photo', type: ChatbotHelper::Telegram::PhotoSize }
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
def optional_arrays
|
27
|
+
[
|
28
|
+
{ name: 'text_entities',
|
29
|
+
type: ChatbotHelper::Telegram::MessageEntity }
|
30
|
+
]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The inline_keyboard_button resource which represents a Telegram bot API
|
4
|
+
# inline_keyboard_button
|
5
|
+
class InlineKeyboardButton < ChatbotHelper::Telegram::BaseResource
|
6
|
+
class << self
|
7
|
+
def required_fields
|
8
|
+
%w[text]
|
9
|
+
end
|
10
|
+
|
11
|
+
def optional_fields
|
12
|
+
%w[url callback_data switch_inline_query
|
13
|
+
switch_inline_query_current_chat]
|
14
|
+
end
|
15
|
+
|
16
|
+
def optional_objects
|
17
|
+
[
|
18
|
+
{ name: 'callback_game',
|
19
|
+
type: ChatbotHelper::Telegram::CallbackGame }
|
20
|
+
]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# A inline_keyboard_button collection which represents an array of
|
26
|
+
# inline_keyboard_button resources
|
27
|
+
class InlineKeyboardButtonCollection <
|
28
|
+
ChatbotHelper::Telegram::CollectionResource
|
29
|
+
class << self
|
30
|
+
def collection_type
|
31
|
+
ChatbotHelper::Telegram::InlineKeyboardButton
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The inline_keyboard_markup resource which represents a Telegram bot API
|
4
|
+
# inline_keyboard_markup
|
5
|
+
class InlineKeyboardMarkup < ChatbotHelper::Telegram::BaseResource
|
6
|
+
class << self
|
7
|
+
def required_arrays
|
8
|
+
[
|
9
|
+
{ name: 'inline_keyboard',
|
10
|
+
type: ChatbotHelper::Telegram::InlineKeyboardButtonCollection }
|
11
|
+
]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The inline_query resource which represents a Telegram bot API inline_query
|
4
|
+
class InlineQuery < ChatbotHelper::Telegram::BaseResource
|
5
|
+
class << self
|
6
|
+
def required_fields
|
7
|
+
%w[id query offset]
|
8
|
+
end
|
9
|
+
|
10
|
+
def required_objects
|
11
|
+
[
|
12
|
+
{ name: 'from', type: ChatbotHelper::Telegram::User }
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
def optional_objects
|
17
|
+
[
|
18
|
+
{ name: 'location', type: ChatbotHelper::Telegram::Location },
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The keyboard_button resource which represents a Telegram bot API
|
4
|
+
# keyboard_button
|
5
|
+
class KeyboardButton < ChatbotHelper::Telegram::BaseResource
|
6
|
+
class << self
|
7
|
+
def required_fields
|
8
|
+
%w[text]
|
9
|
+
end
|
10
|
+
|
11
|
+
def optional_fields
|
12
|
+
%w[request_contact request_location]
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid_resource?(resource)
|
16
|
+
return false if resource.nil?
|
17
|
+
|
18
|
+
# A KeyboardButton can be a simple String.
|
19
|
+
# So if it is string like, return true because it
|
20
|
+
# is valid.
|
21
|
+
return true if resource.respond_to?(:to_str)
|
22
|
+
|
23
|
+
# TODO: This is duplicate code. Maybe this can be avoided...
|
24
|
+
|
25
|
+
# Test resource as always
|
26
|
+
required_fields.each do |f|
|
27
|
+
return false if resource[f].nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
required_objects.each do |o|
|
31
|
+
return false unless o[:type].valid_resource?(resource[o[:name]])
|
32
|
+
end
|
33
|
+
|
34
|
+
required_arrays.each do |a|
|
35
|
+
arr = resource[a[:name]]
|
36
|
+
return false unless arr.respond_to?('each')
|
37
|
+
arr.each do |el|
|
38
|
+
return false unless a[:type].valid_resource?(el)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# All tests passed. Return true...
|
43
|
+
true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def implement_field_accessors
|
48
|
+
if @hash.respond_to?(:to_str)
|
49
|
+
define_singleton_method('text') do
|
50
|
+
# TODO: Should we return @hash.to_str so it is always a `String`?
|
51
|
+
return @hash
|
52
|
+
end
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# A keyboard_button collection which represents an array of keyboard_button
|
60
|
+
# resources
|
61
|
+
class KeyboardButtonCollection < ChatbotHelper::Telegram::CollectionResource
|
62
|
+
class << self
|
63
|
+
def collection_type
|
64
|
+
ChatbotHelper::Telegram::KeyboardButton
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The location resource which represents a Telegram bot API location
|
4
|
+
class Location < ChatbotHelper::Telegram::BaseResource
|
5
|
+
class << self
|
6
|
+
def required_fields
|
7
|
+
%w[longitude latitude]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The message resource which represents a Telegram bot API message
|
4
|
+
class Message < ChatbotHelper::Telegram::BaseResource
|
5
|
+
class << self
|
6
|
+
def required_fields
|
7
|
+
%w[message_id date]
|
8
|
+
end
|
9
|
+
|
10
|
+
def optional_fields
|
11
|
+
%w[forward_from_message_id forward_date edit_date text caption
|
12
|
+
new_chat_title delete_chat_photo group_chat_created
|
13
|
+
supergroup_chat_created channel_chat_created migrate_to_chat_id
|
14
|
+
migrate_from_chat_id]
|
15
|
+
end
|
16
|
+
|
17
|
+
def required_objects
|
18
|
+
[
|
19
|
+
{ name: 'chat', type: ChatbotHelper::Telegram::Chat }
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def optional_objects
|
24
|
+
[
|
25
|
+
{ name: 'from', type: ChatbotHelper::Telegram::User },
|
26
|
+
{ name: 'forward_from', type: ChatbotHelper::Telegram::User },
|
27
|
+
{ name: 'forward_from_chat', type: ChatbotHelper::Telegram::Chat },
|
28
|
+
{ name: 'reply_to_message',
|
29
|
+
type: ChatbotHelper::Telegram::Message },
|
30
|
+
{ name: 'audio', type: ChatbotHelper::Telegram::Audio },
|
31
|
+
{ name: 'document', type: ChatbotHelper::Telegram::Document },
|
32
|
+
{ name: 'game', type: ChatbotHelper::Telegram::Game },
|
33
|
+
{ name: 'sticker', type: ChatbotHelper::Telegram::Sticker },
|
34
|
+
{ name: 'video', type: ChatbotHelper::Telegram::Video },
|
35
|
+
{ name: 'voice', type: ChatbotHelper::Telegram::Voice },
|
36
|
+
{ name: 'contact', type: ChatbotHelper::Telegram::Contact },
|
37
|
+
{ name: 'location', type: ChatbotHelper::Telegram::Location },
|
38
|
+
{ name: 'venue', type: ChatbotHelper::Telegram::Venue },
|
39
|
+
{ name: 'new_chat_member', type: ChatbotHelper::Telegram::User },
|
40
|
+
{ name: 'left_chat_member', type: ChatbotHelper::Telegram::User },
|
41
|
+
{ name: 'pinned_message', type: ChatbotHelper::Telegram::Message }
|
42
|
+
]
|
43
|
+
end
|
44
|
+
|
45
|
+
def optional_arrays
|
46
|
+
[
|
47
|
+
{ name: 'entities', type: ChatbotHelper::Telegram::MessageEntity },
|
48
|
+
{ name: 'photo', type: ChatbotHelper::Telegram::PhotoSize },
|
49
|
+
{ name: 'new_chat_photo', type: ChatbotHelper::Telegram::PhotoSize }
|
50
|
+
]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The message_entity resource which represents a Telegram bot API
|
4
|
+
# message_entity
|
5
|
+
class MessageEntity < ChatbotHelper::Telegram::BaseResource
|
6
|
+
class << self
|
7
|
+
def required_fields
|
8
|
+
%w[type offset length]
|
9
|
+
end
|
10
|
+
|
11
|
+
def optional_fields
|
12
|
+
%w[url]
|
13
|
+
end
|
14
|
+
|
15
|
+
def optional_objects
|
16
|
+
[
|
17
|
+
{ name: 'user', type: ChatbotHelper::Telegram::User }
|
18
|
+
]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The photo_size resource which represents a Telegram bot API photo_size
|
4
|
+
class PhotoSize < ChatbotHelper::Telegram::BaseResource
|
5
|
+
class << self
|
6
|
+
def required_fields
|
7
|
+
%w[file_id width height]
|
8
|
+
end
|
9
|
+
|
10
|
+
def optional_fields
|
11
|
+
%w[file_size]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# A photo_size collection which represents an array of photo_size resources
|
17
|
+
class PhotoSizeCollection < ChatbotHelper::Telegram::CollectionResource
|
18
|
+
class << self
|
19
|
+
def collection_type
|
20
|
+
ChatbotHelper::Telegram::PhotoSize
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The reply_keyboard_markup resource which represents a Telegram bot API
|
4
|
+
# reply_keyboard_markup
|
5
|
+
class ReplyKeyboardMarkup < ChatbotHelper::Telegram::BaseResource
|
6
|
+
class << self
|
7
|
+
def optional_fields
|
8
|
+
%w[resize_keyboard one_time_keyboard selective]
|
9
|
+
end
|
10
|
+
|
11
|
+
def required_arrays
|
12
|
+
[
|
13
|
+
{ name: 'keyboard',
|
14
|
+
type: ChatbotHelper::Telegram::KeyboardButtonCollection }
|
15
|
+
]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The reply_keyboard_remove resource which represents a Telegram bot API
|
4
|
+
# reply_keyboard_remove
|
5
|
+
class ReplyKeyboardRemove < ChatbotHelper::Telegram::BaseResource
|
6
|
+
class << self
|
7
|
+
def required_fields
|
8
|
+
%w[remove_keyboard]
|
9
|
+
end
|
10
|
+
|
11
|
+
def optional_fields
|
12
|
+
%w[selective]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The response_parameters resource which represents a Telegram bot API
|
4
|
+
# response_parameters
|
5
|
+
class ResponseParameters < ChatbotHelper::Telegram::BaseResource
|
6
|
+
class << self
|
7
|
+
def optional_fields
|
8
|
+
%w[migrate_to_chat_id retry_after]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ChatbotHelper
|
2
|
+
module Telegram
|
3
|
+
# The sticker resource which represents a Telegram bot API sticker
|
4
|
+
class Sticker < ChatbotHelper::Telegram::BaseResource
|
5
|
+
class << self
|
6
|
+
def required_fields
|
7
|
+
%w[file_id width height]
|
8
|
+
end
|
9
|
+
|
10
|
+
def optional_fields
|
11
|
+
%w[emoji file_size]
|
12
|
+
end
|
13
|
+
|
14
|
+
def optional_objects
|
15
|
+
[
|
16
|
+
{ name: 'thumb', type: ChatbotHelper::Telegram::PhotoSize }
|
17
|
+
]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|