Class: TelegramBot::Update

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram-bot/models/update.rb

Overview

This object represents an incoming update. At most one of the optional parameters can be present in any given update.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Update

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/telegram-bot/models/update.rb', line 159

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `TelegramBot::Update` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `TelegramBot::Update`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'update_id')
    self.update_id = attributes[:'update_id']
  else
    self.update_id = nil
  end

  if attributes.key?(:'message')
    self.message = attributes[:'message']
  end

  if attributes.key?(:'edited_message')
    self.edited_message = attributes[:'edited_message']
  end

  if attributes.key?(:'channel_post')
    self.channel_post = attributes[:'channel_post']
  end

  if attributes.key?(:'edited_channel_post')
    self.edited_channel_post = attributes[:'edited_channel_post']
  end

  if attributes.key?(:'business_connection')
    self.business_connection = attributes[:'business_connection']
  end

  if attributes.key?(:'business_message')
    self.business_message = attributes[:'business_message']
  end

  if attributes.key?(:'edited_business_message')
    self.edited_business_message = attributes[:'edited_business_message']
  end

  if attributes.key?(:'deleted_business_messages')
    self.deleted_business_messages = attributes[:'deleted_business_messages']
  end

  if attributes.key?(:'message_reaction')
    self.message_reaction = attributes[:'message_reaction']
  end

  if attributes.key?(:'message_reaction_count')
    self.message_reaction_count = attributes[:'message_reaction_count']
  end

  if attributes.key?(:'inline_query')
    self.inline_query = attributes[:'inline_query']
  end

  if attributes.key?(:'chosen_inline_result')
    self.chosen_inline_result = attributes[:'chosen_inline_result']
  end

  if attributes.key?(:'callback_query')
    self.callback_query = attributes[:'callback_query']
  end

  if attributes.key?(:'shipping_query')
    self.shipping_query = attributes[:'shipping_query']
  end

  if attributes.key?(:'pre_checkout_query')
    self.pre_checkout_query = attributes[:'pre_checkout_query']
  end

  if attributes.key?(:'poll')
    self.poll = attributes[:'poll']
  end

  if attributes.key?(:'poll_answer')
    self.poll_answer = attributes[:'poll_answer']
  end

  if attributes.key?(:'my_chat_member')
    self.my_chat_member = attributes[:'my_chat_member']
  end

  if attributes.key?(:'chat_member')
    self.chat_member = attributes[:'chat_member']
  end

  if attributes.key?(:'chat_join_request')
    self.chat_join_request = attributes[:'chat_join_request']
  end

  if attributes.key?(:'chat_boost')
    self.chat_boost = attributes[:'chat_boost']
  end

  if attributes.key?(:'removed_chat_boost')
    self.removed_chat_boost = attributes[:'removed_chat_boost']
  end
end

Instance Attribute Details

#business_connectionObject

Optional. The bot was connected to or disconnected from a business account, or a user edited an existing connection with the bot



35
36
37
# File 'lib/telegram-bot/models/update.rb', line 35

def business_connection
  @business_connection
end

#business_messageObject

Optional. New non-service message from a connected business account



38
39
40
# File 'lib/telegram-bot/models/update.rb', line 38

def business_message
  @business_message
end

#callback_queryObject

Optional. New incoming callback query



59
60
61
# File 'lib/telegram-bot/models/update.rb', line 59

def callback_query
  @callback_query
end

#channel_postObject

Optional. New incoming channel post of any kind - text, photo, sticker, etc.



29
30
31
# File 'lib/telegram-bot/models/update.rb', line 29

def channel_post
  @channel_post
end

#chat_boostObject

Optional. A chat boost was added or changed. The bot must be an administrator in the chat to receive these updates.



83
84
85
# File 'lib/telegram-bot/models/update.rb', line 83

def chat_boost
  @chat_boost
end

#chat_join_requestObject

Optional. A request to join the chat has been sent. The bot must have the can_invite_users administrator right in the chat to receive these updates.



80
81
82
# File 'lib/telegram-bot/models/update.rb', line 80

def chat_join_request
  @chat_join_request
end

#chat_memberObject

Optional. A chat member’s status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify "chat_member" in the list of allowed_updates to receive these updates.



77
78
79
# File 'lib/telegram-bot/models/update.rb', line 77

def chat_member
  @chat_member
