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

Inherits:
Base
  • Object
show all
Includes:
Actionable, Position::Margin, Position::Offset, Position::Vertical, Size::AdjustMode, Size::Flex
Defined in:
lib/line/message/builder/flex/button.rb

Overview

Represents a "button" component in a LINE Flex Message.

Buttons are interactive elements that users can tap to trigger an action (e.g., open a URL, send a message, or trigger a postback). They have various styling options, including style (primary, secondary, link), color and height.

An action is mandatory for a button component.

Buttons have no padding properties of their own; use the padding of the surrounding Box to inset a button.

Example

Line::Message::Builder.with do
flex alt_text: "Button Example" do
  bubble do
    body do
      button style: :primary, height: :sm do
        message "Buy Now", label: "Buy" # Action definition
      end
    end
  end
end
end

Example: Tinting a primary button

Line::Message::Builder.with do
flex alt_text: "Button Example" do
  bubble do
    body do
      button style: :primary, color: "#1DB446" do
        message "Buy Now", label: "Buy"
      end
    end
  end
end
end

See also:

  • https://developers.line.biz/en/reference/messaging-api/#button
  • Actionable for defining the button's action (mandatory)
  • Position::Vertical for gravity property
  • Position::Margin for margin property
  • Position::Offset for offset properties
  • Size::Flex for flex sizing property
  • Size::AdjustMode for adjust_mode property

Instance Attribute Summary

Attributes inherited from Base

#context

Instance Method Summary collapse

Methods included from Size::AdjustMode

included, #shrink_to_fit!

Methods included from Size::Flex

included

Methods included from Position::Offset

included

Methods included from Position::Margin

included

Methods included from Position::Vertical

included

Methods included from Actionable

included, #message, #postback, #uri

Methods inherited from Base

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

Constructor Details

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

Initializes a new Flex Message Button component.

The provided block is instance-eval'd, primarily used to define the button's action using methods from the Actionable module (e.g., message).

[context] An optional context for the builder [options] A hash of options to set instance variables (e.g., :style, :height, and options from included modules) [block] A block to define the button's action and other properties. This block is where you should call an action method like message or postback.



124
125
126
# File 'lib/line/message/builder/flex/button.rb', line 124

def initialize(context: nil, **options, &)
  super # Calls Base#initialize, sets options, and evals block (which should define the action)
end

Dynamic Method Handling

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