Class: UI::FBButtonTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/ui/fb_button_template.rb

Overview

Instance Method Summary collapse

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, buttons)
  @template = {
    recipient: {
      id: nil
    },
    message: {
      attachment: {
        type: 'template',
        payload: {
          template_type: 'button',
          text: text,
          buttons: parse_buttons(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