This package helps you to build Line Messenger API easier and faster. This packages supports Node.JS version 8 or higher.
This package created by Yudha Pratama If you found bugs or errors, you can report at Github Issue or send a direct message to my twitter.
If you like this project, please support us to give a Coffee
npm i line-messenger-api
const Line = require('line-messenger-api').connect({
client_id: 'your client id',
client_secret: 'your client secret'
});
You can get a channel access token that is valid for 30 days. To get a long-lived a channel access token, use the "Issue" button found on your console.
Line
.getAccessToken()
.then((results))
.catch()
The return looks like this:
{
"access_token":"W1TeHCgfH2Liwa.....",
"expires_in":2592000,
"token_type":"Bearer"
}
Revokes a channel access token.
Line
.revokeAccessToken(accessToken)
.then()
.catch()
Sends a reply message in response to an event from a user, group, or room.
To send reply messages, you must have a reply token. You can get a reply token from Webhook events.
Line
.replyMessage(accessToken, replyToken, (message) => {
message.text('Hello!');
})
.then()
.catch();
Sends a push message to a user, goup, or room at any time.
To send a push message you should use the user id, group id, or room id.
Line
.sendPushMessage(accessToken, (message) => {
message.to('user id');
message.text('Hello!');
})
.then()
.catch();
Sends push messages to multiple users at any time. Messages cannot be sent to groups or rooms.
Line
.sendMulticastMessage(accessToken, (message) => {
message.to(['userid 1', 'userid 2']);
message.text('Hello!');
})
.then()
.catch();
Sends push messages to multiple users at any time.
Line
.broadcastMessage(accessToken, (message) => {
message.text('Hello!');
})
.then()
.catch();
To send a message, you have several choices according to the content. You can send a text message, sticker, image, video, audio, location, image map, or button quick reply.
This is the available message objects
message.text('Your text message');
To send a sticker, you must have a package id and sticker id. You can see the sticker list in this link https://developers.line.biz/media/messaging-api/sticker_list.pdf
message.sticker('sticker package id', 'sticker id');
To send an image message, you should use a preview image with a smaller resolution rather than an original image.
Line Messenger requires an https URL link to send an image, video or audio.
message.image('preview image url', 'original image url');
To send a video message, you should use a preview image.
Line Messenger requires an https URL link to send an image, video or audio.
message.video('preview image url', 'video url');
To send an audio message, you should use the audio duration in a millisecond.
Line Messenger requires an https URL link to send an image, video or audio.
message.audio('audio url', 60000);
To send a location message, you should use 4 arguments like description, address, latitude, and longitude in float type.
message.location('description', 'address', latitude, longitude);
Imagemap messages are messages configured with an image that has multiple tappable areas.
To send an imagemap message you should use image URL and alternate text.
For more information about the specification of images supported by imagemap messages, see How to configure an image.
message.imageMap('image url', 'alternate text', (imageMap) => {
imageMap.video('video url', 'preview image url', width, height, x_position, y_position);
});
The imagemap message has a quick action on tappable areas. You can check the available action object below:
imageMap.video('video url', 'preview image url', width, height, x_position, y_position);
imageMap.externalLink('URL link', 'label text');
imageMap.actionUri('URL link', width, height, x_position, y_position);
imageMap.actionMessage('label', 'text message', width, height, x_position, y_position);
If you want to send a quick reply button messages, you can use this method.
message.quickReply('Your text message', (reply) => {
reply.text('label', 'text message');
});
You can set up to 13 quick reply buttons to a message of any type.
You can see the action message of a quick reply in this below:
reply.postback('label', 'text message', 'url postback event');
reply.text('label', 'text message');
If you want to send a DateTime picker action, you should use initial date time, minimal date time, maximal date time, and mode.
You can use mode date
, time
, or datetime
.
For the initial date time, minimal, and maximal date time you can see the format in this link https://developers.line.biz/en/reference/messaging-api/#datetime-picker-action
reply.dateTimePicker('label', 'url postback event', initial_datetime, max_datetime, min_datetime, mode);
reply.camera('label');
reply.cameraRoll('label');
reply.location('label');
If you want to send messages without notification, you can use notificationDisabled method
message.notificationDisabled();
If you want to get an image, video, and audio data sent by users. You can use this method with message id from messages event.
Line
.getContentMessage(accessToken, messageId)
.then((results))
.catch()
If you want to get the target limit for additional messages in the current month.
Line
.getTargetLimit(accessToken)
.then((results))
.catch()
Gets the number of messages sent in the current month.
Line
.getQuotaMessage(accessToken)
.then((results))
.catch()
Gets the number of reply messages sent by the date messages was sent.
Line
.getReplyMessageConsumption(accessToken)
.then((results))
.catch()
Gets the number of push messages sent by the date messages was sent.
Line
.getPushMessageConsumption(accessToken)
.then((results))
.catch()
Gets the number of multicast messages sent by the date messages was sent.
Line
.getMulticastMessageConsumption(accessToken)
.then((results))
.catch()
Gets the number of broadcast messages sent by the date messages was sent.
Line
.getBroadcastMessageConsumption(accessToken)
.then((results))
.catch()
To create a rich menu you must upload a rich menu image after the rich menu was created. You can create up to 1000 rich menus for one LINE official account with the Messaging API.
Line
.createRichMenu(accessToken, (menu) => {
menu.sizeMenu();
menu.selectedMenu();
menu.nameMenu('Rich menu');
menu.chatbar('Tap to open');
menu.area(0, 0, 385, 372, (tap) => {
tap.text('Test 1', 'Test 1');
});
})
.then((results))
.catch()
The createRichMenu method has many objects. You can see this below:
You can use rich menu images with the followong specifications:
- Image ormatL JPEG or PNG
- Image size 2500x1686 or 2500x843 pixels. 2500x843 is set by default.
- Maximum file size: 1MB
menu.sizeMenu(width, height);
To display the rich menu by default.
menu.selectedMenu();
This name value can be used to help manage your rich menus and is not displayed to users.
menu.nameMenu('Write name here');
This chatbar text will be displayed to users. You can set the value like Tap to open or whatever.
menu.chatbar('Tap to open');
The area is a tappable image which define the coordinates and size.
You can see this link for more information about rich meny tappable area images.
menu.area(x_coordinate, y_coordinate, width, height, (tap) => {
tap.text('Test 1', 'Test 1');
});
The area method used message object callback. You can see the message objects on message objects.
After the rich menu was created you will receive rich menu id.
Uploads and attaches an image to a rich menu.
You can use rich menu images with the followong specifications:
- Image ormatL JPEG or PNG
- Image size 2500x1686 or 2500x843 pixels. 2500x843 is set by default.
- Maximum file size: 1MB
Line
.uploadRichMenuImage(accessToken, richMenuId, imagePath)
.then()
.catch()
Gets a list of all rich menus created by Create rich menu.
Line
.getRichMenuList(accessToken)
.then((results))
.catch()
Gets a specific rich menu by rich menu id.
Line
.getRichMenu(accessToken, richMenuId)
.then((results))
.catch()
Sets the default rich menu. The default rich menu is displayed to all users who have added your LINE official account as a friend and are not linked to any per-user rich menu.
Line
.setDefaultRichMeny(accessToken, richMenuId)
.then()
.catch()
Cancels the default rich menu.
Line
.cancelDefaultRichMenu(accessToken)
.then()
.catch()
Gets an active rich menu from a specific user.
Line
.getRichMenuUser(accessToken, userId)
.then((results))
.catch()
Links a rich menu to a user. Only one rich menu can be linked to a user at one time.
Line
.linkRichMenuToUser(accessToken, userId, richMenuId)
.then()
.catch()
Unlinks a rich menu from specific user.
Line
.unlinkRichMenuFromUser(accessToken, userId)
.then()
.catch()
Links a rich menu to many users at one time. Only one rich menu can be linked to a user at one time.
Line
.linkRichMenuToMultipleUser(accessToken, [userId1, userId2], richMenuId)
.then()
.catch()
Unlinks a rich meny from many users.
Line
.unlinkRichMenuFromMultipleUser(accessToken, userId)
.then()
.catch()
Deletes a rich menu.
Line
.deleteRichMenu(accessToken, richMenuId)
.then()
.catch()
Gets user profile information.
Line
.getUserProfile(accessToken, userId)
.then((results))
.catch()
Issues a link token used for the account link feature.
Line
.getAccountLinkToken(accessToken, userId)
.then((results))
.catch()