Class: WhatsappSdk::Resource::Interactive

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

Defined Under Namespace

Modules: Type

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, body:, action:, header: nil, footer: nil) ⇒ Interactive

Returns a new instance of Interactive.



38
39
40
41
42
43
44
45
# File 'lib/whatsapp_sdk/resource/interactive.rb', line 38

def initialize(type:, body:, action:, header: nil, footer: nil)
  @type = type
  @body = body
  @action = action
  @header = header
  @footer = footer
  validate
end

Instance Attribute Details

#actionObject

Returns the interactive action.



36
37
38
# File 'lib/whatsapp_sdk/resource/interactive.rb', line 36

def action
  @action
end

#bodyObject

Returns the interactive body.



26
27
28
# File 'lib/whatsapp_sdk/resource/interactive.rb', line 26

def body
  @body
end

Returns the interactive footer if present.



31
32
33
# File 'lib/whatsapp_sdk/resource/interactive.rb', line 31

def footer
  @footer
end

#headerObject

Returns the interactive header if present. Required for type product_list.



21
22
23
# File 'lib/whatsapp_sdk/resource/interactive.rb', line 21

def header
  @header
end

#typeObject

Returns the Interactive type of message you want to send.



16
17
18
# File 'lib/whatsapp_sdk/resource/interactive.rb', line 16

def type
  @type
end

Instance Method Details

#to_jsonObject



47
48
49
50
51
52
53
54
55
# File 'lib/whatsapp_sdk/resource/interactive.rb', line 47

def to_json
  json = { type: type }
  json[:header] = header.to_json if header
  json[:body] = body.to_json
  json[:footer] = footer.to_json if footer
  json[:action] = action.to_json

  json
end