Messaging API client for LINE
npm i --save messaging-api-line
or
yarn add messaging-api-line
const { LineClient } = require('messaging-api-line');
// get accessToken and channelSecret from LINE developers website
const client = LineClient.connect(accessToken, channelSecret);
All methods return a Promise.
Reply API - Official Docs
Responds to events from users, groups, and rooms.
Responds messages using specified reply token.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
messages | Array<Object> |
Array of objects which contains the contents of the message to be sent. |
Example:
client.reply(REPLY_TOKEN, [
{
type: 'text',
text: 'Hello!',
},
]);
replyToken
can only be used once, but you can send up to 5 messages using the same token.
const { Line } = require('messaging-api-line');
client.reply(REPLY_TOKEN, [
Line.createText('Hello'),
Line.createImage(
'https://example.com/original.jpg',
'https://example.com/preview.jpg'
),
Line.createText('End'),
]);
replyText(token, text)
- Official Docs
Responds text message using specified reply token.
You can include LINE original emoji in text messages using character codes. For a list of LINE emoji that can be sent in LINE chats, see the emoji list.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
text | String |
Text of the message to be sent. |
Example:
client.reply(REPLY_TOKEN, 'Hello!');
replyImage(token, imageUrl, previewImageUrl)
- Official Docs
Responds image message using specified reply token.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
imageUrl | String |
Image URL. |
previewImageUrl | String |
Preview image URL. |
Example:
client.replyImage(
REPLY_TOKEN,
'https://example.com/original.jpg',
'https://example.com/preview.jpg'
);
replyVideo(token, videoUrl, previewImageUrl)
- Official Docs
Responds video message using specified reply token.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
videoUrl | String |
URL of video file. |
previewImageUrl | String |
URL of preview image. |
Example:
client.replyVideo(
REPLY_TOKEN,
'https://example.com/original.mp4',
'https://example.com/preview.jpg'
);
replyAudio(token, audioUrl, duration)
- Official Docs
Responds audio message using specified reply token.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
audioUrl | String |
URL of audio file. |
duration | Number |
Length of audio file. |
Example:
client.replyAudio(REPLY_TOKEN, 'https://example.com/original.m4a', 240000);
replyLocation(token, location)
- Official Docs
Responds location message using specified reply token.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
location | Object |
Object contains location's parameters. |
location.title | String |
Title of the location. |
location.address | String |
Address of the location. |
location.latitude | Number |
Latitude of the location. |
location.longitude | Number |
Longitude of the location. |
Example:
client.replyLocation(REPLY_TOKEN, {
title: 'my location',
address: '〒150-0002 東京都渋谷区渋谷2丁目21−1',
latitude: 35.65910807942215,
longitude: 139.70372892916203,
});
replySticker(token, packageId, stickerId)
- Official Docs
Responds sticker message using specified reply token.
For a list of stickers that can be sent with the Messaging API, see the sticker list.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
packageId | String |
Package ID. |
stickerId | String |
Sticker ID. |
Example:
client.replySticker(REPLY_TOKEN, '1', '1');
replyImagemap(token, altText, imagemap)
- Official Docs
Responds imagemap message using specified reply token.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
altText | String |
Alternative text. |
imagemap | Object |
Object contains imagemap's parameters. |
imagemap.baseUrl | String |
Base URL of image. |
imagemap.baseSize | Object |
Base size object. |
imagemap.baseSize.width | Number |
Width of base image. |
imagemap.baseSize.height | Number |
Height of base image. |
imagemap.actions | Array<Object> |
Action when tapped. |
Example:
client.replyImagemap(REPLY_TOKEN, 'this is an imagemap', {
baseUrl: 'https://example.com/bot/images/rm001',
baseSize: {
width: 1040,
height: 1040,
},
actions: [
{
type: 'uri',
linkUri: 'https://example.com/',
area: {
x: 0,
y: 0,
width: 520,
height: 1040,
},
},
{
type: 'message',
text: 'hello',
area: {
x: 520,
y: 0,
width: 520,
height: 1040,
},
},
],
});
replyTemplate(token, altText, template)
- Official Docs
Responds template message using specified reply token.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
altText | String |
Alternative text. |
template | Object |
Object with the contents of the template. |
Example:
client.replyTemplate(REPLY_TOKEN, 'this is a template', {
type: 'buttons',
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
title: 'Menu',
text: 'Please select',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=123',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=123',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/123',
},
],
});
replyButtonTemplate(token, altText, buttonTemplate)
- Official Docs
Responds button template message using specified reply token.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
altText | String |
Alternative text. |
buttonTemplate | Object |
Object contains buttonTemplate's parameters. |
buttonTemplate.thumbnailImageUrl | String |
Image URL of buttonTemplate. |
buttonTemplate.imageAspectRatio | String |
Aspect ratio of the image. Specify one of the following values: rectangle , square |
buttonTemplate.imageSize | String |
Size of the image. Specify one of the following values: cover , contain |
buttonTemplate.imageBackgroundColor | String |
Background color of image. Specify a RGB color value. The default value is #FFFFFF (white). |
buttonTemplate.title | String |
Title of buttonTemplate. |
buttonTemplate.text | String |
Message text of buttonTemplate. |
buttonTemplate.actions | Array<Object> |
Action when tapped. |
Example:
client.replyButtonTemplate(REPLY_TOKEN, 'this is a template', {
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
title: 'Menu',
text: 'Please select',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=123',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=123',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/123',
},
],
});
replyConfirmTemplate(token, altText, confirmTemplate)
- Official Docs
Responds confirm template message using specified reply token.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
altText | String |
Alternative text. |
confirmTemplate | Object |
Object contains confirmTemplate's parameters. |
confirmTemplate.text | String |
Message text of confirmTemplate. |
confirmTemplate.actions | Array<Object> |
Action when tapped. |
Example:
client.replyConfirmTemplate(REPLY_TOKEN, 'this is a confirm template', {
text: 'Are you sure?',
actions: [
{
type: 'message',
label: 'Yes',
text: 'yes',
},
{
type: 'message',
label: 'No',
text: 'no',
},
],
});
replyCarouselTemplate(token, altText, carouselItems, options)
- Official Docs
Responds carousel template message using specified reply token.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
altText | String |
Alternative text. |
carouselItems | Array<Object> |
Array of columns which contains object for carousel. |
options | Object |
Object contains options. |
options.imageAspectRatio | String |
Aspect ratio of the image. Specify one of the following values: rectangle , square |
options.imageSize | String |
Size of the image. Specify one of the following values: cover , contain |
Example:
client.replyCarouselTemplate(REPLY_TOKEN, 'this is a carousel template', [
{
thumbnailImageUrl: 'https://example.com/bot/images/item1.jpg',
title: 'this is menu',
text: 'description',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=111',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=111',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/111',
},
],
},
{
thumbnailImageUrl: 'https://example.com/bot/images/item2.jpg',
title: 'this is menu',
text: 'description',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=222',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=222',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/222',
},
],
},
]);
replyImageCarouselTemplate(token, altText, carouselItems)
- Official Docs
Responds image carousel template message using specified reply token.
Param | Type | Description |
---|---|---|
token | String |
replyToken received via webhook. |
altText | String |
Alternative text. |
carouselItems | Array<Object> |
Array of columns which contains object for image carousel. |
Example:
client.replyImageCarouselTemplate(
REPLY_TOKEN,
'this is an image carousel template',
[
{
imageUrl: 'https://example.com/bot/images/item1.jpg',
action: {
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=111',
},
},
{
imageUrl: 'https://example.com/bot/images/item2.jpg',
action: {
type: 'message',
label: 'Yes',
text: 'yes',
},
},
{
imageUrl: 'https://example.com/bot/images/item3.jpg',
action: {
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/222',
},
},
]
);
Push API - Official Docs
Sends messages to a user, group, or room at any time.
Sends messages using ID of the receiver.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
messages | Array<Object> |
Array of objects which contains the contents of the message to be sent. |
Example:
client.push(USER_ID, [
{
type: 'text',
text: 'Hello!',
},
]);
pushText(userId, text)
- Official Docs
Sends text message using ID of the receiver.
You can include LINE original emoji in text messages using character codes. For a list of LINE emoji that can be sent in LINE chats, see the emoji list.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
text | String |
Text of the message to be sent. |
Example:
client.pushText(USER_ID, 'Hello!');
pushImage(userId, imageUrl, previewImageUrl)
- Official Docs
Sends image message using ID of the receiver.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
imageUrl | String |
Image URL. |
previewImageUrl | String |
Preview image URL. |
Example:
client.pushImage(
USER_ID,
'https://example.com/original.jpg',
'https://example.com/preview.jpg'
);
pushVideo(userId, videoUrl, previewImageUrl)
- Official Docs
Sends video message using ID of the receiver.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
videoUrl | String |
URL of video file. |
previewImageUrl | String |
URL of preview image. |
Example:
client.pushVideo(
USER_ID,
'https://example.com/original.mp4',
'https://example.com/preview.jpg'
);
pushAudio(userId, audioUrl, duration)
- Official Docs
Sends audio message using ID of the receiver.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
audioUrl | String |
URL of audio file. |
duration | Number |
Length of audio file. |
Example:
client.pushAudio(USER_ID, 'https://example.com/original.m4a', 240000);
pushLocation(userId, location)
- Official Docs
Sends location message using ID of the receiver.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
location | Object |
Object contains location's parameters. |
location.title | String |
Title of the location. |
location.address | String |
Address of the location. |
location.latitude | Number |
Latitude of the location. |
location.longitude | Number |
Longitude of the location. |
Example:
client.pushLocation(USER_ID, {
title: 'my location',
address: '〒150-0002 東京都渋谷区渋谷2丁目21−1',
latitude: 35.65910807942215,
longitude: 139.70372892916203,
});
pushSticker(userId, packageId, stickerId)
- Official Docs
Sends sticker message using ID of the receiver.
For a list of stickers that can be sent with the Messaging API, see the sticker list.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
packageId | String |
Package ID. |
stickerId | String |
Sticker ID. |
Example:
client.pushSticker(USER_ID, '1', '1');
pushImagemap(userId, altText, imagemap)
- Official Docs
Sends imagemap message using ID of the receiver.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
altText | String |
Alternative text. |
imagemap | Object |
Object contains imagemap's parameters. |
imagemap.baseUrl | String |
Base URL of image. |
imagemap.baseSize | Object |
Base size object. |
imagemap.baseSize.width | Number |
Width of base image. |
imagemap.baseSize.height | Number |
Height of base image. |
imagemap.actions | Array<Object> |
Action when tapped. |
Example:
client.pushImagemap(USER_ID, 'this is an imagemap', {
baseUrl: 'https://example.com/bot/images/rm001',
baseSize: {
width: 1040,
height: 1040,
},
actions: [
{
type: 'uri',
linkUri: 'https://example.com/',
area: {
x: 0,
y: 0,
width: 520,
height: 1040,
},
},
{
type: 'message',
text: 'hello',
area: {
x: 520,
y: 0,
width: 520,
height: 1040,
},
},
],
});
pushTemplate(userId, altText, template)
- Official Docs
Sends template message using ID of the receiver.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
altText | String |
Alternative text. |
template | Object |
Object with the contents of the template. |
Example:
client.pushTemplate(USER_ID, 'this is a template', {
type: 'buttons',
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
title: 'Menu',
text: 'Please select',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=123',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=123',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/123',
},
],
});
pushButtonTemplate(userId, altText, buttonTemplate)
- Official Docs
Sends button template message using ID of the receiver.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
altText | String |
Alternative text. |
buttonTemplate | Object |
Object contains buttonTemplate's parameters. |
buttonTemplate.thumbnailImageUrl | String |
Image URL of buttonTemplate. |
buttonTemplate.imageAspectRatio | String |
Aspect ratio of the image. Specify one of the following values: rectangle , square |
buttonTemplate.imageSize | String |
Size of the image. Specify one of the following values: cover , contain |
buttonTemplate.imageBackgroundColor | String |
Background color of image. Specify a RGB color value. The default value is #FFFFFF (white). |
buttonTemplate.title | String |
Title of buttonTemplate. |
buttonTemplate.text | String |
Message text of buttonTemplate. |
buttonTemplate.actions | Array<Object> |
Action when tapped. |
Example:
client.pushButtonTemplate(USER_ID, 'this is a template', {
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
title: 'Menu',
text: 'Please select',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=123',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=123',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/123',
},
],
});
pushConfirmTemplate(userId, altText, confirmTemplate)
- Official Docs
Sends confirm template message using ID of the receiver.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
altText | String |
Alternative text. |
confirmTemplate | Object |
Object contains confirmTemplate's parameters. |
confirmTemplate.text | String |
Message text of confirmTemplate. |
confirmTemplate.actions | Array<Object> |
Action when tapped. |
Example:
client.pushConfirmTemplate(USER_ID, 'this is a confirm template', {
text: 'Are you sure?',
actions: [
{
type: 'message',
label: 'Yes',
text: 'yes',
},
{
type: 'message',
label: 'No',
text: 'no',
},
],
});
pushCarouselTemplate(userId, altText, carouselItems, options)
- Official Docs
Sends carousel template message using ID of the receiver.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
altText | String |
Alternative text. |
carouselItems | Array<Object> |
Array of columns which contains object for carousel. |
options | Object |
Object contains options. |
options.imageAspectRatio | String |
Aspect ratio of the image. Specify one of the following values: rectangle , square |
options.imageSize | String |
Size of the image. Specify one of the following values: cover , contain |
Example:
client.pushCarouselTemplate(USER_ID, 'this is a carousel template', [
{
thumbnailImageUrl: 'https://example.com/bot/images/item1.jpg',
title: 'this is menu',
text: 'description',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=111',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=111',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/111',
},
],
},
{
thumbnailImageUrl: 'https://example.com/bot/images/item2.jpg',
title: 'this is menu',
text: 'description',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=222',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=222',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/222',
},
],
},
]);
pushImageCarouselTemplate(userId, altText, carouselItems)
- Official Docs
Sends image carousel template message using ID of the receiver.
Param | Type | Description |
---|---|---|
userId | String |
ID of the receiver. |
altText | String |
Alternative text. |
carouselItems | Array<Object> |
Array of columns which contains object for image carousel. |
Example:
client.pushImageCarouselTemplate(
USER_ID,
'this is an image carousel template',
[
{
imageUrl: 'https://example.com/bot/images/item1.jpg',
action: {
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=111',
},
},
{
imageUrl: 'https://example.com/bot/images/item2.jpg',
action: {
type: 'message',
label: 'Yes',
text: 'yes',
},
},
{
imageUrl: 'https://example.com/bot/images/item3.jpg',
action: {
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/222',
},
},
]
);
Multicast API - Official Docs
Sends messages to multiple users at any time.
Sends messages to multiple users.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
messages | Array<Object> |
Array of objects which contains the contents of the message to be sent. |
Example:
client.multicast(
[USER_ID],
[
{
type: 'text',
text: 'Hello!',
},
]
);
multicastText(userIds, text)
- Official Docs
Sends text message to multiple users.
You can include LINE original emoji in text messages using character codes. For a list of LINE emoji that can be sent in LINE chats, see the emoji list.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
text | String |
Text of the message to be sent. |
Example:
client.multicastText([USER_ID], 'Hello!');
multicastImage(userIds, imageUrl, previewImageUrl)
- Official Docs
Sends image message to multiple users.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
imageUrl | String |
Image URL. |
previewImageUrl | String |
Preview image URL. |
Example:
client.multicastImage(
[USER_ID],
'https://example.com/original.jpg',
'https://example.com/preview.jpg'
);
multicastVideo(userIds, videoUrl, previewImageUrl)
- Official Docs
Sends video message to multiple users.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
videoUrl | String |
URL of video file. |
previewImageUrl | String |
URL of preview image. |
Example:
client.multicastVideo(
[USER_ID],
'https://example.com/original.mp4',
'https://example.com/preview.jpg'
);
multicastAudio(userIds, audioUrl, duration)
- Official Docs
Sends audio message to multiple users.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
audioUrl | String |
URL of audio file. |
duration | Number |
Length of audio file. |
Example:
client.multicastAudio([USER_ID], 'https://example.com/original.m4a', 240000);
multicastLocation(userIds, location)
- Official Docs
Sends location message to multiple users.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
location | Object |
Object contains location's parameters. |
location.title | String |
Title of the location. |
location.address | String |
Address of the location. |
location.latitude | Number |
Latitude of the location. |
location.longitude | Number |
Longitude of the location. |
Example:
client.multicastLocation([USER_ID], {
title: 'my location',
address: '〒150-0002 東京都渋谷区渋谷2丁目21−1',
latitude: 35.65910807942215,
longitude: 139.70372892916203,
});
multicastSticker(userIds, packageId, stickerId)
- Official Docs
Sends sticker message to multiple users.
For a list of stickers that can be sent with the Messaging API, see the sticker list.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
packageId | String |
Package ID. |
stickerId | String |
Sticker ID. |
Example:
client.multicastSticker([USER_ID], '1', '1');
multicastImagemap(userIds, altText, imagemap)
- Official Docs
Sends imagemap message to multiple users.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
altText | String |
Alternative text. |
imagemap | Object |
Object contains imagemap's parameters. |
imagemap.baseUrl | String |
Base URL of image. |
imagemap.baseSize | Object |
Base size object. |
imagemap.baseSize.width | Number |
Width of base image. |
imagemap.baseSize.height | Number |
Height of base image. |
imagemap.actions | Array<Object> |
Action when tapped. |
Example:
client.multicastImagemap([USER_ID], 'this is an imagemap', {
baseUrl: 'https://example.com/bot/images/rm001',
baseSize: {
width: 1040,
height: 1040,
},
actions: [
{
type: 'uri',
linkUri: 'https://example.com/',
area: {
x: 0,
y: 0,
width: 520,
height: 1040,
},
},
{
type: 'message',
text: 'hello',
area: {
x: 520,
y: 0,
width: 520,
height: 1040,
},
},
],
});
multicastTemplate(userIds, altText, template)
- Official Docs
Sends template message to multiple users.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
altText | String |
Alternative text. |
template | Object |
Object with the contents of the template. |
Example:
client.multicastTemplate([USER_ID], 'this is a template', {
type: 'buttons',
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
title: 'Menu',
text: 'Please select',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=123',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=123',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/123',
},
],
});
multicastButtonTemplate(userIds, altText, buttonTemplate)
- Official Docs
Sends button template message to multiple users.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
altText | String |
Alternative text. |
buttonTemplate | Object |
Object contains buttonTemplate's parameters. |
buttonTemplate.thumbnailImageUrl | String |
Image URL of buttonTemplate. |
buttonTemplate.imageAspectRatio | String |
Aspect ratio of the image. Specify one of the following values: rectangle , square |
buttonTemplate.imageSize | String |
Size of the image. Specify one of the following values: cover , contain |
buttonTemplate.imageBackgroundColor | String |
Background color of image. Specify a RGB color value. The default value is #FFFFFF (white). |
buttonTemplate.title | String |
Title of buttonTemplate. |
buttonTemplate.text | String |
Message text of buttonTemplate. |
buttonTemplate.actions | Array<Object> |
Action when tapped. |
Example:
client.multicastButtonTemplate([USER_ID], 'this is a template', {
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
title: 'Menu',
text: 'Please select',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=123',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=123',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/123',
},
],
});
multicastConfirmTemplate(userIds, altText, confirmTemplate)
- Official Docs
Sends confirm template message to multiple users.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
altText | String |
Alternative text. |
confirmTemplate | Object |
Object contains confirmTemplate's parameters. |
confirmTemplate.text | String |
Message text of confirmTemplate. |
confirmTemplate.actions | Array<Object> |
Action when tapped. |
Example:
client.multicastConfirmTemplate([USER_ID], 'this is a confirm template', {
text: 'Are you sure?',
actions: [
{
type: 'message',
label: 'Yes',
text: 'yes',
},
{
type: 'message',
label: 'No',
text: 'no',
},
],
});
multicastCarouselTemplate(userIds, altText, carouselItems, options)
- Official Docs
Sends carousel template message to multiple users.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
altText | String |
Alternative text. |
carouselItems | Array<Object> |
Array of columns which contains object for carousel. |
options | Object |
Object contains options. |
options.imageAspectRatio | String |
Aspect ratio of the image. Specify one of the following values: rectangle , square |
options.imageSize | String |
Size of the image. Specify one of the following values: cover , contain |
Example:
client.multicastCarouselTemplate([USER_ID], 'this is a carousel template', [
{
thumbnailImageUrl: 'https://example.com/bot/images/item1.jpg',
title: 'this is menu',
text: 'description',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=111',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=111',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/111',
},
],
},
{
thumbnailImageUrl: 'https://example.com/bot/images/item2.jpg',
title: 'this is menu',
text: 'description',
actions: [
{
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=222',
},
{
type: 'postback',
label: 'Add to cart',
data: 'action=add&itemid=222',
},
{
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/222',
},
],
},
]);
multicastImageCarouselTemplate(userIds, altText, carouselItems)
- Official Docs
Sends image carousel template message to multiple users.
Param | Type | Description |
---|---|---|
userIds | Array<String> |
IDs of the receivers. |
altText | String |
Alternative text. |
carouselItems | Array<Object> |
Array of columns which contains object for image carousel. |
Example:
client.multicastImageCarouselTemplate(
[USER_ID],
'this is an image carousel template',
[
{
imageUrl: 'https://example.com/bot/images/item1.jpg',
action: {
type: 'postback',
label: 'Buy',
data: 'action=buy&itemid=111',
},
},
{
imageUrl: 'https://example.com/bot/images/item2.jpg',
action: {
type: 'message',
label: 'Yes',
text: 'yes',
},
},
{
imageUrl: 'https://example.com/bot/images/item3.jpg',
action: {
type: 'uri',
label: 'View detail',
uri: 'http://example.com/page/222',
},
},
]
);
Content API - Official Docs
Retrieves image, video, and audio data sent in specified message.
Param | Type | Description |
---|---|---|
messageId | String |
Message ID. |
Example:
client.retrieveMessageContent(MESSAGE_ID).then(buffer => {
console.log(buffer);
// <Buffer 61 61 73 64 ...>
});
Profile API - Official Docs
Gets user profile information.
Param | Type | Description |
---|---|---|
userId | String |
ID of the user. |
Example:
client.getUserProfile(USER_ID).then(profile => {
console.log(profile);
// {
// displayName: 'LINE taro',
// userId: USER_ID,
// pictureUrl: 'http://obs.line-apps.com/...',
// statusMessage: 'Hello, LINE!',
// }
});
Group/Room Member Profile API - Official Docs
getGroupMemberProfile(groupId, userId)
- Official Docs
Gets the user profile of a member of a group that the bot is in. This includes the user IDs of users who has not added the bot as a friend or has blocked the bot.
Param | Type | Description |
---|---|---|
groupId | String |
ID of the group. |
userId | String |
ID of the user. |
Example:
client.getGroupMemberProfile(GROUP_ID, USER_ID).then(member => {
console.log(member);
// {
// "displayName":"LINE taro",
// "userId":"Uxxxxxxxxxxxxxx...",
// "pictureUrl":"http://obs.line-apps.com/..."
// }
});
getRoomMemberProfile(roomId, userId)
- Official Docs
Gets the user profile of a member of a room that the bot is in. This includes the user IDs of users who has not added the bot as a friend or has blocked the bot.
Param | Type | Description |
---|---|---|
roomId | String |
ID of the group. |
userId | String |
ID of the user. |
Example:
client.getRoomMemberProfile(ROOM_ID, USER_ID).then(member => {
console.log(member);
// {
// "displayName":"LINE taro",
// "userId":"Uxxxxxxxxxxxxxx...",
// "pictureUrl":"http://obs.line-apps.com/..."
// }
});
Group/Room Member IDs API - Official Docs
getGroupMemberIds(groupId, start)
- Official Docs
Gets the ID of the users of the members of a group that the bot is in. This includes the user IDs of users who have not added the bot as a friend or has blocked the bot.
This feature is only available for LINE@ Approved accounts or official accounts.
Param | Type | Description |
---|---|---|
groupId | String |
ID of the group. |
start | String |
continuationToken . |
Example:
client.getGroupMemberIds(GROUP_ID, CURSOR).then(res => {
console.log(res);
// {
// memberIds: [
// 'Uxxxxxxxxxxxxxx...',
// 'Uxxxxxxxxxxxxxx...',
// 'Uxxxxxxxxxxxxxx...'
// ],
// next: 'jxEWCEEP...'
// }
});
Recursively gets the ID of the users of the members of a group that the bot is in using cursors.
This feature is only available for LINE@ Approved accounts or official accounts.
Param | Type | Description |
---|---|---|
groupId | String |
ID of the group. |
Example:
client.getAllGroupMemberIds(GROUP_ID).then(ids => {
console.log(ids);
// [
// 'Uxxxxxxxxxxxxxx..1',
// 'Uxxxxxxxxxxxxxx..2',
// 'Uxxxxxxxxxxxxxx..3',
// 'Uxxxxxxxxxxxxxx..4',
// 'Uxxxxxxxxxxxxxx..5',
// 'Uxxxxxxxxxxxxxx..6',
// ]
});
getRoomMemberIds(roomId, start)
- Official Docs
Gets the ID of the users of the members of a room that the bot is in. This includes the user IDs of users who have not added the bot as a friend or has blocked the bot.
This feature is only available for LINE@ Approved accounts or official accounts.
Param | Type | Description |
---|---|---|
roomId | String |
ID of the room. |
start | String |
continuationToken . |
Example:
client.getRoomMemberIds(ROOM_ID, CURSOR).then(res => {
console.log(res);
// {
// memberIds: [
// 'Uxxxxxxxxxxxxxx...',
// 'Uxxxxxxxxxxxxxx...',
// 'Uxxxxxxxxxxxxxx...'
// ],
// next: 'jxEWCEEP...'
// }
});
Recursively gets the ID of the users of the members of a room that the bot is in using cursors.
This feature is only available for LINE@ Approved accounts or official accounts.
Param | Type | Description |
---|---|---|
roomId | String |
ID of the room. |
Example:
client.getAllRoomMemberIds(ROOM_ID).then(ids => {
console.log(ids);
// [
// 'Uxxxxxxxxxxxxxx..1',
// 'Uxxxxxxxxxxxxxx..2',
// 'Uxxxxxxxxxxxxxx..3',
// 'Uxxxxxxxxxxxxxx..4',
// 'Uxxxxxxxxxxxxxx..5',
// 'Uxxxxxxxxxxxxxx..6',
// ]
});
Leave API - Official Docs
leaveGroup(groupId)
- Official Docs
Leave a group.
Param | Type | Description |
---|---|---|
groupId | String |
ID of the group. |
Example:
client.leaveGroup(GROUP_ID);
leaveRoom(roomId)
- Official Docs
Leave a room.
Param | Type | Description |
---|---|---|
roomId | String |
ID of the room. |
Example:
client.leaveRoom(ROOM_ID);
Rich Menu API - Official Docs
getRichMenuList()
- Official Docs
Gets a list of all uploaded rich menus.
Example:
client.getRichMenuList().then(richMenus => {
console.log(richMenus);
// [
// {
// richMenuId: 'RICH_MENU_ID',
// size: {
// width: 2500,
// height: 1686,
// },
// selected: false,
// name: 'Nice richmenu',
// chatBarText: 'Tap here',
// areas: [
// {
// bounds: {
// x: 0,
// y: 0,
// width: 2500,
// height: 1686,
// },
// action: {
// type: 'postback',
// data: 'action=buy&itemid=123',
// },
// },
// ],
// },
// ]
});
getRichMenu(richMenuId)
- Official Docs
Gets a rich menu via a rich menu ID.
Param | Type | Description |
---|---|---|
richMenuId | String |
ID of an uploaded rich menu. |
Example:
client.getRichMenu(RICH_MENU_ID).then(richMenu => {
console.log(richMenu);
// {
// richMenuId: 'RICH_MENU_ID',
// size: {
// width: 2500,
// height: 1686,
// },
// selected: false,
// name: 'Nice richmenu',
// chatBarText: 'Tap here',
// areas: [
// {
// bounds: {
// x: 0,
// y: 0,
// width: 2500,
// height: 1686,
// },
// action: {
// type: 'postback',
// data: 'action=buy&itemid=123',
// },
// },
// ],
// }
});
createRichMenu(richMenu)
- Official Docs
Creates a rich menu.
Param | Type | Description |
---|---|---|
richMenu | RichMenu |
A rich menu object. |
Example:
client
.createRichMenu({
size: {
width: 2500,
height: 1686,
},
selected: false,
name: 'Nice richmenu',
chatBarText: 'Tap here',
areas: [
{
bounds: {
x: 0,
y: 0,
width: 2500,
height: 1686,
},
action: {
type: 'postback',
data: 'action=buy&itemid=123',
},
},
],
})
.then(richMenu => {
console.log(richMenu);
// {
// richMenuId: "{richMenuId}"
// }
});
deleteRichMenu(richMenuId)
- Official Docs
Deletes a rich menu.
Param | Type | Description |
---|---|---|
richMenuId | String |
ID of an uploaded rich menu. |
Example:
client.deleteRichMenu(RICH_MENU_ID);
getLinkedRichMenu(userId)
- Official Docs
Gets the ID of the rich menu linked to a user.
Param | Type | Description |
---|---|---|
userId | String |
ID of the user. |
Example:
client.getLinkedRichMenu(USER_ID).then(richMenu => {
console.log(richMenu);
// {
// richMenuId: "{richMenuId}"
// }
});
linkRichMenu(userId, richMenuId)
- Official Docs
Links a rich menu to a user.
Param | Type | Description |
---|---|---|
userId | String |
ID of the user. |
richMenuId | String |
ID of an uploaded rich menu. |
Example:
client.linkRichMenu(USER_ID, RICH_MENU_ID);
unlinkRichMenu(userId)
- Official Docs
Unlinks a rich menu from a user.
Param | Type | Description |
---|---|---|
userId | String |
ID of the user. |
Example:
client.unlinkRichMenu(USER_ID);
downloadRichMenuImage(richMenuId)
- Official Docs
Downloads an image associated with a rich menu.
Param | Type | Description |
---|---|---|
richMenuId | String |
ID of an uploaded rich menu. |
Example:
client.downloadRichMenuImage(RICH_MENU_ID).then(imageBuffer => {
console.log(imageBuffer);
// <Buffer 61 61 73 64 ...>
});
uploadRichMenuImage(richMenuId, buffer)
- Official Docs
Uploads and attaches an image to a rich menu.
Param | Type | Description |
---|---|---|
richMenuId | String |
ID of an uploaded rich menu. |
buffer | Buffer |
Image buffer which must be jpeg or png format. |
Example:
const fs = require('fs');
client.uploadRichMenuImage(RICH_MENU_ID, fs.readFileSync('image.png'));
To avoid sending requests to real LINE server, specify origin
option when constructing your client:
const { LineClient } = require('messaging-api-line');
const client = LineClient.connect({
accessToken: ACCESS_TOKEN,
channelSecret: CHANNEL_SECRET,
origin: 'https://mydummytestserver.com',
});
Warning: Don't do this on production server.