module Facebook::Messenger::Incoming::Common
Attributes
Public Class Methods
Assign message to instance variable
@param [Object] messaging Object of message.
# File lib/facebook/messenger/incoming/common.rb, line 15 def initialize(messaging) @messaging = messaging end
Public Instance Methods
Function send sender_action of 'mark_seen' to sender. @see developers.facebook.com/docs/messenger-platform/send-messages/sender-actions
Info about sender actions.
@return Send message to sender.
# File lib/facebook/messenger/incoming/common.rb, line 103 def mark_seen payload = { recipient: sender, sender_action: 'mark_seen' } Facebook::Messenger::Bot.deliver(payload, page_id: recipient['id']) end
If the user responds to your message, the appropriate event (messages, messaging_postbacks, etc.) will be sent to your webhook, with a prior_message
object appended. The prior_message
object includes the source of the message the user is responding to, as well as the user_ref used for the original message send.
@return [Hash] The 'prior_message' hash.
# File lib/facebook/messenger/incoming/common.rb, line 51 def prior_message @messaging['prior_message'] end
Function return id of the page from which the message has arrived.
@return [String] Facebook
page id.
# File lib/facebook/messenger/incoming/common.rb, line 38 def recipient @messaging['recipient'] end
Send reply to sender.
@param [Hash] message Hash defining the message.
@return Send reply to sender.
# File lib/facebook/messenger/incoming/common.rb, line 119 def reply(message) payload = { recipient: sender, message: message, message_type: Facebook::Messenger::Bot::MessageType::RESPONSE } Facebook::Messenger::Bot.deliver(payload, page_id: recipient['id']) end
Function return PSID of sender.
@see developers.facebook.com/docs/messenger-platform/identity
Info about PSID.
@see developers.facebook.com/docs/messenger-platform/webhook#format
Webhook event format.
@return [String] PSID of sender.
# File lib/facebook/messenger/incoming/common.rb, line 29 def sender @messaging['sender'] end
Function return timestamp when message is sent.
@return [Object] Message
time sent.
# File lib/facebook/messenger/incoming/common.rb, line 60 def sent_at Time.at(@messaging['timestamp'] / 1000) end
Function send sender_action of 'typing_off' to sender. @see developers.facebook.com/docs/messenger-platform/send-messages/sender-actions
Info about sender actions.
@return Send message to sender.
# File lib/facebook/messenger/incoming/common.rb, line 87 def typing_off payload = { recipient: sender, sender_action: 'typing_off' } Facebook::Messenger::Bot.deliver(payload, page_id: recipient['id']) end
Function send sender_action of 'typing_on' to sender. @see developers.facebook.com/docs/messenger-platform/send-messages/sender-actions
Info about sender actions.
@return Send message to sender.
# File lib/facebook/messenger/incoming/common.rb, line 71 def typing_on payload = { recipient: sender, sender_action: 'typing_on' } Facebook::Messenger::Bot.deliver(payload, page_id: recipient['id']) end