Module: Facebook::Messenger::Incoming::Common
- Included in:
- AccountLinking, Delivery, Message, Optin, 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
-
#access_token ⇒ String
Function returns the configured access token.
-
#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 the page of id from which the message is 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
#access_token ⇒ String
Function returns the configured access token.
134 135 136 |
# File 'lib/facebook/messenger/incoming/common.rb', line 134 def access_token Facebook::Messenger.config.provider.access_token_for(recipient) end |
#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, access_token: access_token) 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.
50 51 52 |
# File 'lib/facebook/messenger/incoming/common.rb', line 50 def @messaging['prior_message'] end |
#recipient ⇒ String
Function return the page of id from which the message is arrived.
37 38 39 |
# File 'lib/facebook/messenger/incoming/common.rb', line 37 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, access_token: access_token) end |
#sender ⇒ String
Function return PSID of sender.
28 29 30 |
# File 'lib/facebook/messenger/incoming/common.rb', line 28 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, access_token: access_token) 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, access_token: access_token) end |