class MessengerClient::ListTemplate

Constants

TEMPLATE_STYLES

Public Class Methods

new(template_items, buttons = [], style = "large") click to toggle source
# File lib/messenger_client/list_template.rb, line 5
def initialize(template_items, buttons = [], style = "large")
  @template_items = template_items
  @buttons        = buttons
  @style          = style.downcase
end

Public Instance Methods

payload() click to toggle source
# File lib/messenger_client/list_template.rb, line 15
def payload
  data = {
    template_type: type,
    elements: @template_items.map(&:to_json),
  }

  raise ArgumentError, "#{@style} is not a valid template style. Your choices are #{TEMPLATE_STYLES.join(', ')}" unless TEMPLATE_STYLES.include?(@style)
  data.merge!(top_element_style: @style)

  data.merge!(buttons: @buttons.map(&:to_json)) if @buttons.any?
  data
end
type() click to toggle source
# File lib/messenger_client/list_template.rb, line 11
def type
  "list"
end