# Sending messages

You can create bots to send various types of messages to users via two main messaging methods: reply messages and push messages.

dummy dummy
Messaging method
  • Replies (a.k.a. "reply messages")
  • Push messages
    • Push messages (one-to-one)
    • Multicast messages (one-to-many, targeting a list of user IDs)
    • Narrowcast messages (one-to-many, targeting a segmented list)
    • Broadcast messages (one-to-many, targeting all friends)
Message types
  • Text message
  • Sticker message
  • Image message
  • Video message
  • Audio message
  • Location message
  • Imagemap message
  • Template message
  • Flex message
For more information on the types of messages you can send using the Messaging API, see Message types.

# Messaging methods

The Messaging API provides two main messaging methods for you to use: replies (a.k.a. "reply messages") and push messages.

# Reply messages

Reply messages are sent in response to user actions, such as adding your LINE Official Account as a friend or sending it a message.

The body of the message should contain the same reply token that was part of the webhook event. You can send up to 5 message objects in a single request.

Example request

curl -v -X POST https://api.line.me/v2/bot/message/reply \
-H 'Content-Type:application/json' \
-H 'Authorization: Bearer {channel access token}' \
-d '{
    "replyToken":"nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
    "messages":[
        {
            "type":"text",
            "text":"Hello, user"
        },
        {
            "type":"text",
            "text":"May I help you?"
        }
    ]
}'

For more information, see Send reply message in the Messaging API reference.

# Push messages

Push messages are messages that you can send to users at any time. Send these messages by one of the following methods:

Message method Recipient(s)
Push messages Sent to a single user
Multicast messages Sent to multiple users
Narrowcast messages Sent to multiple users via attribute data or retargeting
Broadcast messages Sent to all friends of your LINE Official Account

Unlike reply messages, push messages do not require a reply token. You can send up to 5 message objects in a single request.

Sample request for multicast message

curl -v -X POST https://api.line.me/v2/bot/message/multicast \
-H 'Content-Type:application/json' \
-H 'Authorization: Bearer {channel access token}' \
-d '{
    "to": ["U4af4980629...","U0c229f96c4..."],
    "messages":[
        {
            "type":"text",
            "text":"Hello, world1"
        },
        {
            "type":"text",
            "text":"Hello, world2"
        }
    ]
}'

# Sending messages to multiple users via attribute data or retargeting (narrowcast messages)

This technique lets you send a push message to multiple users at any time. You can specify recipients using attributes (such as age, gender, OS, and region) or by retargeting (audiences). Messages cannot be sent to groups or rooms.

Follow these steps to send narrowcast messages:

  1. Prepare a list of recipients
  2. Begin sending narrowcast messages
  3. Check the status of the narrowcast messages
Messages are sent asynchronously

Narrowcast messages are sent asynchronously in the background. The API call to send the messages always succeeds, but failures can occur once the messages start to be delivered. You must check the messages' status to determine if they were sent successfully.

# Preparing a list of recipients

You must prepare different kinds of data for different types of recipients. You can combine these recipients using logical operators (AND, OR, and NOT). For example, the recipients could be all users who have either received message A OR clicked a URL in message B.

Recipients Data to prepare
All users who have added your LINE Official Account as a friend Nothing.
Users who can be identified by a user ID or Identifier for Advertisers (IFA) Create an audience for uploading user IDs*
Users who have clicked a URL in a message you sent them before Create an audience for click-based retargeting*
Users who have opened a message you sent them before Create an audience for impression-based retargeting*

* If you have created an audience, follow the instructions below to confirm that it is ready to accept messages.

# Confirming that an audience is ready to accept messages

Audiences are created asynchronously in the background. Confirm that an audience's status has changed to READY (ready to accept messages) before you start sending it narrowcast messages.

You can check an audience's status via the following API endpoint.

curl -v -X GET https://api.line.me/v2/bot/audienceGroup/{audienceGroupId} \
-H 'Authorization: Bearer {channel access token}'

