Class: Line::Message::Builder::QuickReply

Inherits:
Base
  • Object
show all
Defined in:
lib/line/message/builder/quick_reply.rb

Overview

The QuickReply class provides a builder for creating quick reply buttons that can be attached to text messages or flex messages in the LINE Messaging API.

Quick reply buttons appear at the bottom of the chat screen and allow users to quickly respond to messages with predefined actions. They provide a convenient way to guide user interactions without requiring typing.

Quick replies support:

  • Message actions that send text messages when tapped
  • Postback actions that send data to your webhook
  • Optional image icons for each button (up to 13 buttons total)

Example: Basic quick reply with message actions

Line::Message::Builder.with do
text "Choose your favorite:" do
  quick_reply do
    message "Pizza", label: "Pizza"
    message "Sushi", label: "Sushi"
  end
end
end

Example: Quick reply with postback actions

Line::Message::Builder.with do
text "What would you like to do?" do
  quick_reply do
    postback "action=order", label: "Place Order", display_text: "I want to order"
    postback "action=track", label: "Track Order"
  end
end
end

Example: Quick reply with image icons

Line::Message::Builder.with do
text "Select a category:" do
  quick_reply do
    message "Food", label: "Food", image_url: "https://example.com/food.png"
    message "Drinks", label: "Drinks", image_url: "https://example.com/drinks.png"
  end
end
end

See also:

Instance Attribute Summary

Attributes inherited from Base

#context

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(context: nil) ⇒ QuickReply

Creates a new quick reply builder.

Quick reply builders manage a collection of action buttons that appear at the bottom of messages. The builder provides methods to add message and postback actions with optional image icons.

[context] An optional context object for method delegation (default: nil) [block] Block for configuring quick reply buttons using message, postback and uri methods

Example

quick_reply = QuickReply.new(context: view_context) do
message "Yes", label: "Yes"
message "No", label: "No"
end


75
76
77
78
79
# File 'lib/line/message/builder/quick_reply.rb', line 75

def initialize(context: nil, &)
  @items = []

  super
end

Dynamic Method Handling

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

Instance Method Details

#message(text, label:, image_url: nil) ⇒ Object

Adds a message action button to the quick reply.

Message actions send the specified text as a message from the user when the button is tapped. This is useful for providing predefined response options that simplify user interaction.

[text] The text message to send when the button is tapped [label] The label text displayed on the button (required) [image_url] Optional icon image URL for the button (default: nil) [block] Optional block for additional configuration

Example: Basic message button

quick_reply do
message "I agree", label: "Yes"
message "I disagree", label: "No"
end

Example: Message button with icon

quick_reply do
message "Order pizza", label: "Pizza",
        image_url: "https://example.com/pizza.png"
end


109
110
111
112
113
114
# File 'lib/line/message/builder/quick_reply.rb', line 109

def message(text, label:, image_url: nil, &)
  action(
    Actions::Message.new(text, context: context, label: label, &),
    image_url
  )
end

#postback(data, label: nil, display_text: nil, image_url: nil) ⇒ Object

Adds a postback action button to the quick reply.

Postback actions send data to your bot's webhook when the button is tapped, allowing you to trigger backend logic without displaying a message. Optionally, you can specify display text that will appear in the chat as if the user sent it.

[data] The data payload to send to the webhook (max 300 characters) [label] The label text displayed on the button (default: nil) [display_text] Text to display in chat when tapped (default: nil) [image_url] Optional icon image URL for the button (default: nil) [block] Optional block for additional configuration

Example: Basic postback button

quick_reply do
postback "action=yes", label: "Yes"
postback "action=no", label: "No"
end

Example: Postback with display text

quick_reply do
postback "action=order&item=pizza",
         label: "Order Pizza",
         display_text: "I'd like to order a pizza"
end

Example: Postback button with icon

quick_reply do
postback "action=confirm",
         label: "Confirm",
         image_url: "https://example.com/check.png"
end


156
157
158
159
160
161
# File 'lib/line/message/builder/quick_reply.rb', line 156

def postback(data, label: nil, display_text: nil, image_url: nil, &)
  action(
    Actions::Postback.new(data, context: context, label: label, display_text: display_text, &),
    image_url
  )
end

#uri(uri, label:, image_url: nil) ⇒ Object

Adds a URI action button to the quick reply.

URI actions open the given URI when the button is tapped, without any webhook handling. The altUri.desktop property is not supported in a quick reply, so Actions::Uri#alt_uri_desktop has no effect here.

[uri] The URI to open. Schemes http, https, line and tel [label] The label text displayed on the button (required) [image_url] Optional icon image URL for the button (default: nil) [block] Optional block for additional configuration

Example: Basic URI button

quick_reply do
uri "https://example.com/menu", label: "See menu"
end

Example: URI button with icon

quick_reply do
uri "tel:+81312345678", label: "Call us",
    image_url: "https://example.com/phone.png"
end


191
192
193
194
195
196
# File 'lib/line/message/builder/quick_reply.rb', line 191

def uri(uri, label:, image_url: nil, &)
  action(
    Actions::Uri.new(uri, context: context, label: label, &),
    image_url
  )
end