Module: Facebook::Messenger::Incoming::Common
- Included in:
- AccountLinking, Delivery, GamePlay, Message, MessageReaction, Optin, PassThreadControl, Payment, PolicyEnforcement, Postback, Read, Referral
- Defined in:
- lib/facebook/messenger/incoming/common.rb
Overview
Common attributes for all incoming data from Facebook.
Instance Attribute Summary collapse
-
#messaging ⇒ Object
readonly
Returns the value of attribute messaging.
Instance Method Summary collapse
-
#initialize(messaging) ⇒ Object
Assign message to instance variable.
-
#mark_seen ⇒ Object
Function send sender_action of ‘mark_seen’ to sender.
-
#prior_message ⇒ Hash
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.
-
#recipient ⇒ String
Function return id of the page from which the message has arrived.
-
#reply(message) ⇒ Object
Send reply to sender.
-
#sender ⇒ String
Function return PSID of sender.
-
#sent_at ⇒ Object
Function return timestamp when message is sent.
-
#typing_off ⇒ Object
Function send sender_action of ‘typing_off’ to sender.
-
#typing_on ⇒ Object
Function send sender_action of ‘typing_on’ to sender.
Instance Attribute Details
#messaging ⇒ Object (readonly)
Returns the value of attribute messaging.
8 9 10 |
# File 'lib/facebook/messenger/incoming/common.rb', line 8 def messaging @messaging end |
Instance Method Details
#initialize(messaging) ⇒ Object
Assign message to instance variable
15 16 17 |
# File 'lib/facebook/messenger/incoming/common.rb', line 15 def initialize(messaging) @messaging = messaging end |
#mark_seen ⇒ Object
Function send sender_action of ‘mark_seen’ to sender.
103 104 105 106 107 108 109 110 |
# 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 |
#prior_message ⇒ Hash
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.
51 52 53 |
# File 'lib/facebook/messenger/incoming/common.rb', line 51 def @messaging['prior_message'] end |
#recipient ⇒ String
Function return id of the page from which the message has arrived.
38 39 40 |
# File 'lib/facebook/messenger/incoming/common.rb', line 38 def recipient @messaging['recipient'] end |
#reply(message) ⇒ Object
Send reply to sender.
119 120 121 122 123 124 125 126 127 |
# File 'lib/facebook/messenger/incoming/common.rb', line 119 def reply() payload = { recipient: sender, message: , message_type: Facebook::Messenger::Bot::MessageType::RESPONSE } Facebook::Messenger::Bot.deliver(payload, page_id: recipient['id']) end |
#sender ⇒ String
Function return PSID of sender.
29 30 31 |
# File 'lib/facebook/messenger/incoming/common.rb', line 29 def sender @messaging['sender'] end |
#sent_at ⇒ Object
Function return timestamp when message is sent.
60 61 62 |
# File 'lib/facebook/messenger/incoming/common.rb', line 60 def sent_at Time.at(@messaging['timestamp'] / 1000) end |
#typing_off ⇒ Object
Function send sender_action of ‘typing_off’ to sender.
87 88 89 90 91 92 93 94 |
# 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 |
#typing_on ⇒ Object
Function send sender_action of ‘typing_on’ to sender.
71 72 73 74 75 76 77 78 |
# 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 |