Class: FlowChat::Whatsapp::Renderer

Inherits:
Object
  • Object
show all
Includes:
Renderers::MarkdownSupport
Defined in:
lib/flow_chat/whatsapp/renderer.rb

Constant Summary collapse

BUTTON_TITLE_LENGTH =

WhatsApp button and list row title limits. The choice mapper reads these too, to alias the truncated title it knows this renderer will display for a given choice count.

20
LIST_ROW_TITLE_LENGTH =
24
MAX_CAPTION_LENGTH =

Meta: "Media asset caption text. Maximum 1024 characters." Documented for image, video, and document messages. Audio and sticker messages' own schemas list only id/link (audio also has voice) - no caption field at all - so they can never carry the numbered body this way, however short it is.

1024
CAPTIONABLE_MEDIA_TYPES =
[:image, :video, :document].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Renderers::MarkdownSupport

included, #sanitize_html, #to_html, #to_plain_text

Constructor Details

#initialize(message, choices: nil, media: nil) ⇒ Renderer

Returns a new instance of Renderer.



24
25
26
27
28
# File 'lib/flow_chat/whatsapp/renderer.rb', line 24

def initialize(message, choices: nil, media: nil)
  @message = message
  @choices = choices
  @media = media
end

Instance Attribute Details

#choicesObject (readonly)

Returns the value of attribute choices.



22
23
24
# File 'lib/flow_chat/whatsapp/renderer.rb', line 22

def choices
  @choices
end

#mediaObject (readonly)

Returns the value of attribute media.



22
23
24
# File 'lib/flow_chat/whatsapp/renderer.rb', line 22

def media
  @media
end

#messageObject (readonly)

Returns the value of attribute message.



22
23
24
# File 'lib/flow_chat/whatsapp/renderer.rb', line 22

def message
  @message
end

Instance Method Details

#renderObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/flow_chat/whatsapp/renderer.rb', line 30

def render
  if media && choices
    build_selection_message_with_media
  elsif media
    build_media_message
  elsif choices
    build_selection_message
  else
    build_text_message
  end
end