Class: UI::FBButtonTemplate
- Inherits:
-
Object
- Object
- UI::FBButtonTemplate
- Defined in:
- lib/ui/fb_button_template.rb
Overview
BUTTON TEMPLATE ############################# developers.facebook.com/docs/messenger-platform/send-api-reference/button-template
Instance Method Summary collapse
-
#build(user) ⇒ Object
Use this method to return a valid hash and save it for later.
-
#initialize(text, buttons) ⇒ FBButtonTemplate
constructor
A new instance of FBButtonTemplate.
-
#send(user) ⇒ Object
Sends the valid JSON to Messenger API.
Constructor Details
#initialize(text, buttons) ⇒ FBButtonTemplate
Returns a new instance of FBButtonTemplate.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ui/fb_button_template.rb', line 7 def initialize(text, ) @template = { recipient: { id: nil }, message: { attachment: { type: 'template', payload: { template_type: 'button', text: text, buttons: () } } } } end |
Instance Method Details
#build(user) ⇒ Object
Use this method to return a valid hash and save it for later
32 33 34 35 |
# File 'lib/ui/fb_button_template.rb', line 32 def build(user) @template[:recipient][:id] = user.id @template end |
#send(user) ⇒ Object
Sends the valid JSON to Messenger API
26 27 28 29 |
# File 'lib/ui/fb_button_template.rb', line 26 def send(user) formed = build(user) Bot.deliver(formed, access_token: ENV['ACCESS_TOKEN']) end |