end

#chosen_inline_resultObject

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.



56
57
58
# File 'lib/telegram-bot/models/update.rb', line 56

def chosen_inline_result
  @chosen_inline_result
end

#deleted_business_messagesObject

Optional. Messages were deleted from a connected business account



44
45
46
# File 'lib/telegram-bot/models/update.rb', line 44

def deleted_business_messages
  @deleted_business_messages
end

#edited_business_messageObject

Optional. New version of a message from a connected business account



41
42
43
# File 'lib/telegram-bot/models/update.rb', line 41

def edited_business_message
  @edited_business_message
end

#edited_channel_postObject

Optional. New version of a channel post that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot.



32
33
34
# File 'lib/telegram-bot/models/update.rb', line 32

def edited_channel_post
  @edited_channel_post
end

#edited_messageObject

Optional. New version of a message that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot.



26
27
28
# File 'lib/telegram-bot/models/update.rb', line 26

def edited_message
  @edited_message
end

#inline_queryObject

Optional. New incoming inline query



53
54
55
# File 'lib/telegram-bot/models/update.rb', line 53

def inline_query
  @inline_query
end

#messageObject

Optional. New incoming message of any kind - text, photo, sticker, etc.



23
24
25
# File 'lib/telegram-bot/models/update.rb', line 23

def message
  @message
end

#message_reactionObject

Optional. A reaction to a message was changed by a user. The bot must be an administrator in the chat and must explicitly specify "message_reaction" in the list of allowed_updates to receive these updates. The update isn’t received for reactions set by bots.



47
48
49
# File 'lib/telegram-bot/models/update.rb', line 47

def message_reaction
  @message_reaction
end

#message_reaction_countObject

Optional. Reactions to a message with anonymous reactions were changed. The bot must be an administrator in the chat and must explicitly specify "message_reaction_count" in the list of allowed_updates to receive these updates. The updates are grouped and can be sent with delay up to a few minutes.



50
51
52
# File 'lib/telegram-bot/models/update.rb', line 50

def message_reaction_count
  @message_reaction_count
end

#my_chat_memberObject

Optional. The bot’s chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user.



74
75
76
# File 'lib/telegram-bot/models/update.rb', line 74

def my_chat_member
  @my_chat_member
end

#pollObject

Optional. New poll state. Bots receive only updates about manually stopped polls and polls, which are sent by the bot



68
69
70
# File 'lib/telegram-bot/models/update.rb', line 68

def poll
  @poll
end

#poll_answerObject

Optional. A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.



71
72
73
# File 'lib/telegram-bot/models/update.rb', line 71

def poll_answer
  @poll_answer
end

#pre_checkout_queryObject

Optional. New incoming pre-checkout query. Contains full information about checkout



65
66
67
# File 'lib/telegram-bot/models/update.rb', line 65

def pre_checkout_query
  @pre_checkout_query
end

#removed_chat_boostObject

Optional. A boost was removed from a chat. The bot must be an administrator in the chat to receive these updates.



86
87
88
# File 'lib/telegram-bot/models/update.rb', line 86

def removed_chat_boost
  @removed_chat_boost
end

#shipping_queryObject

Optional. New incoming shipping query. Only for invoices with flexible price



62
63
64
# File 'lib/telegram-bot/models/update.rb', line 62

def shipping_query
  @shipping_query
end

#update_idObject

The update’s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This identifier 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.



20
21
22
# File 'lib/telegram-bot/models/update.rb', line 20

def update_id
  @update_id
end

Class Method Details

._deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/telegram-bot/models/update.rb', line 356

def self._deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = TelegramBot.const_get(type)
    klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



118
119
120
# File 'lib/telegram-bot/models/update.rb', line 118

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/telegram-bot/models/update.rb', line 89

