# Receiving messages (webhooks)

Every time a user adds your LINE Official Account as a friend or sends it a message, the LINE Platform sends an HTTP POST request with a webhook event object to the webhook URL (bot server) you have specified in the LINE Developers Console.

Make sure that your bot server processes the webhook event objects correctly.

Security warning

Your bot server may receive malicious HTTP POST requests that weren't sent from the LINE Platform.

Don't process any webhook event objects until you have verified their signatures.

We recommend processing events asynchronously

We recommend processing events asynchronously, so that processing an HTTP POST request doesn't cause delays in processing subsequent requests.

# Verifying signatures

Have your bot server verify the signature in the x-line-signature request header to confirm that the request was sent from the LINE Platform.

  1. Using the HMAC-SHA256 algorithm with the channel secret as the secret key, compute the digest for the request body.
  2. Confirm that the Base64-encoded digest matches the signature in the x-line-signature request header.

The following is an example of how to implement signature validation in Python®.

import base64
import hashlib
import hmac

channel_secret = '...' # Channel secret string
body = '...' # Request body string
hash = hmac.new(channel_secret.encode('utf-8'),
    body.encode('utf-8'), hashlib.sha256).digest()
signature = base64.b64encode(hash)
# Compare x-line-signature request header and the signature

For more information and code samples, see Signature validation in the Messaging API reference.

# Webhook event types

You can control your bot's behavior and respond to the user based on the data in the webhook event object. For more information, see Webhook event object in the Messaging API reference.

# Webhook events for one-on-one chats or group chats

In one-on-one chats or group chats, you will receive these webhook events based on user action.

Event type Description 1-on-1 chats Group chats
Message event Indicates that the user sent a message. You can reply to this event.
Unsend event Indicates that the user unsent a message in a group chat or a talk room.
Follow event Indicates that your LINE Official Account was added as a friend (or unblocked). You can reply to this event.
Unfollow event Indicates that your LINE Official Account was blocked.
Join event Indicates that your LINE Official Account joined a group chat or talk room. You can reply to this event.
Leave event Indicates that the user either deleted your LINE Official Account from the group chat, or the LINE Official Account has left the group chat or talk room.
Member join event Indicates that the user joined a group chat or talk room of which your LINE Official Account is a member. You can reply to this event.
Member leave event Indicates that the user left a group or talk room of which your LINE Official Account is a member.
Postback event Indicates that the user performed a postback action. You can reply to this event.
Video viewing complete event Indicates that the user finished watching the video message with the specified trackingId sent from the LINE Official account. You can reply to this event.

✅ : Receive ❌ : Don't receive

# Webhook events for LINE Things

Some webhook events are unique to LINE Things.

Event type Description
Device link event Indicates that the user linked a device with LINE.
Device unlink event Indicates that the user unlinked a device from LINE.
LINE Things scenario execution event Indicates that an automatic communication scenario has been executed.

# Other webhook events

There are also webhook events that are sent when beacons are in use, or webhook events that are sent when accounts are linked using the Messaging API.

Event type Description
Beacon event Indicates that a user is within the reception range of the Beacon. You can reply to this event. For more information, see Using beacons.
Account link event Indicates that the user linked the LINE account with the service account provided by the provider. You can reply to this event. For more information, see Linking user accounts.

# Getting content sent by users

Your bot server can retrieve images, video, audio, and other files sent by users.

Example request

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

For more information, see Get content in the Messaging API reference.

Note
  • Content sent by users is automatically deleted after a certain period of time.
  • There is no API for retrieving text sent by users.

# Getting user profile information

Get the user ID from the webhook event object. User IDs allow you to get users' LINE profile information such as user's display name, user ID, URL to the profile image and status message.

Example request

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

If successful, a JSON object is returned.

{
    "displayName":"LINE Botto",
    "userId":"U4af4980629...",
    "pictureUrl":"https://obs.line-apps.com/...",
    "statusMessage":"Hello world!"
}

For more information, see Get profile in the Messaging API reference.