Module: Line::Message::Builder::Flex::Actionable

Included in:
Box, Button, Image, Text
Defined in:
lib/line/message/builder/flex/actionable.rb

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:

Class Method Summary collapse

Instance Method Summary collapse

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

button_component.message "Hello User!", label: "Send Greeting"


48
49
50
# File 'lib/line/message/builder/flex/actionable.rb', line 48

def message(text, **options, &)
  @action = Actions::Message.new(text, context: context, **options, &)
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

button_component.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, **options, &)
  @action = Actions::Postback.new(data, context: context, **options, &)
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

button_component.uri "https://example.com", label: "Learn more"


83
84
85
# File 'lib/line/message/builder/flex/actionable.rb', line 83

def uri(uri, **options, &)
  @action = Actions::Uri.new(uri, context: context, **options, &)
end