Class: Line::Message::Builder::Flex::Builder
- 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
action: :message, label: "Learn More", text: "Tell me more"
end
end
end
See also:
- https://developers.line.biz/en/reference/messaging-api/#flex-messages
- Bubble
- Carousel
- QuickReply
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#bubble(**options) ⇒ Object
Defines the content of this Flex Message as a single Bubble.
-
#carousel(**options) ⇒ Object
Defines the content of this Flex Message as a Carousel of bubbles.
-
#initialize(context: nil, **options) ⇒ Builder
constructor
Initializes a new Flex Message Builder.
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, **, &) @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(**, &) @contents = Line::Message::Builder::Flex::Bubble.new(context: context, **, &) end |
#carousel(**options) ⇒ Object
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(**, &) @contents = Line::Message::Builder::Flex::Carousel.new(context: context, **, &) end |