Module: Bobot::Event::Common

Included in:
AccountLinking, Delivery, Message, Optin, 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_seenObject



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

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

#recipientObject



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

def recipient
  @messaging['recipient']
end

#reply(payload_message:) ⇒ Object



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

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

#reply_with_attachment(url:, type:) ⇒ Object



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

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

#reply_with_audio(url:) ⇒ Object



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

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

#reply_with_buttons(text:, buttons:) ⇒ Object



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

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

#reply_with_file(url:) ⇒ Object



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

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

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



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

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

#reply_with_image(url:) ⇒ Object



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

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

#reply_with_quick_replies(text:, quick_replies:) ⇒ Object



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

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

#reply_with_text(text:) ⇒ Object



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

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

#reply_with_video(url:) ⇒ Object



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

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

#senderObject



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

def sender
  @messaging['sender']
end

#sender_action(sender_action:) ⇒ Object



23
24
25
# File 'lib/bobot/events/common.rb', line 23

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

#sent_atObject



19
20
21
# File 'lib/bobot/events/common.rb', line 19

def sent_at
  Time.zone.at(@messaging['timestamp'] / 1000)
end

#show_typing(state:) ⇒ Object



27
28
29
# File 'lib/bobot/events/common.rb', line 27

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