telegram-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +97 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/api/inline_keyboard_markup.rb +17 -0
- data/examples/api/send_message.rb +5 -0
- data/examples/client/handler.rb +19 -0
- data/lib/telegram/bot.rb +29 -0
- data/lib/telegram/bot/api.rb +261 -0
- data/lib/telegram/bot/client.rb +54 -0
- data/lib/telegram/bot/client_accessors.rb +5 -0
- data/lib/telegram/bot/configuration.rb +11 -0
- data/lib/telegram/bot/exceptions.rb +13 -0
- data/lib/telegram/bot/types.rb +47 -0
- data/lib/telegram/bot/types/animation.rb +17 -0
- data/lib/telegram/bot/types/audio.rb +14 -0
- data/lib/telegram/bot/types/callback_game.rb +4 -0
- data/lib/telegram/bot/types/callback_query.rb +23 -0
- data/lib/telegram/bot/types/chat.rb +25 -0
- data/lib/telegram/bot/types/chat_member.rb +28 -0
- data/lib/telegram/bot/types/chat_photo.rb +10 -0
- data/lib/telegram/bot/types/chosen_inline_result.rb +21 -0
- data/lib/telegram/bot/types/contact.rb +12 -0
- data/lib/telegram/bot/types/document.rb +17 -0
- data/lib/telegram/bot/types/file.rb +15 -0
- data/lib/telegram/bot/types/force_reply.rb +9 -0
- data/lib/telegram/bot/types/game.rb +26 -0
- data/lib/telegram/bot/types/inline_keyboard_button.rb +19 -0
- data/lib/telegram/bot/types/inline_keyboard_markup.rb +20 -0
- data/lib/telegram/bot/types/inline_query.rb +21 -0
- data/lib/telegram/bot/types/invoice.rb +13 -0
- data/lib/telegram/bot/types/keyboard_button.rb +11 -0
- data/lib/telegram/bot/types/location.rb +10 -0
- data/lib/telegram/bot/types/mask_position.rb +12 -0
- data/lib/telegram/bot/types/message.rb +145 -0
- data/lib/telegram/bot/types/message_entity.rb +17 -0
- data/lib/telegram/bot/types/order_info.rb +16 -0
- data/lib/telegram/bot/types/photo_size.rb +12 -0
- data/lib/telegram/bot/types/pre_checkout_query.rb +23 -0
- data/lib/telegram/bot/types/reply_keyboard_markup.rb +22 -0
- data/lib/telegram/bot/types/reply_keyboard_remove.rb +9 -0
- data/lib/telegram/bot/types/shipping_address.rb +14 -0
- data/lib/telegram/bot/types/shipping_query.rb +20 -0
- data/lib/telegram/bot/types/sticker.rb +24 -0
- data/lib/telegram/bot/types/sticker_set.rb +16 -0
- data/lib/telegram/bot/types/successful_payment.rb +19 -0
- data/lib/telegram/bot/types/update.rb +54 -0
- data/lib/telegram/bot/types/user.rb +14 -0
- data/lib/telegram/bot/types/user_profile_photos.rb +14 -0
- data/lib/telegram/bot/types/venue.rb +16 -0
- data/lib/telegram/bot/types/video.rb +19 -0
- data/lib/telegram/bot/types/video_note.rb +17 -0
- data/lib/telegram/bot/types/voice.rb +12 -0
- data/lib/telegram/bot/types/webhook_info.rb +15 -0
- data/lib/telegram/version.rb +3 -0
- data/telegram-ruby.gemspec +29 -0
- metadata +176 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class Invoice
|
3
|
+
attr_accessor :title,
|
4
|
+
:description,
|
5
|
+
:start_parameter,
|
6
|
+
:currency,
|
7
|
+
:total_amount
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class Message
|
3
|
+
attr_accessor :message_id,
|
4
|
+
:from,
|
5
|
+
:date,
|
6
|
+
:chat,
|
7
|
+
:forward_from,
|
8
|
+
:forward_from_chat,
|
9
|
+
:forward_from_message_id,
|
10
|
+
:forward_signature,
|
11
|
+
:forward_date,
|
12
|
+
:reply_to_message,
|
13
|
+
:edit_date,
|
14
|
+
:media_group_id,
|
15
|
+
:author_signature,
|
16
|
+
:text,
|
17
|
+
:entities,
|
18
|
+
:caption_entities,
|
19
|
+
:audio,
|
20
|
+
:document,
|
21
|
+
:game,
|
22
|
+
:photo,
|
23
|
+
:sticker,
|
24
|
+
:video,
|
25
|
+
:voice,
|
26
|
+
:video_note,
|
27
|
+
:caption,
|
28
|
+
:contact,
|
29
|
+
:location,
|
30
|
+
:venue,
|
31
|
+
:new_chat_members,
|
32
|
+
:left_chat_member,
|
33
|
+
:new_chat_title,
|
34
|
+
:new_chat_photo,
|
35
|
+
:delete_chat_photo,
|
36
|
+
:group_chat_created,
|
37
|
+
:supergroup_chat_created,
|
38
|
+
:channel_chat_created,
|
39
|
+
:migrate_to_chat_id,
|
40
|
+
:migrate_from_chat_id,
|
41
|
+
:pinned_message,
|
42
|
+
:invoice,
|
43
|
+
:successful_payment
|
44
|
+
|
45
|
+
def initialize(attributes)
|
46
|
+
attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
47
|
+
end
|
48
|
+
|
49
|
+
def from=(attributes)
|
50
|
+
@from = User.new(attributes)
|
51
|
+
end
|
52
|
+
|
53
|
+
def chat=(attributes)
|
54
|
+
@chat = Chat.new(attributes)
|
55
|
+
end
|
56
|
+
|
57
|
+
def forward_from=(attributes)
|
58
|
+
@forward_from = User.new(attributes)
|
59
|
+
end
|
60
|
+
|
61
|
+
def forward_from_chat=(attributes)
|
62
|
+
@forward_from_chat = Chat.new(attributes)
|
63
|
+
end
|
64
|
+
|
65
|
+
def reply_to_message=(attributes)
|
66
|
+
@reply_to_message = Message.new(attributes)
|
67
|
+
end
|
68
|
+
|
69
|
+
def entities=(attributes)
|
70
|
+
@entities = attributes.map {|attr| MessageEntity.new(attr) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def caption_entities=(attributes)
|
74
|
+
@caption_entities = attributes.map {|attr| MessageEntity.new(attr) }
|
75
|
+
end
|
76
|
+
|
77
|
+
def audio=(attributes)
|
78
|
+
@audio = Audio.new(attributes)
|
79
|
+
end
|
80
|
+
|
81
|
+
def document=(attributes)
|
82
|
+
@document = Audio.new(attributes)
|
83
|
+
end
|
84
|
+
|
85
|
+
def game=(attributes)
|
86
|
+
@game = Game.new(attributes)
|
87
|
+
end
|
88
|
+
|
89
|
+
def photo=(attributes)
|
90
|
+
@photo = PhotoSize.new(attributes)
|
91
|
+
end
|
92
|
+
|
93
|
+
def sticker=(attributes)
|
94
|
+
@sticker = Sticker.new(attributes)
|
95
|
+
end
|
96
|
+
|
97
|
+
def video=(attributes)
|
98
|
+
@video = Video.new(attributes)
|
99
|
+
end
|
100
|
+
|
101
|
+
def voice=(attributes)
|
102
|
+
@voice = Voice.new(attributes)
|
103
|
+
end
|
104
|
+
|
105
|
+
def video_note=(attributes)
|
106
|
+
@video_note = VideoNote.new(attributes)
|
107
|
+
end
|
108
|
+
|
109
|
+
def contact=(attributes)
|
110
|
+
@contact = Contact.new(attributes)
|
111
|
+
end
|
112
|
+
|
113
|
+
def location=(attributes)
|
114
|
+
@location = Location.new(attributes)
|
115
|
+
end
|
116
|
+
|
117
|
+
def venue=(attributes)
|
118
|
+
@venue = Venue.new(attributes)
|
119
|
+
end
|
120
|
+
|
121
|
+
def new_chat_members=(attributes)
|
122
|
+
@new_chat_members = attributes.map {|attr| User.new(attr) }
|
123
|
+
end
|
124
|
+
|
125
|
+
def left_chat_member=(attributes)
|
126
|
+
@left_chat_member = User.new(attributes)
|
127
|
+
end
|
128
|
+
|
129
|
+
def new_chat_photo=(attributes)
|
130
|
+
@new_chat_photo = PhotoSize.new(attributes)
|
131
|
+
end
|
132
|
+
|
133
|
+
def pinned_message=(attributes)
|
134
|
+
@pinned_message = Message.new(attributes)
|
135
|
+
end
|
136
|
+
|
137
|
+
def invoice=(attributes)
|
138
|
+
@invoice = Invoice.new(attributes)
|
139
|
+
end
|
140
|
+
|
141
|
+
def successful_payment=(attributes)
|
142
|
+
@successful_payment = SuccessfulPayment.new(attributes)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class MessageEntity
|
3
|
+
attr_accessor :type,
|
4
|
+
:offset,
|
5
|
+
:length,
|
6
|
+
:url,
|
7
|
+
:user
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
11
|
+
end
|
12
|
+
|
13
|
+
def user=(attributes)
|
14
|
+
@user = User.new(attributes)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class OrderInfo
|
3
|
+
attr_accessor :name,
|
4
|
+
:phone_number,
|
5
|
+
:email,
|
6
|
+
:shipping_address
|
7
|
+
|
8
|
+
def initialize(attributes)
|
9
|
+
attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
10
|
+
end
|
11
|
+
|
12
|
+
def shipping_address=(attributes)
|
13
|
+
@shipping_address = ShippingAddress.new(attributes)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class PreCheckoutQuery
|
3
|
+
attr_accessor :id,
|
4
|
+
:from,
|
5
|
+
:currency,
|
6
|
+
:total_amount,
|
7
|
+
:invoice_payload,
|
8
|
+
:shipping_option_id,
|
9
|
+
:order_info
|
10
|
+
|
11
|
+
def initialize(attributes)
|
12
|
+
attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
13
|
+
end
|
14
|
+
|
15
|
+
def from=(attributes)
|
16
|
+
@from = User.new(attr)
|
17
|
+
end
|
18
|
+
|
19
|
+
def order_info=(attributes)
|
20
|
+
@order_info = OrderInfo.new(attr)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class ReplyKeyboardMarkup
|
3
|
+
attr_accessor :keyboard, :resize_keyboard, :one_time_keyboard, :selective
|
4
|
+
|
5
|
+
def initialize(attributes, options = {})
|
6
|
+
options.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
7
|
+
|
8
|
+
@keyboard = attributes.map do |v|
|
9
|
+
v.map do |b|
|
10
|
+
if b.is_a?(KeyboardButton)
|
11
|
+
b
|
12
|
+
elsif b.is_a?(Hash)
|
13
|
+
InlineKeyboardButton.new(b)
|
14
|
+
else
|
15
|
+
raise Telegram::Bot::Exceptions::KeyboardMarkupError
|
16
|
+
.new('Attributes must be Array of Array of Telegram::Bot::Types::KeyboardButton or Hash')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class ShippingAddress
|
3
|
+
attr_accessor :country_code,
|
4
|
+
:state,
|
5
|
+
:city,
|
6
|
+
:street_line1,
|
7
|
+
:street_line2,
|
8
|
+
:post_code
|
9
|
+
|
10
|
+
def initialize(attributes)
|
11
|
+
attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class ShippingQuery
|
3
|
+
attr_accessor :id,
|
4
|
+
:from,
|
5
|
+
:invoice_payload,
|
6
|
+
:shipping_address
|
7
|
+
|
8
|
+
def initialize(attributes)
|
9
|
+
attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
10
|
+
end
|
11
|
+
|
12
|
+
def from=(attributes)
|
13
|
+
@from = User.new(attr)
|
14
|
+
end
|
15
|
+
|
16
|
+
def shipping_address=(attributes)
|
17
|
+
@shipping_address = ShippingAddress.new(attributes)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class Sticker
|
3
|
+
attr_accessor :file_id,
|
4
|
+
:width,
|
5
|
+
:height,
|
6
|
+
:thumb,
|
7
|
+
:emoji,
|
8
|
+
:set_name,
|
9
|
+
:mask_position,
|
10
|
+
:file_size
|
11
|
+
|
12
|
+
def initialize(attributes)
|
13
|
+
attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
14
|
+
end
|
15
|
+
|
16
|
+
def thumb=(attributes)
|
17
|
+
@thumb = PhotoSize.new(attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def mask_position=(attributes)
|
21
|
+
@mask_position = MaskPosition.new(attributes)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class StickerSet
|
3
|
+
attr_accessor :name,
|
4
|
+
:title,
|
5
|
+
:contains_masks,
|
6
|
+
:stickers
|
7
|
+
|
8
|
+
def initialize(attributes)
|
9
|
+
attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
10
|
+
end
|
11
|
+
|
12
|
+
def stickers=(attributes)
|
13
|
+
@stickers = attributes.map {|attr| Sticker.new(attr) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class SuccessfulPayment
|
3
|
+
attr_accessor :currency,
|
4
|
+
:total_amount,
|
5
|
+
:invoice_payload,
|
6
|
+
:shipping_option_id,
|
7
|
+
:order_info,
|
8
|
+
:telegram_payment_charge_id,
|
9
|
+
:provider_payment_charge_id
|
10
|
+
|
11
|
+
def initialize(attributes)
|
12
|
+
attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
13
|
+
end
|
14
|
+
|
15
|
+
def order_info=(attributes)
|
16
|
+
@order_info = OrderInfo.new(attributes)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Telegram::Bot::Types
|
2
|
+
class Update
|
3
|
+
attr_accessor :update_id,
|
4
|
+
:message,
|
5
|
+
:edited_message,
|
6
|
+
:channel_post,
|
7
|
+
:edited_channel_post,
|
8
|
+
:inline_query,
|
9
|
+
:chosen_inline_result,
|
10
|
+
:callback_query,
|
11
|
+
:shipping_query,
|
12
|
+
:pre_checkout_query
|
13
|
+
|
14
|
+
def initialize(attributes)
|
15
|
+
attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k }
|
16
|
+
end
|
17
|
+
|
18
|
+
def message=(attributes)
|
19
|
+
@message = Message.new(attributes)
|
20
|
+
end
|
21
|
+
|
22
|
+
def edited_message=(attributes)
|
23
|
+
@edited_message = Message.new(attributes)
|
24
|
+
end
|
25
|
+
|
26
|
+
def channel_post=(attributes)
|
27
|
+
@channel_post = Message.new(attributes)
|
28
|
+
end
|
29
|
+
|
30
|
+
def edited_channel_post=(attributes)
|
31
|
+
@edited_channel_post = Message.new(attributes)
|
32
|
+
end
|
33
|
+
|
34
|
+
def inline_query=(attributes)
|
35
|
+
@inline_query = InlineQuery.new(attributes)
|
36
|
+
end
|
37
|
+
|
38
|
+
def chosen_inline_result=(attributes)
|
39
|
+
@chosen_inline_result = ChosenInlineResult.new(attributes)
|
40
|
+
end
|
41
|
+
|
42
|
+
def callback_query=(attributes)
|
43
|
+
@callback_query = CallbackQuery.new(attributes)
|
44
|
+
end
|
45
|
+
|
46
|
+
def shipping_query=(attributes)
|
47
|
+
@shipping_query = ShippingQuery.new(attributes)
|
48
|
+
end
|
49
|
+
|
50
|
+
def pre_checkout_query=(attributes)
|
51
|
+
@pre_checkout_query = PreCheckoutQuery.new(attributes)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|