Class: Bobot::Event::Message

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/bobot/events/message.rb

Direct Known Subclasses

MessageEcho, MessageRequest

Constant Summary collapse

ATTACHMENT_TYPES =
%w[image audio video file location fallback].freeze

Instance Attribute Summary

Attributes included from Common

#messaging, #page

Instance Method Summary collapse

Methods included from Common

#initialize, #mark_as_seen, #prior_message, #recipient, #reply, #reply_with_attachment, #reply_with_audio, #reply_with_buttons, #reply_with_file, #reply_with_generic, #reply_with_image, #reply_with_quick_replies, #reply_with_text, #reply_with_video, #reply_with_youtube_video, #send_pass_thread_control, #send_take_thread_control, #sender, #sender_action, #sent_at, #show_typing

Instance Method Details

#app_idObject



32
33
34
# File 'lib/bobot/events/message.rb', line 32

def app_id
  @messaging['message']['app_id']
end

#attachment_typeObject



42
43
44
45
46
# File 'lib/bobot/events/message.rb', line 42

def attachment_type
  return if attachments.nil?

  attachments.first['type']
end

#attachment_urlObject



48
49
50
51
52
53
# File 'lib/bobot/events/message.rb', line 48

def attachment_url
  return if attachments.nil?
  return unless %w[image audio video file].include? attachment_type

  attachments.first['payload']['url']
end

#attachmentsObject



24
25
26
# File 'lib/bobot/events/message.rb', line 24

def attachments
  @messaging['message']['attachments']
end

#echo?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/bobot/events/message.rb', line 20

def echo?
  @messaging['message']['is_echo'].present?
end

#idObject



8
9
10
# File 'lib/bobot/events/message.rb', line 8

def id
  @messaging['message']['mid']
end

#location_coordinatesObject



55
56
57
58
59
60
# File 'lib/bobot/events/message.rb', line 55

def location_coordinates
  return [] unless attachment_type?('location')

  coordinates_data = attachments.first['payload']['coordinates']
  [coordinates_data['lat'], coordinates_data['long']]
end

#nlpObject



28
29
30
# File 'lib/bobot/events/message.rb', line 28

def nlp
  @messaging['message']['nlp']
end

#quick_replyObject Also known as: payload



62
63
64
65
66
# File 'lib/bobot/events/message.rb', line 62

def quick_reply
  return unless @messaging['message']['quick_reply']

  @messaging['message']['quick_reply']['payload']
end

#seqObject



12
13
14
# File 'lib/bobot/events/message.rb', line 12

def seq
  @messaging['message']['seq']
end

#textObject



16
17
18
# File 'lib/bobot/events/message.rb', line 16

def text
  @messaging['message']['text']
end