Class: MessengerClient::ListTemplate
- Defined in:
- lib/messenger_client/list_template.rb
Constant Summary collapse
- TEMPLATE_STYLES =
%w(plain)
Instance Method Summary collapse
-
#initialize(template_items, buttons = [], style = nil) ⇒ ListTemplate
constructor
A new instance of ListTemplate.
- #payload ⇒ Object
- #type ⇒ Object
Methods inherited from Template
Constructor Details
#initialize(template_items, buttons = [], style = nil) ⇒ ListTemplate
Returns a new instance of ListTemplate.
5 6 7 8 9 |
# File 'lib/messenger_client/list_template.rb', line 5 def initialize(template_items, = [], style = nil) @template_items = template_items @buttons = @style = style end |
Instance Method Details
#payload ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/messenger_client/list_template.rb', line 15 def payload data = { template_type: type, elements: @template_items.map(&:to_json), } if !@style.nil? raise ArgumentError, "#{@style} is not a valid template style" unless TEMPLATE_STYLES.include?(@style) data.merge!(top_element_style: @style) end data.merge!(buttons: @buttons.map(&:to_json)) if @buttons.any? data end |
#type ⇒ Object
11 12 13 |
# File 'lib/messenger_client/list_template.rb', line 11 def type "list" end |