def self.attribute_map
  {
    :'update_id' => :'update_id',
    :'message' => :'message',
    :'edited_message' => :'edited_message',
    :'channel_post' => :'channel_post',
    :'edited_channel_post' => :'edited_channel_post',
    :'business_connection' => :'business_connection',
    :'business_message' => :'business_message',
    :'edited_business_message' => :'edited_business_message',
    :'deleted_business_messages' => :'deleted_business_messages',
    :'message_reaction' => :'message_reaction',
    :'message_reaction_count' => :'message_reaction_count',
    :'inline_query' => :'inline_query',
    :'chosen_inline_result' => :'chosen_inline_result',
    :'callback_query' => :'callback_query',
    :'shipping_query' => :'shipping_query',
    :'pre_checkout_query' => :'pre_checkout_query',
    :'poll' => :'poll',
    :'poll_answer' => :'poll_answer',
    :'my_chat_member' => :'my_chat_member',
    :'chat_member' => :'chat_member',
    :'chat_join_request' => :'chat_join_request',
    :'chat_boost' => :'chat_boost',
    :'removed_chat_boost' => :'removed_chat_boost'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/telegram-bot/models/update.rb', line 332

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



152
153
154
155
# File 'lib/telegram-bot/models/update.rb', line 152

def self.openapi_nullable
  Set.new([
  ])
end

.openapi_typesObject

Attribute type mapping.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/telegram-bot/models/update.rb', line 123

def self.openapi_types
  {
    :'update_id' => :'Integer',
    :'message' => :'Message',
    :'edited_message' => :'Message',
    :'channel_post' => :'Message',
    :'edited_channel_post' => :'Message',
    :'business_connection' => :'BusinessConnection',
    :'business_message' => :'Message',
    :'edited_business_message' => :'Message',
    :'deleted_business_messages' => :'BusinessMessagesDeleted',
    :'message_reaction' => :'MessageReactionUpdated',
    :'message_reaction_count' => :'MessageReactionCountUpdated',
    :'inline_query' => :'InlineQuery',
    :'chosen_inline_result' => :'ChosenInlineResult',
    :'callback_query' => :'CallbackQuery',
    :'shipping_query' => :'ShippingQuery',
    :'pre_checkout_query' => :'PreCheckoutQuery',
    :'poll' => :'Poll',
    :'poll_answer' => :'PollAnswer',
    :'my_chat_member' => :'ChatMemberUpdated',
    :'chat_member' => :'ChatMemberUpdated',
    :'chat_join_request' => :'ChatJoinRequest',
    :'chat_boost' => :'ChatBoostUpdated',
    :'removed_chat_boost' => :'ChatBoostRemoved'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/telegram-bot/models/update.rb', line 289

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      update_id == o.update_id &&
      message == o.message &&
      edited_message == o.edited_message &&
      channel_post == o.channel_post &&
      edited_channel_post == o.edited_channel_post &&
      business_connection == o.business_connection &&
      business_message == o.business_message &&
      edited_business_message == o.edited_business_message &&
      deleted_business_messages == o.deleted_business_messages &&
      message_reaction == o.message_reaction &&
      message_reaction_count == o.message_reaction_count &&
      inline_query == o.inline_query &&
      chosen_inline_result == o.chosen_inline_result &&
      callback_query == o.callback_query &&
      shipping_query == o.shipping_query &&
      pre_checkout_query == o.pre_checkout_query &&
      poll == o.poll &&
      poll_answer == o.poll_answer &&
      my_chat_member == o.my_chat_member &&
      chat_member == o.chat_member &&
      chat_join_request == o.chat_join_request &&
      chat_boost == o.chat_boost &&
      removed_chat_boost == o.removed_chat_boost
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'lib/telegram-bot/models/update.rb', line 427

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


319
320
321
# File 'lib/telegram-bot/models/update.rb', line 319

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



325
326
327
# File 'lib/telegram-bot/models/update.rb', line 325

def hash
  [update_id, message, edited_message, channel_post, edited_channel_post, business_connection, business_message, edited_business_message, deleted_business_messages, message_reaction, message_reaction_count, inline_query, chosen_inline_result, callback_query, shipping_query, pre_checkout_query, poll, poll_answer, my_chat_member, chat_member, chat_join_request, chat_boost, removed_chat_boost].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



269
270
271
272
273
274
275
276
277
# File 'lib/telegram-bot/models/update.rb', line 269

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  if @update_id.nil?
    invalid_properties.push('invalid value for "update_id", update_id cannot be nil.')
  end

  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



403
404
405
# File 'lib/telegram-bot/models/update.rb', line 403

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/telegram-bot/models/update.rb', line 409

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



397
398
399
# File 'lib/telegram-bot/models/update.rb', line 397

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



281
282
283
284
285
# File 'lib/telegram-bot/models/update.rb', line 281

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  return false if @update_id.nil?
  true
end