telbe 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcf64c6457b7403573aabe87dd8c46594cf0ca2db28f3103040cf5234919ef84
4
- data.tar.gz: d62045d388c68f4676f69e0337f065871912413634c8501ffc6e17afad5b5fdf
3
+ metadata.gz: d7c896576ba70db333e3545589afc64b42fb3ebe437e031d32c6b9cdd4f76c4d
4
+ data.tar.gz: a3ae4f6a883708888c6be49e7c00f791cca50ebe858f630e02ab0b8662913377
5
5
  SHA512:
6
- metadata.gz: 40866b0b706a7321078df7d7dd586d464953239515dc92b6d45bd92bf02b424525f00058b6e3bb33a3cf90a6b0ad4b0d92161c81eadfba1395290bee68c83ac8
7
- data.tar.gz: 9211847e1f3a3d50370818a2bdccd7b6231f19b3d88f9e4b7e33b5d359ffd44a366678aedaf05a8f1d5dff57ec34c5aa494a3ae92fb0374878ae2b14c74ae12e
6
+ metadata.gz: b8e1c434683fe70d45f54e9700660ed96794b3b40e473dd75425a23303a7efe6f4b2831c451a806f60e8857b3b79b8a53f94b4f01f549a0031ad437a0f3e4782
7
+ data.tar.gz: bc851b6a16fd2ea0a0c970a065701653801cac0a197715c63341590ccd4a3e56a0f4009f3f758a697436a423c7187446323aed42d9606422c1b78091db5eecb2
data/.gitignore CHANGED
@@ -4,3 +4,5 @@
4
4
  /tmp/
5
5
  /vendor/
6
6
  *.gem
7
+ /.ruby-gemset
8
+ /.ruby-version
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --require rspec/collection_matchers
3
+ --format documentation
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in bot_engine.gemspec
3
+ # Specify your gem's dependencies in telbe.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -4,9 +4,9 @@ A complete ruby client that implements [Telegram's Bot API](https://core.telegra
4
4
 
5
5
  Ruby is such a beautiful and productive language.
6
6
 
