module Line::Message::Builder::Flex::Actionable
The Actionable module provides a DSL for defining an action that can be triggered when a user interacts with certain Flex Message components (e.g., a Button component, or an entire Bubble or Box component if itβs made tappable).
When a component includes this module, it gains methods like message and postback to associate a specific LINE action with itself. The chosen action is stored in the action attribute.
Attributes
The following attribute is automatically added to classes that include this module:
- action
-
The action object associated with this component. Returns an
Actions::Message,Actions::Postback, ornilif no action is defined.
See also:
Public Instance Methods
Source
# File lib/line/message/builder/flex/actionable.rb, line 47 def message(text, **options, &) @action = Actions::Message.new(text, context: context, **options, &) end
Defines a message action for the component. When the component is tapped, a message with the given text is sent from the user to the chat.
- text
-
The text of the message to send
- options
-
Additional options for the message action, such as
:label. SeeActions::Message
Example
button_component.message "Hello User!", label: "Send Greeting"
Source
# File lib/line/message/builder/flex/actionable.rb, line 64 def postback(data, **options, &) @action = Actions::Postback.new(data, context: context, **options, &) end
Defines a postback action for the component. When the component is tapped, a postback event with the given data is sent to the botβs webhook.
- data
-
The data payload for the postback event
- options
-
Additional options for the postback action, such as
:labelor:display_text. SeeActions::Postback
Example
button_component.postback "action=buy&item_id=123", label: "Buy Item"