Once the status property in the response has changed to READY (ready to accept messages), you may begin sending narrowcast messages with that audience given as the recipient.

Learn more about checking an audience's status from Get audience data in the Messaging API Reference.

# Beginning to send narrowcast messages

To begin to send narrowcast messages, specify the message you want to send (messages property) and its recipient (the recipient objects in the recipient property). If you omit the recipient property, the messages are sent to every user who has added your LINE Official Account as a friend.

The recipient object can represent a complex set of criteria using logical conjunctions (AND operators), disjunctions (OR operators), and complements (NOT operators).

Example recipient object representing an audience

{
    "type": "audience",
    "audienceGroupId": 5614991017776
}

You can also specify a demographic filter object (in the filter.demographic property), which will allow you to segment your recipient list using friends' attributes (such as age, gender, OS, and region). The demographic filter object can similarly represent a complex set of criteria using logical conjunctions (AND operators), disjunctions (OR operators), and complements (NOT operators).

Using attribute data
  • The attribute data used for demographic filters is always 3 days old.
  • If you don't specify any attributes, messages will be sent to everyone—even users with attribute values of "unknown".

Example demographic filter object for gender

{
    "type": "gender",
    "oneOf": [
        "male",
        "female"
    ]
}

Example request

curl -v -X POST https://api.line.me/v2/bot/message/narrowcast \
-H 'Authorization: Bearer {channel access token}' \
-H 'Content-Type: application/json' \
-d '{
    "messages": [
        {
            "type": "text",
            "text": "test message"
        }
    ],
    "recipient": {
        "type": "operator",
        "and": [
            {
                "type": "audience",
                "audienceGroupId": 5614991017776
            },
            {
                "type": "operator",
                "not": {
                    "type": "audience",
                    "audienceGroupId": 4389303728991
                }
            }
        ]
    },
    "filter": {
        "demographic": {
            "type": "operator",
            "or": [
                {
                    "type": "operator",
                    "and": [
                        {
                            "type": "gender",
                            "oneOf": [
                                "male",
                                "female"
                            ]
                        },
                        {
                            "type": "age",
                            "gte": "age_20",
                            "lt": "age_25"
                        },
                        {
                            "type": "appType",
                            "oneOf": [
                                "android",
                                "ios"
                            ]
                        },
                        {
                            "type": "area",
                            "oneOf": [
                                "jp_23",
                                "jp_05"
                            ]
                        },
                        {
                            "type": "subscriptionPeriod",
                            "gte": "day_7",
                            "lt": "day_30"
                        }
                    ]
                },
                {
                    "type": "operator",
                    "and": [
                        {
                            "type": "age",
                            "gte": "age_35",
                            "lt": "age_40"
                        },
                        {
                            "type": "operator",
                            "not": {
                                "type": "gender",
                                "oneOf": [
                                    "male"
                                ]
                            }
                        }
                    ]
                }
            ]
        }
    },
    "limit": {
        "max": 100
    }
}'

Learn more from Sending narrowcast messages in the Messaging API Reference.

# Checking the status of a narrowcast message

Narrowcast messages are sent asynchronously in the background. We offer an API endpoint that allows you to check if a narrowcast message was successfully sent.

curl -v -X GET https://api.line.me/v2/bot/message/progress/narrowcast?requestId={request_id} \
-H 'Authorization: Bearer {channel access token}'

Learn more from Get narrowcast message status in the Messaging API Reference.

# Usage restrictions of narrowcast messages

When using narrowcast messages, please take note of the following:

  • To use attribute data, your "Target reach" number must be 100 or more.
  • Combine audience and attribute data so that the number of recipients is 50 or more. If this criterion isn't met, you can't send narrowcast messages. However, you can send to less than 50 people if:
    • You use an audience for uploading the user ID without using attribute data
    • You use the chat tag audience
  • When sending narrowcast messages, you can specify up to 10 audiences (recipient objects).