7
- [Virtus](https://github.com/solnic/virtus) is heavilly used, mainly because it's easy to instantiate objects from hashes, even complex objects. Virtus is deprecated, at a future release we'll evaulate differente approaches to address the problem.
7
+ SimplifyApi is being used to automagicaly objectify JSON and JSONify objects, it also implements a "safe" environment to accomodate future API specifications without too much burden.
8
8
 
9
- Currently under heavy development.
9
+ Currently under heavy development (or maybe not!).
10
10
 
11
11
  Please [collaborate](https://github.com/rodgco/telbe/issues/new) with your questions, ideas or problems!
12
12
 
data/lib/telbe/base.rb CHANGED
@@ -3,7 +3,7 @@ module Telbe
3
3
  def self.inherited(base)
4
4
  base.send(:include, SimplifyApi)
5
5
  base.send(:attribute, :chat_id, Object, mandatory: true)
6
- base.send(:attribute, :disable_notification, values: [true, false])
6
+ base.send(:attribute, :disable_notification, values: [true, false], default: false)
7
7
  base.send(:attribute, :reply_to_message_id, Integer)
8
8
  base.send(:attribute, :reply_markup, Object)
9
9
  end
@@ -13,7 +13,7 @@ module Telbe
13
13
  def self.inherited(base)
14
14
  super(base)
15
15
  base.send(:attribute, :caption, String)
16
- base.send(:attribute, :parse_mode, String, values: ["Markdown", "HTML"])
16
+ base.send(:attribute, :parse_mode, String, values: %w[Markdown HTML], default: 'Markdown')
17
17
  end
18
18
  end
19
19
 
@@ -23,17 +23,17 @@ module Telbe
23
23
  base.send(:attribute, :type, String, mandatory: true)
24
24
  base.send(:attribute, :media, String, mandatory: true)
25
25
  base.send(:attribute, :caption, String)
26
- base.send(:attribute, :parse_mode, String, values: ["Markdown", "HTML"])
26
+ base.send(:attribute, :parse_mode, String, values: %w[Markdown HTML], default: 'Markdown')
27
27
  end
28
28
  end
29
-
29
+
30
30
  class InlineQueryResult
31
31
  def self.inherited(base)
32
32
  base.send(:include, SimplifyApi)
33
33
  base.send(:attribute, :type, String, mandatory: true)
34
34
  base.send(:attribute, :id, String, mandatory: true)
35
35
  base.send(:attribute, :caption, String)
36
- base.send(:attribute, :parse_mode, String, values: ["Markdown", "HTML"])
36
+ base.send(:attribute, :parse_mode, String, values: %w[Markdown HTML], default: 'Markdown')
37
37
  base.send(:attribute, :reply_markup, InlineKeyboardMarkup)
38
38
  base.send(:attribute, :input_message_content, Object)
39
39
  end
data/lib/telbe/bot.rb CHANGED
@@ -1,231 +1,233 @@
1
- module Telbe
2
- class Bot
3
- ENDPOINT = 'https://api.telegram.org/'
4
-
5
- def initialize(token:, proxy: nil)
6
- @token = token
7
- @proxy = proxy
8
- @connection = Excon.new(ENDPOINT, persistent: true, proxy: @proxy)
9
- end
10
-
11
- def request(action, query = {})
12
- path = "/bot#{@token}/#{action}"
13
- response = @connection.post(path: path, query: query.to_h)
14
- if response.status == 200
15
- body = response.body
16
- data = JSON.parse(body)
17
- data["result"]
18
- else
19
- raise ResponseError, response.body
20
- end
21
- end
22
-
23
- def send_message(message_descriptor)
24
- Message.new(request(:sendMessage, message_descriptor))
25
- end
26
-
27
- def get_updates(get_updates_descriptor)
28
- request(:getUpdates, get_updates_descriptor).collect do |update|
29
- Update.new(update)
30
- end
31
- end
32
- end
33
-
34
- # type String Type of the entity. Can be mention (@username), hashtag, cashtag, bot_command, url, email, phone_number, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames)
35
- # offset Integer Offset in UTF-16 code units to the start of the entity
36
- # length Integer Length of the entity in UTF-16 code units
37
- # url String Optional. For “text_link” only, url that will be opened after user taps on the text
38
- # user User Optional. For “text_mention” only, the mentioned user
39
- class MessageEntity
40
- include SimplifyApi
41
- attribute :type, String, mandatory: true
42
- attribute :offset, Integer, mandatory: true
43
- attribute :length, Integer, mandatory: true
44
- attribute :url, String
45
- attribute :user, User
46
- end
47
-
48
- # force_reply True Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply'
49
- # selective Boolean Optional. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
50
- class ForceReply
51
- include SimplifyApi
52
- attribute :force_reply, values: [true], mandatory: true
53
- attribute :selective, values: [true, false]
54
- end
55
-
56
- # chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername)
57
- # text String Yes Text of the message to be sent
58
- # parse_mode String Optional Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
59
- # disable_web_page_preview Boolean Optional Disables link previews for links in this message
60
- # disable_notification Boolean Optional Sends the message silently. Users will receive a notification with no sound.
61
- # reply_to_message_id Integer Optional If the message is a reply, ID of the original message
62
- # reply_markup InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply Optional Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
63
- class MessageDescriptor
64
- include SimplifyApi
65
- attribute :chat_id, Integer, mandatory: true
66
- attribute :text, String, mandatory: true
67
- attribute :parse_mode, String, values: ["Markdown", "HTML"]
68
- attribute :disable_web_page_preview, values: [true, false]
69
- attribute :reply_to_message_id, Integer
70
- attribute :reply_markup, Object
71
- end
72
-
73
- # message_id Integer Unique message identifier inside this chat
74
- # from User Optional. Sender, empty for messages sent to channels
75
- # date Integer Date the message was sent in Unix time
76
- # chat Chat Conversation the message belongs to
77
- # forward_from User Optional. For forwarded messages, sender of the original message
78
- # forward_from_chat Chat Optional. For messages forwarded from channels, information about the original channel
79
- # forward_from_message_id Integer Optional. For messages forwarded from channels, identifier of the original message in the channel
80
- # forward_signature String Optional. For messages forwarded from channels, signature of the post author if present
81
- # forward_sender_name String Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages
82
- # forward_date Integer Optional. For forwarded messages, date the original message was sent in Unix time
83
- # reply_to_message Message Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
84
- # edit_date Integer Optional. Date the message was last edited in Unix time
85
- # media_group_id String Optional. The unique identifier of a media message group this message belongs to
86
- # author_signature String Optional. Signature of the post author for messages in channels
87
- # text String Optional. For text messages, the actual UTF-8 text of the message, 0-4096 characters.
88
- # entities Array of MessageEntity Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
89
- # caption_entities Array of MessageEntity Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption
90
- # audio Audio Optional. Message is an audio file, information about the file
91
- # document Document Optional. Message is a general file, information about the file
92
- # animation Animation Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set
93
- # game Game Optional. Message is a game, information about the game. More about games »
94
- # photo Array of PhotoSize Optional. Message is a photo, available sizes of the photo
95
- # sticker Sticker Optional. Message is a sticker, information about the sticker
96
- # video Video Optional. Message is a video, information about the video
97
- # voice Voice Optional. Message is a voice message, information about the file
98
- # video_note VideoNote Optional. Message is a video note, information about the video message
99
- # caption String Optional. Caption for the animation, audio, document, photo, video or voice, 0-1024 characters
100
- # contact Contact Optional. Message is a shared contact, information about the contact
101
- # location Location Optional. Message is a shared location, information about the location
102
- # venue Venue Optional. Message is a venue, information about the venue
103
- # poll Poll Optional. Message is a native poll, information about the poll
104
- # new_chat_members Array of User Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
105
- # left_chat_member User Optional. A member was removed from the group, information about them (this member may be the bot itself)
106
- # new_chat_title String Optional. A chat title was changed to this value
107
- # new_chat_photo Array of PhotoSize Optional. A chat photo was change to this value
108
- # delete_chat_photo True Optional. Service message: the chat photo was deleted
109
- # group_chat_created True Optional. Service message: the group has been created
110
- # supergroup_chat_created True Optional. Service message: the supergroup has been created. This field can‘t be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.
111
- # channel_chat_created True Optional. Service message: the channel has been created. This field can‘t be received in a message coming through updates, because bot can’t be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel.
112
- # migrate_to_chat_id Integer Optional. The group has been migrated to a supergroup with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
113
- # migrate_from_chat_id Integer Optional. The supergroup has been migrated from a group with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
114
- # pinned_message Message Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
115
- # invoice Invoice Optional. Message is an invoice for a payment, information about the invoice. More about payments »
116
- # successful_payment SuccessfulPayment Optional. Message is a service message about a successful payment, information about the payment. More about payments »
117
- # connected_website String Optional. The domain name of the website on which the user has logged in. More about Telegram Login »
118
- # passport_data PassportData Optional. Telegram Passport data
119
- class Message
120
- include SimplifyApi
121
- attribute :message_id, Integer, mandatory: true
122
- attribute :from, User
123
- attribute :date, Integer, mandatory: true
124
- attribute :chat, Chat, mandatory: true
125
- attribute :forward_from, User
126
- attribute :forward_from_chat, Chat
127
- attribute :forward_from_message_id, Integer
128
- attribute :forward_signature, String
129
- attribute :forward_sender_name, String
130
- attribute :forward_date, Integer
131
- attribute :reply_to_message, Message
132
- attribute :edit_date, Integer
133
- attribute :media_group_id, String
134
- attribute :author_signature, String
135
- attribute :text, String
136
- attribute :entities, [MessageEntity]
137
- attribute :caption_entities, [MessageEntity]
138
- attribute :audio, Audio
139
- attribute :document, Document
140
- attribute :animation, Animation
141
- # attribute :game, Game
142
- attribute :photo, [PhotoSize]
143
- attribute :sticker, Sticker
144
- attribute :video, Video
145
- attribute :voice, Voice
146
- attribute :video_note, VideoNote
147
- attribute :caption, String
148
- attribute :contact, Contact
149
- attribute :location, Location
150
- attribute :venue, Venue
151
- attribute :poll, Poll
152
- attribute :new_chat_members, [User]
153
- attribute :left_chat_member, User
154
- attribute :new_chat_title, String
155
- attribute :new_chat_photo, [PhotoSize]
156
- attribute :delete_chat_photo, values: [true]
157
- attribute :group_chat_created, values: [true]
158
- attribute :supergroup_chat_created, values: [true]
159
- attribute :channel_chat_created, values: [true]
160
- attribute :migrate_to_chat_id, Integer
161
- attribute :migrate_from_chat_id, Integer
162
- attribute :pinned_message, Message
163
- # attribute :invoice, Invoice
164
- # attribute :successful_payment, SuccessfulPayment
165
- attribute :connected_website, String
166
- # attribute :passport_data, PassportData
167
-
168
- def reply(&block)
169
- reply = MessageDescriptor.new(chat_id: chat.id)
170
- yield reply if block_given?
171
- reply
172
- end
173
-
174
- def get_command_for(bot)
175
- text && text.sub(Regexp.new("@#{bot.get_me.username}($|\s|\.|,)", Regexp::IGNORECASE), '').strip
176
- end
177
- end
178
-
179
- # chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername)
180
- # from_chat_id Integer or String Yes Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
181
- # disable_notification Boolean Optional Sends the message silently. Users will receive a notification with no sound.
182
- # message_id Integer Yes Message identifier in the chat specified in from_chat_id
183
- class ForwardMessageDescriptor
184
- include SimplifyApi
185
- attribute :chat_id, Object, mandatory: true
186
- attribute :from_chat_id, Object, mandatory: true
187
- attribute :disable_notification, values: [true, false]
188
- attribute :message_id, Integer, mandatory: true
189
- end
190
-
191
- # update_id Integer The update‘s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially.
192
- # message Message Optional. New incoming message of any kind — text, photo, sticker, etc.
193
- # edited_message Message Optional. New version of a message that is known to the bot and was edited
194
- # channel_post Message Optional. New incoming channel post of any kind — text, photo, sticker, etc.
195
- # edited_channel_post Message Optional. New version of a channel post that is known to the bot and was edited
196
- # inline_query InlineQuery Optional. New incoming inline query
197
- # chosen_inline_result ChosenInlineResult Optional. The result of an inline query that was chosen by a user and sent to their chat partner. Please see our documentation on the feedback collecting for details on how to enable these updates for your bot.
198
- # callback_query CallbackQuery Optional. New incoming callback query
199
- # shipping_query ShippingQuery Optional. New incoming shipping query. Only for invoices with flexible price
200
- # pre_checkout_query PreCheckoutQuery Optional. New incoming pre-checkout query. Contains full information about checkout
201
- # poll Poll Optional. New poll state. Bots receive only updates about polls, which are sent or stopped by the bot
202
- class Update
203
- include SimplifyApi
204
- attribute :update_id, Integer, mandatory: true
205
- attribute :message, Message
206
- attribute :edited_message, Message
207
- attribute :channel_post, Message
208
- attribute :inline_query, InlineQuery
209
- attribute :chosen_inline_result, ChosenInlineResult
210
- attribute :callback_query, CallbackQuery
211
- attribute :poll, Poll
212
- end
213
-
214
- # offset Integer Optional Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will forgotten.
215
- # limit Integer Optional Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100.
216
- # timeout Integer Optional Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.
217
- # allowed_updates Array of String Optional List the types of updates you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used.
218
- class GetUpdatesDescriptor
219
- include SimplifyApi
220
- attribute :offset, Integer
221
- attribute :limit, Integer
222
- attribute :timeout, Integer
223
- attribute :allowed_updates, [String]
224
- end
225
-
226
- class ResponseError < StandardError
227
- def initialize(msg = "Bot Response Error")
228
- super
229
- end
230
- end
231
- end
1
+ # frozen_string_literal: true
2
+
3
+ # The main module that agregates all classes
4
+ module Telbe
5
+
6
+ class Bot
7
+ ENDPOINT = 'https://api.telegram.org/'
8
+
9
+ def initialize(token:, proxy: nil)
10
+ @token = token
11
+ @proxy = proxy
12
+ @connection = Excon.new(ENDPOINT, persistent: true, proxy: @proxy)
13
+ end
14
+
15
+ def request(action, query = {})
16
+ path = "/bot#{@token}/#{action}"
17
+ response = @connection.post(path: path, query: query.to_h)
18
+ raise ResponseError, response.body unless response.status == 200
19
+
20
+ body = response.body
21
+ data = JSON.parse(body)
22
+ data['result']
23
+ end
24
+
25
+ def send_message(message_descriptor)
26
+ Message.new(request(:sendMessage, message_descriptor))
27
+ end
28
+
29
+ def get_updates(get_updates_descriptor)
30
+ request(:getUpdates, get_updates_descriptor).collect do |update|
31
+ Update.new(update)
32
+ end
33
+ end
34
+ end
35
+
36
+ # type String Type of the entity. Can be mention (@username), hashtag, cashtag, bot_command, url, email, phone_number, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames)
37
+ # offset Integer Offset in UTF-16 code units to the start of the entity
38
+ # length Integer Length of the entity in UTF-16 code units
39
+ # url String Optional. For “text_link” only, url that will be opened after user taps on the text
40
+ # user User Optional. For “text_mention” only, the mentioned user
41
+ class MessageEntity
42
+ include SimplifyApi
43
+ attribute :type, String, mandatory: true
44
+ attribute :offset, Integer, mandatory: true
45
+ attribute :length, Integer, mandatory: true
46
+ attribute :url, String
47
+ attribute :user, User
48
+ end
49
+
50
+ # force_reply True Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply'
51
+ # selective Boolean Optional. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
52
+ class ForceReply
53
+ include SimplifyApi
54
+ attribute :force_reply, values: [true], mandatory: true, default: true
55
+ attribute :selective, values: [true, false], default: true
56
+ end
57
+
58
+ # chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername)
59
+ # text String Yes Text of the message to be sent
60
+ # parse_mode String Optional Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
61
+ # disable_web_page_preview Boolean Optional Disables link previews for links in this message
62
+ # disable_notification Boolean Optional Sends the message silently. Users will receive a notification with no sound.
63
+ # reply_to_message_id Integer Optional If the message is a reply, ID of the original message
64
+ # reply_markup InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply Optional Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
65
+ class MessageDescriptor
66
+ include SimplifyApi
67
+ attribute :chat_id, Integer, mandatory: true
68
+ attribute :text, String, mandatory: true
69
+ attribute :parse_mode, String, values: %w[Markdown HTML], default: 'Markdown'
70
+ attribute :disable_web_page_preview, values: [true, false], default: false
71
+ attribute :reply_to_message_id, Integer
72
+ attribute :reply_markup, Object
73
+ end
74
+
75
+ # message_id Integer Unique message identifier inside this chat
76
+ # from User Optional. Sender, empty for messages sent to channels
77
+ # date Integer Date the message was sent in Unix time
78
+ # chat Chat Conversation the message belongs to
79
+ # forward_from User Optional. For forwarded messages, sender of the original message
80
+ # forward_from_chat Chat Optional. For messages forwarded from channels, information about the original channel
81
+ # forward_from_message_id Integer Optional. For messages forwarded from channels, identifier of the original message in the channel
82
+ # forward_signature String Optional. For messages forwarded from channels, signature of the post author if present
83
+ # forward_sender_name String Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages
84
+ # forward_date Integer Optional. For forwarded messages, date the original message was sent in Unix time
85
+ # reply_to_message Message Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
86
+ # edit_date Integer Optional. Date the message was last edited in Unix time
87
+ # media_group_id String Optional. The unique identifier of a media message group this message belongs to
88
+ # author_signature String Optional. Signature of the post author for messages in channels
89
+ # text String Optional. For text messages, the actual UTF-8 text of the message, 0-4096 characters.
90
+ # entities Array of MessageEntity Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
91
+ # caption_entities Array of MessageEntity Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption
92
+ # audio Audio Optional. Message is an audio file, information about the file
93
+ # document Document Optional. Message is a general file, information about the file
94
+ # animation Animation Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set
95
+ # game Game Optional. Message is a game, information about the game. More about games »
96
+ # photo Array of PhotoSize Optional. Message is a photo, available sizes of the photo
97
+ # sticker Sticker Optional. Message is a sticker, information about the sticker
98
+ # video Video Optional. Message is a video, information about the video
99
+ # voice Voice Optional. Message is a voice message, information about the file
100
+ # video_note VideoNote Optional. Message is a video note, information about the video message
101
+ # caption String Optional. Caption for the animation, audio, document, photo, video or voice, 0-1024 characters
102
+ # contact Contact Optional. Message is a shared contact, information about the contact
103
+ # location Location Optional. Message is a shared location, information about the location
104
+ # venue Venue Optional. Message is a venue, information about the venue
105
+ # poll Poll Optional. Message is a native poll, information about the poll
106
+ # new_chat_members Array of User Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
107
+ # left_chat_member User Optional. A member was removed from the group, information about them (this member may be the bot itself)
108
+ # new_chat_title String Optional. A chat title was changed to this value
109
+ # new_chat_photo Array of PhotoSize Optional. A chat photo was change to this value
110
+ # delete_chat_photo True Optional. Service message: the chat photo was deleted
111
+ # group_chat_created True Optional. Service message: the group has been created
112
+ # supergroup_chat_created True Optional. Service message: the supergroup has been created. This field can‘t be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.
113
+ # channel_chat_created True Optional. Service message: the channel has been created. This field can‘t be received in a message coming through updates, because bot can’t be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel.
114
+ # migrate_to_chat_id Integer Optional. The group has been migrated to a supergroup with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
115
+ # migrate_from_chat_id Integer Optional. The supergroup has been migrated from a group with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
116
+ # pinned_message Message Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
117
+ # invoice Invoice Optional. Message is an invoice for a payment, information about the invoice. More about payments »
118
+ # successful_payment SuccessfulPayment Optional. Message is a service message about a successful payment, information about the payment. More about payments »
119
+ # connected_website String Optional. The domain name of the website on which the user has logged in. More about Telegram Login »
120
+ # passport_data PassportData Optional. Telegram Passport data
121
+ class Message
122
+ include SimplifyApi
123
+ attribute :message_id, Integer, mandatory: true
124
+ attribute :from, User
125
+ attribute :date, Integer, mandatory: true
126
+ attribute :chat, Chat, mandatory: true
127
+ attribute :forward_from, User
128
+ attribute :forward_from_chat, Chat
129
+ attribute :forward_from_message_id, Integer
130
+ attribute :forward_signature, String
131
+ attribute :forward_sender_name, String
132
+ attribute :forward_date, Integer
133
+ attribute :reply_to_message, Message
134
+ attribute :edit_date, Integer
135
+ attribute :media_group_id, String
136
+ attribute :author_signature, String
137
+ attribute :text, String
138
+ attribute :entities, [MessageEntity]
139
+ attribute :caption_entities, [MessageEntity]
140
+ attribute :audio, Audio
141
+ attribute :document, Document
142
+ attribute :animation, Animation
143
+ # attribute :game, Game
144
+ attribute :photo, [PhotoSize]
145
+ attribute :sticker, Sticker
146
+ attribute :video, Video
147
+ attribute :voice, Voice
148
+ attribute :video_note, VideoNote
149
+ attribute :caption, String
150
+ attribute :contact, Contact
151
+ attribute :location, Location
152
+ attribute :venue, Venue
153
+ attribute :poll, Poll
154
+ attribute :new_chat_members, [User]
155
+ attribute :left_chat_member, User
156
+ attribute :new_chat_title, String
157
+ attribute :new_chat_photo, [PhotoSize]
158
+ # attribute :delete_chat_photo, values: [true], default: true
159
+ # attribute :group_chat_created, values: [true], default: true
160
+ # attribute :supergroup_chat_created, values: [true], default: true
161
+ # attribute :channel_chat_created, values: [true], default: true
162
+ attribute :migrate_to_chat_id, Integer
163
+ attribute :migrate_from_chat_id, Integer
164
+ attribute :pinned_message, Message
165
+ # attribute :invoice, Invoice
166
+ # attribute :successful_payment, SuccessfulPayment
167
+ attribute :connected_website, String
168
+ # attribute :passport_data, PassportData
169
+
170
+ def reply(&block)
171
+ reply = MessageDescriptor.new(chat_id: chat.id)
172
+ yield reply if block_given?
173
+ reply
174
+ end
175
+
176
+ def get_command_for(bot)
177
+ text && text.sub(Regexp.new("@#{bot.get_me.username}($|\s|\.|,)", Regexp::IGNORECASE), '').strip
178
+ end
179
+ end
180
+
181
+ # chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername)
182
+ # from_chat_id Integer or String Yes Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
183
+ # disable_notification Boolean Optional Sends the message silently. Users will receive a notification with no sound.
184
+ # message_id Integer Yes Message identifier in the chat specified in from_chat_id
185
+ class ForwardMessageDescriptor
186
+ include SimplifyApi
187
+ attribute :chat_id, Object, mandatory: true
188
+ attribute :from_chat_id, Object, mandatory: true
189
+ attribute :disable_notification, values: [true, false], default: true
190
+ attribute :message_id, Integer, mandatory: true
191
+ end
192
+
193
+ # update_id Integer The update‘s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially.
194
+ # message Message Optional. New incoming message of any kind — text, photo, sticker, etc.
195
+ # edited_message Message Optional. New version of a message that is known to the bot and was edited
196
+ # channel_post Message Optional. New incoming channel post of any kind — text, photo, sticker, etc.
197
+ # edited_channel_post Message Optional. New version of a channel post that is known to the bot and was edited
198
+ # inline_query InlineQuery Optional. New incoming inline query
199
+ # chosen_inline_result ChosenInlineResult Optional. The result of an inline query that was chosen by a user and sent to their chat partner. Please see our documentation on the feedback collecting for details on how to enable these updates for your bot.
200
+ # callback_query CallbackQuery Optional. New incoming callback query
201
+ # shipping_query ShippingQuery Optional. New incoming shipping query. Only for invoices with flexible price
202
+ # pre_checkout_query PreCheckoutQuery Optional. New incoming pre-checkout query. Contains full information about checkout
203
+ # poll Poll Optional. New poll state. Bots receive only updates about polls, which are sent or stopped by the bot
204
+ class Update
205
+ include SimplifyApi
206
+ attribute :update_id, Integer, mandatory: true
207
+ attribute :message, Message
208
+ attribute :edited_message, Message
209
+ attribute :channel_post, Message
210
+ attribute :inline_query, InlineQuery
211
+ attribute :chosen_inline_result, ChosenInlineResult
212
+ attribute :callback_query, CallbackQuery
213
+ attribute :poll, Poll
214
+ end
215
+
216
+ # offset Integer Optional Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will forgotten.
217
+ # limit Integer Optional Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100.
218
+ # timeout Integer Optional Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.
219
+ # allowed_updates Array of String Optional List the types of updates you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used.
220
+ class GetUpdatesDescriptor
221
+ include SimplifyApi
222
+ attribute :offset, Integer
223
+ attribute :limit, Integer
224
+ attribute :timeout, Integer
225
+ attribute :allowed_updates, [String]
226
+ end
227
+
228
+ class ResponseError < StandardError
229
+ def initialize(msg = "Bot Response Error")
230
+ super
231
+ end
232
+ end
233
+ end
data/lib/telbe/chat.rb CHANGED
@@ -106,7 +106,7 @@ module Telbe
106
106
  class Chat
107
107
  include SimplifyApi
108
108
  attribute :id, Integer, mandatory: true
109
- attribute :type, String, mandatory: true, values: ["private", "group", "supergroup", "channel"]
109
+ attribute :type, String, mandatory: true, values: %w[private group supergroup channel]
110
110
  attribute :title, String
111
111
  attribute :username, String
112
112
  attribute :first_name, String
@@ -52,7 +52,7 @@ module Telbe
52
52
  attribute :switch_inline_query, String
53
53
  attribute :switch_inline_query_current_chat, String
54
54
  # attribute :callback_game, CallbackGame
55
- attribute :pay, values: [true, false]
55
+ attribute :pay, values: [true, false]
56
56
  end
57
57
 
58
58
  # Created to nest the arrays in InlineKeyboardMarkup
data/lib/telbe/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Telbe
2
- VERSION = "0.0.6"
2
+ VERSION = '0.0.7'
3
3
  end
data/spec/bot_spec.rb ADDED
File without changes
@@ -0,0 +1,100 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = "doc"
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
data/telbe.gemspec CHANGED
@@ -1,22 +1,27 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'telbe/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "telbe"
8
+ spec.name = 'telbe'
8
9
  spec.version = Telbe::VERSION
9
- spec.date = "2019-05-07"
10
- spec.authors = ["Rodrigo Garcia Couto"]
11
- spec.email = ["r@rodg.co"]
12
- spec.summary = %q{A Telegram Bot Engine}
13
- spec.description = %q{Still in development. A Telegram Bot Engine that eventually will support all of Telegrams features.}
14
- spec.homepage = "https://github.com/rodgco/telbe"
15
- spec.license = "MIT"
10
+ spec.date = '2019-05-07'
11
+ spec.authors = ['Rodrigo Garcia Couto']
12
+ spec.email = ['r@rodg.co']
13
+ spec.summary = 'A Telegram Bot Engine'
14
+ spec.description = 'Still in development. A Telegram Bot Engine that eventually will support all of Telegrams features'
15
+ spec.homepage = 'https://github.com/rodgco/telbe'
16
+ spec.license = 'MIT'
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
18
19
 
19
- spec.add_dependency "excon", ">= 0.64.0"
20
- spec.add_dependency "simplify_api", "~> 0.1"
21
- spec.add_development_dependency "bundler", "~> 2.0"
20
+ spec.add_dependency 'excon', '>= 0.64.0'
21
+ spec.add_dependency 'simplify_api', '~> 0.1'
22
+ spec.add_development_dependency 'bundler', '~> 2.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.8'
24
+ spec.add_development_dependency 'rspec-collection_matchers', '~> 1.1'
25
+ spec.add_development_dependency 'rubocop', '~> 0'
26
+ spec.add_development_dependency 'rubocop-performance', '~> 1.4'
22
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Garcia Couto
@@ -52,8 +52,64 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-collection_matchers
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.4'
55
111
  description: Still in development. A Telegram Bot Engine that eventually will support
56
- all of Telegrams features.
112
+ all of Telegrams features
57
113
  email:
58
114
  - r@rodg.co
59
115
  executables: []
@@ -61,6 +117,7 @@ extensions: []
61
117
  extra_rdoc_files: []
62
118
  files:
63
119
  - ".gitignore"
120
+ - ".rspec"
64
121
  - Gemfile
65
122
  - README.md
66
123
  - lib/telbe.rb
@@ -77,6 +134,8 @@ files:
77
134
  - lib/telbe/user.rb
78
135
  - lib/telbe/version.rb
79
136
  - lib/telbe/webhook.rb
137
+ - spec/bot_spec.rb
138
+ - spec/spec_helper.rb
80
139
  - telbe.gemspec
81
140
  homepage: https://github.com/rodgco/telbe
82
141
  licenses:
@@ -97,8 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
156
  - !ruby/object:Gem::Version
98
157
  version: '0'
99
158
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.7.3
159
+ rubygems_version: 3.0.3
102
160
  signing_key:
103
161
  specification_version: 4
104
162
  summary: A Telegram Bot Engine