Module: Bobot::Event::Common

Included in:
AccountLinking, Delivery, Message, Optin, PolicyEnforcement, Postback, Read, Referral
Defined in:
lib/bobot/events/common.rb

Overview

Common attributes for all incoming data from Facebook.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#messagingObject (readonly)

Returns the value of attribute messaging.



5
6
7
# File 'lib/bobot/events/common.rb', line 5

def messaging
  @messaging
end

#pageObject (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_type: "RESPONSE") ⇒ Object



40
41
42
# File 'lib/bobot/events/common.rb', line 40

def mark_as_seen(messaging_type: "RESPONSE")
  page.mark_as_seen(to: sender["id"], messaging_type: messaging_type)
end

#prior_messageObject

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 prior_message
  @messaging['prior_message']
end

#recipientObject



15
16
17
# File 'lib/bobot/events/common.rb', line 15

def recipient
  @messaging['recipient']
end

#reply(payload_message:, messaging_type: "RESPONSE") ⇒ Object



44
45
46
# File 'lib/bobot/events/common.rb', line 44

def reply(payload_message:, messaging_type: "RESPONSE")
  page.send(payload_message: payload_message, to: sender["id"], messaging_type: messaging_type)
end

#reply_with_attachment(url:, type:, messaging_type: "RESPONSE") ⇒ Object



56
57
58
# File 'lib/bobot/events/common.rb', line 56

def reply_with_attachment(url:, type:, messaging_type: "RESPONSE")
  page.send_attachment(url: url, type: type, to: sender["id"], messaging_type: messaging_type)
end

#reply_with_audio(url:, messaging_type: "RESPONSE") ⇒ Object



64
65
66
# File 'lib/bobot/events/common.rb', line 64

def reply_with_audio(url:, messaging_type: "RESPONSE")
  page.send_audio(url: url, to: sender["id"], messaging_type: messaging_type)
end

#reply_with_buttons(text:, buttons:, messaging_type: "RESPONSE") ⇒ Object



80
81
82
# File 'lib/bobot/events/common.rb', line 80

def reply_with_buttons(text:, buttons:, messaging_type: "RESPONSE")
  page.send_buttons(text: text, buttons: buttons, to: sender["id"], messaging_type: messaging_type)
end

#reply_with_file(url:, messaging_type: "RESPONSE") ⇒ Object



72
73
74
# File 'lib/bobot/events/common.rb', line 72

def reply_with_file(url:, messaging_type: "RESPONSE")
  page.send_file(url: url, to: sender["id"], messaging_type: messaging_type)
end

#reply_with_generic(elements:, image_aspect_ratio: 'square', messaging_type: "RESPONSE") ⇒ Object Also known as: reply_with_carousel



84
85
86
# File 'lib/bobot/events/common.rb', line 84

def reply_with_generic(elements:, image_aspect_ratio: 'square', messaging_type: "RESPONSE")
  page.send_generic(elements: elements, image_aspect_ratio: image_aspect_ratio, to: sender["id"], messaging_type: messaging_type)
end

#reply_with_image(url:, messaging_type: "RESPONSE") ⇒ Object



60
61
62
# File 'lib/bobot/events/common.rb', line 60

def reply_with_image(url:, messaging_type: "RESPONSE")
  page.send_image(url: url, to: sender["id"], messaging_type: messaging_type)
end

#reply_with_quick_replies(text:, quick_replies:, messaging_type: "RESPONSE") ⇒ Object



76
77
78
# File 'lib/bobot/events/common.rb', line 76

def reply_with_quick_replies(text:, quick_replies:, messaging_type: "RESPONSE")
  page.send_quick_replies(text: text, quick_replies: quick_replies, to: sender["id"], messaging_type: messaging_type)
end

#reply_with_text(text:, messaging_type: "RESPONSE") ⇒ Object



48
49
50
# File 'lib/bobot/events/common.rb', line 48

def reply_with_text(text:, messaging_type: "RESPONSE")
  page.send_text(text: text, to: sender["id"], messaging_type: messaging_type)
end

#reply_with_video(url:, messaging_type: "RESPONSE") ⇒ Object



68
69
70
# File 'lib/bobot/events/common.rb', line 68

def reply_with_video(url:, messaging_type: "RESPONSE")
  page.send_video(url: url, to: sender["id"], messaging_type: messaging_type)
end

#reply_with_youtube_video(url:, messaging_type: "RESPONSE") ⇒ Object



52
53
54
# File 'lib/bobot/events/common.rb', line 52

def reply_with_youtube_video(url:, messaging_type: "RESPONSE")
  page.send_youtube_video(url: url, to: sender["id"], messaging_type: messaging_type)
end

#senderObject



11
12
13
# File 'lib/bobot/events/common.rb', line 11

def sender
  @messaging['sender']
end

#sender_action(sender_action:, messaging_type: "RESPONSE") ⇒ Object



32
33
34
# File 'lib/bobot/events/common.rb', line 32

def sender_action(sender_action:, messaging_type: "RESPONSE")
  page.sender_action(sender_action: sender_action, to: sender["id"], messaging_type: messaging_type)
end

#sent_atObject



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_type: "RESPONSE") ⇒ Object



36
37
38
# File 'lib/bobot/events/common.rb', line 36

def show_typing(state:, messaging_type: "RESPONSE")
  page.show_typing(state: state, to: sender["id"], messaging_type: messaging_type)
end