# 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 object correctly.

Don't blindly trust HTTP POST requests your bot server receives

Your bot server may receive malicious HTTP POST requests that were not 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 on the basis of the data in the webhook event object.

# Webhook events for one-on-one chats

The following webhook events are available for the one-on-one chat. For more information, see Webhook event objects in the Messaging API reference.

Event type Description
Message event Indicates that the user sent a message. You can reply to this event.
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 account joined a group or talk room. You can reply to this event.
Leave event Indicates that a user deleted your bot from a group or that your bot left a group or talk room.
Member join event This event indicates that the user has joined a group or talk room of which the bot is a member. You can reply to this event.
Member leave event This event indicates that the user has left a group or talk room of which the bot 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 has finished watching the video message with the specified trackingId sent from the LINE Official account. You can reply to this event.
Beacon event Indicates that the user entered the range of a LINE Beacon device. You can reply to this event. For more information, see Using beacons.
Account link event Indicates that the user has linked their LINE account with a provider's (your) service account. You can reply to this event. For more information, see Linking user accounts.

# Webhook events for group chats

See Group chats for webhook events that are specific to group chats.

# 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.

# 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.