line-messaging
==
SDK of the LINE Messaging API for Node.js
Installation
The LINE BOT API SDK can be installed with NPM.
$ npm install line-messaging
Getting started
Require the SDK
var LINEBot = ;
Using with Express 3/4
var app = ;var bot = LINEBot;app;bot;bot;
Create the bot client instance
Instance of bot client is a handler of the Messaging API.
var bot = LINEBot
Call API
You can call API through the bot client instance.
Reply message
sample is following;
bot;
This procedure sends a message to the destination that is associated with .
More advanced sample is below;
var textMessageBuilder = 'hello';bot;
LINEBot#replyMessage() takes reply token and MessageBuilder. This method sends message that is built by MessageBuilder to the destination.
Get profile
Get detail information of user.
bot;
When LINEBot#getProfile() success return JSON object.
Response body example
"displayName":"LINE taro" "userId":"Uxxxxxxxxxxxxxx..." "pictureUrl":"http://obs.line-apps.com/..." "statusMessage":"Hello, LINE!"
Get message content
Get detail information of message content.
bot;
When LINEBot#getMessageContent() success return the content in binary.
Push message
sample is following;
bot;
This procedure sends a message to the destination that is associated with .
More advanced sample is below;
var textMessageBuilder = 'hello';bot;
Other method;
Send image message
bot;
Send audio message
bot;
Send video message
bot;
Send location message
bot;
Send sticker message
bot;
If you want detail information of sticker, please refer Sticker
Send multi message
bot;
Message builder
Type of message depends on the type of instance of MessageBuilder. That means this method sends text message if you pass TextMessageBuilder, on the other hand it sends image message if you pass ImageMessageBuilder.
The type of instance of MessageBuilder
TextMessageBuilder
var text = 'Hello' 'World!' ...;
ImageMessageBuilder
var image = 'https://example.com/original.jpg' 'https://example.com/preview.jpg';
AudioMessageBuilder
var audio = 'https://example.com/original.m4a' 240000;
VideoMessageBuilder
var video = 'https://example.com/original.mp4' 'https://example.com/preview.jpg';
LocationMessageBuilder
var location = 'my location' '〒150-0002 東京都渋谷区渋谷2丁目21−1' 3565910807942215 13970372892916203;
StickerMessageBuilder
var sticker = 1 1;
MultiMessageBuilder
var multiMessageBuilder = text image audio video;
ImagemapMessageBuilder
var imagemap = ;imagemap;imagemap;imagemap; // message/url, x, y, with, height, typeimagemap;imagemap;
TemplateMessageBuilder
- Buttons
var buttons = ;buttons;buttons;buttons; // label, data/url, typebuttons;buttons;buttons;
- Confirm
// create confirm templatevar confirm = ;confirm;confirm;confirm;
- Carousel
var column1 = ;column1 ; var column2 = ;column2 ; var column3 = ;column3 ; var carousel = column1 column2 column3;
And after create template, Your must be create instance MessageBuilder before sends;
var template = 'this is a buttons template' buttons;
Webhook
LINE's server sends user action (message, image, location and etc.) to your bot server. Request of that contains event(s); event is action of the user.
Webhook events:
- MESSAGE Event name which contains the sent message.
- FOLLOW Event name for when your account is added as a friend (or unblocked). You can reply to follow events.
- UNFOLLOW Event name for when your account is blocked.
- JOIN Event name for when your account joins a group or talk room. You can reply to join events.
- LEAVE Event name for when your account leaves a group.
- POSTBACK Event name for when a user performs an action on a template message which initiates a postback. You can reply to postback events.
- BEACON Event name for when a user detects a LINE Beacon. You can reply to beacon events.