Class: Facebook::Messenger::Incoming::Message
- Inherits:
-
Object
- Object
- Facebook::Messenger::Incoming::Message
- Includes:
- Common
- Defined in:
- lib/facebook/messenger/incoming/message.rb
Overview
Message class represents an incoming Facebook Messenger message event.
Direct Known Subclasses
Constant Summary collapse
- ATTACHMENT_TYPES =
Returns Supported attachments for message.
%w[image audio video file location fallback].freeze
Instance Attribute Summary
Attributes included from Common
Instance Method Summary collapse
-
#app_id ⇒ String
Function return app id from message.
-
#attachment_type ⇒ String
Get the type of attachment in message.
-
#attachment_url ⇒ String
Get the URL of attachment in message.
-
#attachments ⇒ Array
Function returns array containing attachment data.
-
#echo? ⇒ Boolean
Whether message is echo or not?.
-
#id ⇒ String
Function returns unique id of message.
-
#location_coordinates ⇒ Array
Get the location coordinates if attachment type is ‘location’.
-
#nlp ⇒ Hash
If facebook messenger built-in NLP is enabled, message will contain ‘nlp’ key in response.
-
#quick_reply ⇒ String
Get the payload of quick reply.
- #seq ⇒ Object
-
#text ⇒ String
Function returns text of message.
Methods included from Common
#initialize, #mark_seen, #prior_message, #recipient, #reply, #sender, #sent_at, #typing_off, #typing_on
Instance Method Details
#app_id ⇒ String
Function return app id from message.
77 78 79 |
# File 'lib/facebook/messenger/incoming/message.rb', line 77 def app_id @messaging['message']['app_id'] end |
#attachment_type ⇒ String
Get the type of attachment in message.
97 98 99 100 101 |
# File 'lib/facebook/messenger/incoming/message.rb', line 97 def return if .nil? .first['type'] end |
#attachment_url ⇒ String
Get the URL of attachment in message. URL is only available for attachments of type image/audio/video/file.
109 110 111 112 113 114 |
# File 'lib/facebook/messenger/incoming/message.rb', line 109 def return if .nil? return unless %w[image audio video file].include? .first['payload']['url'] end |
#attachments ⇒ Array
Function returns array containing attachment data
55 56 57 |
# File 'lib/facebook/messenger/incoming/message.rb', line 55 def @messaging['message']['attachments'] end |
#echo? ⇒ Boolean
Whether message is echo or not?
44 45 46 |
# File 'lib/facebook/messenger/incoming/message.rb', line 44 def echo? @messaging['message']['is_echo'] end |
#id ⇒ String
Function returns unique id of message
22 23 24 |
# File 'lib/facebook/messenger/incoming/message.rb', line 22 def id @messaging['message']['mid'] end |
#location_coordinates ⇒ Array
Get the location coordinates if attachment type is ‘location’.
122 123 124 125 126 127 |
# File 'lib/facebook/messenger/incoming/message.rb', line 122 def location_coordinates return [] unless ('location') coordinates_data = .first['payload']['coordinates'] [coordinates_data['lat'], coordinates_data['long']] end |
#nlp ⇒ Hash
If facebook messenger built-in NLP is enabled, message will
contain 'nlp' key in response.
68 69 70 |
# File 'lib/facebook/messenger/incoming/message.rb', line 68 def nlp @messaging['message']['nlp'] end |
#quick_reply ⇒ String
Get the payload of quick reply.
136 137 138 139 140 |
# File 'lib/facebook/messenger/incoming/message.rb', line 136 def quick_reply return unless @messaging['message']['quick_reply'] @messaging['message']['quick_reply']['payload'] end |
#seq ⇒ Object
26 27 28 |
# File 'lib/facebook/messenger/incoming/message.rb', line 26 def seq @messaging['message']['seq'] end |
#text ⇒ String
Function returns text of message
35 36 37 |
# File 'lib/facebook/messenger/incoming/message.rb', line 35 def text @messaging['message']['text'] end |