Module: Arafa::Whatsapp::MessageBody

Defined in:
lib/arafa/whatsapp/message_body.rb

Overview

Sum type over WhatsApp's polymorphic body field (§1.13). Each message kind gets its own Dry::Struct (coerced/validated the moment it's built) instead of one contract with every field across every kind marked optional — Whatsapp::AfricasTalking#body accepts any of these and calls #to_h to get the wire shape.

Defined Under Namespace

Modules: Interactive Classes: Media, Template, Text

Class Method Summary collapse

Class Method Details

.interactive_buttons(buttons:, body_text:, header_text: nil) ⇒ Object



135
136
137
# File 'lib/arafa/whatsapp/message_body.rb', line 135

def interactive_buttons(buttons:, body_text:, header_text: nil)
  Interactive::Buttons.new(buttons: buttons, body_text: body_text, header_text: header_text)
end

.interactive_list(button:, sections:, body_text:, header_text: nil, footer_text: nil) ⇒ Object



139
140
141
142
# File 'lib/arafa/whatsapp/message_body.rb', line 139

def interactive_list(button:, sections:, body_text:, header_text: nil, footer_text: nil)
  Interactive::List.new(button: button, sections: sections, body_text: body_text,
                        header_text: header_text, footer_text: footer_text)
end

.media(media_type:, url:, caption: nil) ⇒ Object



127
128
129
# File 'lib/arafa/whatsapp/message_body.rb', line 127

def media(media_type:, url:, caption: nil)
  Media.new(media_type: media_type, url: url, caption: caption)
end

.template(template_id:, body_values:, header_value: nil) ⇒ Object



131
132
133
# File 'lib/arafa/whatsapp/message_body.rb', line 131

def template(template_id:, body_values:, header_value: nil)
  Template.new(template_id: template_id, body_values: body_values, header_value: header_value)
end

.text(message:) ⇒ Object



123
124
125
# File 'lib/arafa/whatsapp/message_body.rb', line 123

def text(message:)
  Text.new(message: message)
end