linebot
🤖 SDK for the LINE Messaging API for Node.js
- Come with built-in server for quick setup
- Provide convenient addon functions to event object
About LINE Messaging API
Please refer to the official API documents for details.
- Developer Documents - https://developers.line.biz/en/docs/
- API Reference - https://developers.line.biz/en/reference/messaging-api/
Installation
$ npm install linebot --save
Usage
var linebot = ; var bot = ; bot; bot;
Express.js server
Using with your ownconst app = ;const linebotParser = bot;app;app;
See examples
folder for more examples.
API
LineBot object
linebot(config)
Create LineBot instance with specified configuration.
var bot = ;
LineBot.listen(webHookPath, port, callback)
Start built-in http server on the specified port
,
and accept POST request callback on the specified webHookPath
.
This method is provided for convenience.
You can write you own server and use verify
and parse
methods to process webhook events.
See examples/echo-express-long.js
for example.
LineBot.parser()
Create Express.js middleware to parse the request.
The parser assumes that the request body has never been parsed by any body parser before,
so it must be placed BEFORE any generic body parser e.g. app.use(bodyParser.json());
LineBot.verify(rawBody, signature)
Verify X-Line-Signature
header.
LineBot.parse(body)
Process incoming webhook request, and raise an event.
LineBot.on(eventType, eventHandler)
Raised when a Webhook event is received.
bot;bot;bot;bot;bot;bot;bot;bot;bot;
LineBot.reply(replyToken, message)
Reply a message.
See: Event.reply(message)
LineBot.push(to, message)
Send push message.
to
is a userId, or an array of userId.
A userId can be saved from event.source.userId
when added as a friend (follow event), or during the chat (message event).
message
can be a string, an array of string,
a Send message object,
or an array of Send message objects.
LineBot.multicast(to, message)
Send push message to multiple users (Max: 150 users).
This is more efficient than push
as it will make api call only once.
to
is an array of userId.
message
can be a string, an array of string,
a Send message object,
or an array of Send message objects.
LineBot.broadcast(message)
Send push message to all users.
This is more efficient than push
as it will make api call only once.
message
can be a string, an array of string,
a Send message object,
or an array of Send message objects.
LineBot.getMessageContent(messageId)
Get image, video, and audio data sent by users as a Buffer object.
LineBot.getUserProfile(userId)
Get user profile information of the user.
LineBot.getGroupMemberProfile(groupId, userId)
Get user profile of a member in a group.
LineBot.getGroupMember(groupId)
Get userId of all members in a group.
LineBot.leaveGroup(groupId)
Leave a group.
LineBot.getRoomMemberProfile(roomId, userId)
Get user profile of a member in a chat room.
LineBot.getRoomMember(roomId)
Get userId of all members in a chat room.
LineBot.leaveRoom(roomId)
Leave a room.
LineBot.getTotalFollowers(date)
Get the number of users who have added this linebot on or before a specified date.
Default date is yesterday (UTC+9).
LineBot.getQuota()
Get the number of messages quota in the current month.
See: Get the target limit for additional messages
LineBot.getTotalReplyMessages(date)
LineBot.getTotalPushMessages(date)
LineBot.getTotalBroadcastMessages(date)
LineBot.getTotalMulticastMessages(date)
Get the number of messages that this linebot reply, push, broadcast, or multicast.
Default date is yesterday (UTC+9).
See: Get number of sent reply messages
Event object
Provide convenient shorthands to call LineBot's functions which require parameter from a source event object.
Event.reply(message)
Respond to the event.
message
can be a string, an array of string,
a Send message object,
or an array of Send message objects.
Return a Promise object from node-fetch
module.
This is a shorthand for: LineBot.reply(event.replyToken, message)
// reply text messageevent; // reply multiple text messagesevent; // reply message objectevent; // reply multiple message objectevent; event; event; event; event; event; event; event; event; event;
Event.source.profile()
Get user profile information of the sender.
This is a shorthand for:
LineBot.getUserProfile(event.source.userId)
if it is 1:1 chatLineBot.getGroupMemberProfile(event.source.groupId, event.source.userId)
if bot is in a groupLineBot.getRoomMemberProfile(event.source.roomId, event.source.userId)
if bot is in a chat room
eventsourceprofile;
Event.source.member()
Get userId of all members in a group or a chat room.
This is a shorthand for:
LineBot.getGroupMember(event.source.groupId)
if bot is in a groupLineBot.getRoomMember(event.source.roomId)
if bot is in a chat room
eventsource;
Event.message.content()
Get image, video, and audio data sent by users as a Buffer object.
This is a shorthand for: LineBot.getMessageContent(event.message.messageId)
eventmessagecontent;