Module: Line::Message::Builder::Flex::Actionable
Overview
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,
postback and uri 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, or nil if no action is defined.
See also:
- Line::Message::Builder::Actions::Message
- Line::Message::Builder::Actions::Postback
- Line::Message::Builder::Actions::Uri
- https://developers.line.biz/en/reference/messaging-api/#action-objects
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#message(text, **options) ⇒ Object
Defines a message action for the component.
-
#postback(data, **options) ⇒ Object
Defines a postback action for the component.
-
#uri(uri, **options) ⇒ Object
Defines a URI action for the component.
Class Method Details
.included(base) ⇒ Object
:nodoc:
31 32 33 |
# File 'lib/line/message/builder/flex/actionable.rb', line 31 def self.included(base) # :nodoc: base.attr_reader :action end |
Instance Method Details
#message(text, **options) ⇒ Object
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.
See Actions::Message
Example
. "Hello User!", label: "Send Greeting"
48 49 50 |
# File 'lib/line/message/builder/flex/actionable.rb', line 48 def (text, **, &) @action = Actions::Message.new(text, context: context, **, &) end |
#postback(data, **options) ⇒ Object
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 :label or
:display_text. See Actions::Postback
Example
.postback "action=buy&item_id=123", label: "Buy Item"
65 66 67 |
# File 'lib/line/message/builder/flex/actionable.rb', line 65 def postback(data, **, &) @action = Actions::Postback.new(data, context: context, **, &) end |
#uri(uri, **options) ⇒ Object
Defines a URI action for the component. When the component is tapped, the given URI is opened. No webhook handling is needed, which makes this the action to use for linking a component to a web page.
[uri]
The URI to open. Schemes http, https, line and tel
[options]
Additional options for the URI action, such as :label or
:alt_uri_desktop. See Actions::Uri
Example
.uri "https://example.com", label: "Learn more"
83 84 85 |
# File 'lib/line/message/builder/flex/actionable.rb', line 83 def uri(uri, **, &) @action = Actions::Uri.new(uri, context: context, **, &) end |