Messaging API client for LINE
npm i --save messaging-api-line
or
yarn add messaging-api-line
import { LINEClient } from 'messaging-api-line';
// get accessToken and channelSecret from LINE developers website
const client = LINEClient.connect(accessToken, channelSecret);
async function() {
await client.pushText(id, text);
}
or
client.pushText(id, text).then(() => {
// do something
});
All methods return a Promise.
client.reply('1qwyg56uj', [
{
type: 'text',
text: 'Hello!',
},
]);
client.reply('1qwyg56uj', 'Hello!');
client.replyImage(
'1qwyg56uj',
'https://example.com/original.jpg',
'https://example.com/preview.jpg'
);
client.replyVideo(
'1qwyg56uj',
'https://example.com/original.mp4',
'https://example.com/preview.jpg'
);
client.replyAudio('1qwyg56uj', 'https://example.com/original.m4a', 240000);
client.replyLocation('1qwyg56uj', {
title: 'my location',
address: '〒150-0002 東京都渋谷区渋谷2丁目21−1',
latitude: 35.65910807942215,
longitude: 139.70372892916203,
});
client.replySticker('1qwyg56uj', '1', '1');
client.replyImagemap(
'1qwyg56uj',
'this is an imagemap',
{
baseUrl: 'https://example.com/bot/images/rm001',
baseHeight: 1040,
baseWidth: 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,
},
},
],
}
);
client.replyTemplate(
'1qwyg56uj',
'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',
},
],
}
);
client.replyButtonTemplate(
'1qwyg56uj',
'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',
},
],
}
);
client.replyConfirmTemplate(
'1qwyg56uj',
'this is a confirm template',
{
text: 'Are you sure?',
actions: [
{
type: 'message',
label: 'Yes',
text: 'yes',
},
{
type: 'message',
label: 'No',
text: 'no',
},
],
}
);
client.replyCarouselTemplate(
'1qwyg56uj',
'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',
},
],
},
]
);
client.push('1', [
{
type: 'text',
text: 'Hello!',
},
]);
client.pushText('1', 'Hello!');
client.pushImage(
'1',
'https://example.com/original.jpg',
'https://example.com/preview.jpg'
);
client.pushVideo(
'1',
'https://example.com/original.mp4',
'https://example.com/preview.jpg'
);
client.pushAudio('1', 'https://example.com/original.m4a', 240000);
client.pushLocation('1', {
title: 'my location',
address: '〒150-0002 東京都渋谷区渋谷2丁目21−1',
latitude: 35.65910807942215,
longitude: 139.70372892916203,
});
client.pushSticker('1', '1', '1');
client.pushImagemap(
'1',
'this is an imagemap',
{
baseUrl: 'https://example.com/bot/images/rm001',
baseHeight: 1040,
baseWidth: 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,
},
},
],
}
);
client.pushTemplate(
'1',
'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',
},
],
}
);
client.pushButtonTemplate(
'1',
'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',
},
],
}
);
client.pushConfirmTemplate(
'1',
'this is a confirm template',
{
text: 'Are you sure?',
actions: [
{
type: 'message',
label: 'Yes',
text: 'yes',
},
{
type: 'message',
label: 'No',
text: 'no',
},
],
}
);
client.pushCarouselTemplate(
'1',
'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',
},
],
},
]
);
client.multicast(['1'], [
{
type: 'text',
text: 'Hello!',
},
]);
client.multicastText(['1'], 'Hello!');