Class: WhatsappSdk::Resource::InteractiveHeader

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

Defined Under Namespace

Modules: Type

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, text: nil, image: nil, document: nil, video: nil) ⇒ InteractiveHeader

Returns a new instance of InteractiveHeader.



40
41
42
43
44
45
46
47
# File 'lib/whatsapp_sdk/resource/interactive_header.rb', line 40

def initialize(type:, text: nil, image: nil, document: nil, video: nil)
  @type = type
  @text = text
  @image = image
  @document = document
  @video = video
  validate
end

Instance Attribute Details

#documentObject

Returns document if the interactive header type is document.



33
34
35
# File 'lib/whatsapp_sdk/resource/interactive_header.rb', line 33

def document
  @document
end

#imageObject

Returns image if the interactive header type is image.



28
29
30
# File 'lib/whatsapp_sdk/resource/interactive_header.rb', line 28

def image
  @image
end

#textObject

Returns Text string if the interactive header type is text. For the header interactive, the character limit is 60 characters. For the body interactive, the character limit is 1024 characters.



23
24
25
# File 'lib/whatsapp_sdk/resource/interactive_header.rb', line 23

def text
  @text
end

#typeObject

Returns the interactive header type.



9
10
11
# File 'lib/whatsapp_sdk/resource/interactive_header.rb', line 9

def type
  @type
end

#videoObject

Returns video if the interactive header type is video.



38
39
40
# File 'lib/whatsapp_sdk/resource/interactive_header.rb', line 38

def video
  @video
end

Instance Method Details

#to_jsonObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/whatsapp_sdk/resource/interactive_header.rb', line 49

def to_json
  json = { type: type }
  json[type.to_sym] = case type
                      when "text"
                        text
                      when "image"
                        image.to_json
                      when "document"
                        document.to_json
                      when "video"
                        video.to_json
                      else
                        raise "Invalid type: #{type}"
                      end

  json
end