class Line::Message::Builder::Actions::Message
Represents a message action for LINE messages.
A message action sends a specified text message to the chat from the user when a button associated with this action is tapped. Itโs commonly used in quick replies or other interactive message components.
Example
Line::Message::Builder.with do text "Select your favorite food:" quick_reply do # When this button is tapped, the user sends "Pizza" button action: :message, label: "Pizza", text: "Pizza" # When this button is tapped, the user sends "Sushi" button action: :message, label: "Sushi", text: "Sushi" end end
See also:
Attributes
The text that is sent as a message from the user when the action is performed. This is a required attribute.
Public Class Methods
Source
# File lib/line/message/builder/actions/message.rb, line 69 def initialize(text, context: nil, **options, &) @text = text super(context: context, **options, &) end
Initializes a new Message action.
- text
-
The text to be sent when the action is performed (required)
- context
-
An optional context object for resolving method calls within a block
- options
-
A hash of options to set instance variables (can include
:label) - block
-
An optional block to be instance-evalโd (not commonly used for simple actions)
Raises RequiredError if text is nil (this check is done in to_h but text is conceptually required on initialization).
Example
action = Message.new("Hello, world!") action = Message.new("Pizza", label: "Select Pizza")
Line::Message::Builder::Base::new
Public Instance Methods
Source
# File lib/line/message/builder/actions/message.rb, line 90 def to_h raise RequiredError, "text is required" if text.nil? return to_sdkv2 if context.sdkv2? to_api end
Converts the Message action object to a hash suitable for the LINE Messaging API.
The returned hash includes :type, :label (if set), and :text.
Raises RequiredError if text is nil.
Example
action = Message.new("Pizza") action.to_h # => { type: "message", text: "Pizza" }
- return
-
A hash representing the message action