Class: WhatsappSdk::Resource::InteractiveAction

Inherits:
Object
  • Object
show all
Defined in:
lib/whatsapp_sdk/resource/interactive_action.rb

Defined Under Namespace

Modules: Type

Constant Summary collapse

REPLY_BUTTONS_MINIMUM =
1
REPLY_BUTTONS_MAXIMUM =
3
LIST_BUTTON_TITLE_MAXIMUM =
20
LIST_SECTIONS_MINIMUM =
1
LIST_SECTIONS_MAXIMUM =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, buttons: [], button: "", sections: []) ⇒ InteractiveAction

Returns a new instance of InteractiveAction.



54
55
56
57
58
59
# File 'lib/whatsapp_sdk/resource/interactive_action.rb', line 54

def initialize(type:, buttons: [], button: "", sections: [])
  @type = type
  @buttons = buttons
  @button = button
  @sections = sections
end

Instance Attribute Details

#buttonObject

Returns the button of the Action. For list_message type, it’s required.



30
31
32
# File 'lib/whatsapp_sdk/resource/interactive_action.rb', line 30

def button
  @button
end

#buttonsObject

Returns the buttons of the Action. For reply_button type, it’s required.



25
26
27
# File 'lib/whatsapp_sdk/resource/interactive_action.rb', line 25

def buttons
  @buttons
end

#sectionsObject

Returns the sections of the Action. For list_message type, it’s required.



35
36
37
# File 'lib/whatsapp_sdk/resource/interactive_action.rb', line 35

def sections
  @sections
end

#typeObject

Returns the type of interactive action you want to send.



20
21
22
# File 'lib/whatsapp_sdk/resource/interactive_action.rb', line 20

def type
  @type
end

Instance Method Details

#add_reply_button(reply_button) ⇒ Object

TODO: attr_accessor :catalog_id TODO: attr_accessor :product_retailer_id



40
41
42
# File 'lib/whatsapp_sdk/resource/interactive_action.rb', line 40

def add_reply_button(reply_button)
  @buttons << reply_button
end

#add_section(section) ⇒ Object



44
45
46
# File 'lib/whatsapp_sdk/resource/interactive_action.rb', line 44

def add_section(section)
  @sections << section
end

#to_jsonObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/whatsapp_sdk/resource/interactive_action.rb', line 61

def to_json
  json = {}
  case type
  when "list_message"
    json = { button: button, sections: sections.map(&:to_json) }
  when "reply_button"
    json = { buttons: buttons.map(&:to_json) }
  end

  json
end

#validateObject



73
74
75
# File 'lib/whatsapp_sdk/resource/interactive_action.rb', line 73

def validate
  validate_fields
end