Module: Bobot::Event::Common
- Included in:
- AccountLinking, Delivery, Message, Optin, PassThreadControl, PolicyEnforcement, Postback, Read, Referral, TakeThreadControl
- Defined in:
- lib/bobot/events/common.rb
Overview
Common attributes for all incoming data from Facebook.
Instance Attribute Summary collapse
-
#messaging ⇒ Object
readonly
Returns the value of attribute messaging.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
- #initialize(messaging) ⇒ Object
- #mark_as_seen(messaging_options: nil) ⇒ Object
-
#prior_message ⇒ Object
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 ⇒ Object
- #reply(payload_message:, messaging_options: nil) ⇒ Object
- #reply_with_attachment(url:, type:, messaging_options: nil) ⇒ Object
- #reply_with_audio(url:, messaging_options: nil) ⇒ Object
- #reply_with_buttons(text:, buttons:, messaging_options: nil) ⇒ Object
- #reply_with_file(url:, messaging_options: nil) ⇒ Object
- #reply_with_generic(elements:, image_aspect_ratio: 'square', messaging_options: nil) ⇒ Object (also: #reply_with_carousel)
- #reply_with_image(url:, messaging_options: nil) ⇒ Object
- #reply_with_quick_replies(text:, quick_replies:, messaging_options: nil) ⇒ Object
- #reply_with_text(text:, messaging_options: nil) ⇒ Object
- #reply_with_video(url:, messaging_options: nil) ⇒ Object
- #reply_with_youtube_video(url:, messaging_options: nil) ⇒ Object
- #send_pass_thread_control(target_app_id:, metadata: nil) ⇒ Object
- #send_take_thread_control(metadata: nil) ⇒ Object
- #sender ⇒ Object
- #sender_action(sender_action:, messaging_options: nil) ⇒ Object
- #sent_at ⇒ Object
- #show_typing(state:, messaging_options: nil) ⇒ Object
Instance Attribute Details
#messaging ⇒ Object (readonly)
Returns the value of attribute messaging.
5 6 7 |
# File 'lib/bobot/events/common.rb', line 5 def messaging @messaging end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
5 6 7 |
# File 'lib/bobot/events/common.rb', line 5 def page @page end |
Instance Method Details
#initialize(messaging) ⇒ Object
7 8 9 |
# File 'lib/bobot/events/common.rb', line 7 def initialize(messaging) @messaging = messaging end |
#mark_as_seen(messaging_options: nil) ⇒ Object
48 49 50 |
# File 'lib/bobot/events/common.rb', line 48 def mark_as_seen(messaging_options: nil) page.mark_as_seen(to: sender["id"], messaging_options: ) end |
#prior_message ⇒ Object
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.
24 25 26 |
# File 'lib/bobot/events/common.rb', line 24 def @messaging['prior_message'] end |
#recipient ⇒ Object
15 16 17 |
# File 'lib/bobot/events/common.rb', line 15 def recipient @messaging[is_a?(Bobot::Event::MessageEcho) ? 'sender' : 'recipient'] end |
#reply(payload_message:, messaging_options: nil) ⇒ Object
52 53 54 |
# File 'lib/bobot/events/common.rb', line 52 def reply(payload_message:, messaging_options: nil) page.send(payload_message: , to: sender["id"], messaging_options: ) end |
#reply_with_attachment(url:, type:, messaging_options: nil) ⇒ Object
64 65 66 |
# File 'lib/bobot/events/common.rb', line 64 def (url:, type:, messaging_options: nil) page.(url: url, type: type, to: sender["id"], messaging_options: ) end |
#reply_with_audio(url:, messaging_options: nil) ⇒ Object
72 73 74 |
# File 'lib/bobot/events/common.rb', line 72 def reply_with_audio(url:, messaging_options: nil) page.send_audio(url: url, to: sender["id"], messaging_options: ) end |
#reply_with_buttons(text:, buttons:, messaging_options: nil) ⇒ Object
88 89 90 |
# File 'lib/bobot/events/common.rb', line 88 def (text:, buttons:, messaging_options: nil) page.(text: text, buttons: , to: sender["id"], messaging_options: ) end |
#reply_with_file(url:, messaging_options: nil) ⇒ Object
80 81 82 |
# File 'lib/bobot/events/common.rb', line 80 def reply_with_file(url:, messaging_options: nil) page.send_file(url: url, to: sender["id"], messaging_options: ) end |
#reply_with_generic(elements:, image_aspect_ratio: 'square', messaging_options: nil) ⇒ Object Also known as: reply_with_carousel
92 93 94 |
# File 'lib/bobot/events/common.rb', line 92 def reply_with_generic(elements:, image_aspect_ratio: 'square', messaging_options: nil) page.send_generic(elements: elements, image_aspect_ratio: image_aspect_ratio, to: sender["id"], messaging_options: ) end |
#reply_with_image(url:, messaging_options: nil) ⇒ Object
68 69 70 |
# File 'lib/bobot/events/common.rb', line 68 def reply_with_image(url:, messaging_options: nil) page.send_image(url: url, to: sender["id"], messaging_options: ) end |
#reply_with_quick_replies(text:, quick_replies:, messaging_options: nil) ⇒ Object
84 85 86 |
# File 'lib/bobot/events/common.rb', line 84 def reply_with_quick_replies(text:, quick_replies:, messaging_options: nil) page.send_quick_replies(text: text, quick_replies: quick_replies, to: sender["id"], messaging_options: ) end |
#reply_with_text(text:, messaging_options: nil) ⇒ Object
56 57 58 |
# File 'lib/bobot/events/common.rb', line 56 def reply_with_text(text:, messaging_options: nil) page.send_text(text: text, to: sender["id"], messaging_options: ) end |
#reply_with_video(url:, messaging_options: nil) ⇒ Object
76 77 78 |
# File 'lib/bobot/events/common.rb', line 76 def reply_with_video(url:, messaging_options: nil) page.send_video(url: url, to: sender["id"], messaging_options: ) end |
#reply_with_youtube_video(url:, messaging_options: nil) ⇒ Object
60 61 62 |
# File 'lib/bobot/events/common.rb', line 60 def reply_with_youtube_video(url:, messaging_options: nil) page.send_youtube_video(url: url, to: sender["id"], messaging_options: ) end |
#send_pass_thread_control(target_app_id:, metadata: nil) ⇒ Object
36 37 38 |
# File 'lib/bobot/events/common.rb', line 36 def send_pass_thread_control(target_app_id:, metadata: nil) page.deliver_pass_thread_control(to: sender["id"], metadata: , target_app_id: target_app_id) end |
#send_take_thread_control(metadata: nil) ⇒ Object
32 33 34 |
# File 'lib/bobot/events/common.rb', line 32 def send_take_thread_control(metadata: nil) page.deliver_take_thread_control(to: sender["id"], metadata: ) end |
#sender ⇒ Object
11 12 13 |
# File 'lib/bobot/events/common.rb', line 11 def sender @messaging[is_a?(Bobot::Event::MessageEcho) ? 'recipient' : 'sender'] end |
#sender_action(sender_action:, messaging_options: nil) ⇒ Object
40 41 42 |
# File 'lib/bobot/events/common.rb', line 40 def sender_action(sender_action:, messaging_options: nil) page.sender_action(sender_action: sender_action, to: sender["id"], messaging_options: ) end |
#sent_at ⇒ Object
28 29 30 |
# File 'lib/bobot/events/common.rb', line 28 def sent_at Time.zone.at(@messaging['timestamp'] / 1000) end |
#show_typing(state:, messaging_options: nil) ⇒ Object
44 45 46 |
# File 'lib/bobot/events/common.rb', line 44 def show_typing(state:, messaging_options: nil) page.show_typing(state: state, to: sender["id"], messaging_options: ) end |