Class: Line::Message::Builder::Flex::Builder

Inherits:
Base
  • Object
show all
Defined in:
lib/line/message/builder/flex/builder.rb

Overview

The Builder class is the main entry point for constructing a complete LINE Flex Message. A Flex Message is a highly customizable message type that can contain one main content element, which is either a single Bubble or a Carousel of bubbles.

This builder requires alt_text (alternative text) for accessibility and for display on devices or LINE versions that cannot render Flex Messages. It can also have a quickReply attached to it.

Example: Creating a Flex Message with a single bubble

Line::Message::Builder.with do
flex alt_text: "My Product" do
  flex_builder.bubble size: :giga do
    hero_image "https://example.com/product.jpg"
    body do
      text "Product Name", weight: :bold, size: :xl
    end
  end
  quick_reply do
    button action: :message, label: "Learn More", text: "Tell me more"
  end
end
end

See also:

Instance Attribute Summary

Attributes inherited from Base

#context

Instance Method Summary collapse

Methods inherited from Base

inherited, #method_missing, #quick_reply, #respond_to_missing?, #to_h

Constructor Details

#initialize(context: nil, **options) ⇒ Builder

Initializes a new Flex Message Builder. The provided block is instance-eval'd, allowing DSL methods like #bubble or #carousel to define the main content.

[context] An optional context for the builder. [option] A hash of options to set instance variables (e.g., :alt_text). [block] A block to define the content (bubble or carousel) of this Flex Message.



61
62
63
64
65
# File 'lib/line/message/builder/flex/builder.rb', line 61

def initialize(context: nil, **options, &)
  @contents = nil # Will hold either a Bubble or Carousel instance

  super # Calls Base#initialize, sets options (like @alt_text), and evals block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Line::Message::Builder::Base

Instance Method Details

#bubble(**options) ⇒ Object

Defines the content of this Flex Message as a single Bubble. If called, this will overwrite any previously defined carousel content.

[option] Options for the Bubble. See Bubble#initialize. [block] A block to define the sections of the Bubble.



74
75
76
# File 'lib/line/message/builder/flex/builder.rb', line 74

def bubble(**options, &)
  @contents = Line::Message::Builder::Flex::Bubble.new(context: context, **options, &)
end

Defines the content of this Flex Message as a Carousel of bubbles. If called, this will overwrite any previously defined bubble content.

[option] Options for the Carousel. See Carousel#initialize. [block] A block to define the bubbles within the Carousel.



85
86
87
# File 'lib/line/message/builder/flex/builder.rb', line 85

def carousel(**options, &)
  @contents = Line::Message::Builder::Flex::Carousel.new(context: context, **options, &)
end