All Projects → boybundit → Linebot

boybundit / Linebot

Licence: mit
🤖 SDK for the LINE Messaging API for Node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Linebot

Bottender
⚡️ A framework for building conversational user interfaces.
Stars: ✭ 3,803 (+1966.85%)
Mutual labels:  chatbot, messaging, line
Messaging Apis
Messaging APIs for multi-platform
Stars: ✭ 1,754 (+853.26%)
Mutual labels:  chatbot, messaging, line
Integrations
Connect your App to Multiple Messaging Channels with the W3C Open standard.
Stars: ✭ 721 (+291.85%)
Mutual labels:  chatbot, messaging, line
messaging-apis
Messaging APIs for multi-platform
Stars: ✭ 1,759 (+855.98%)
Mutual labels:  line, messaging, chatbot
Notify
A dead simple Go library for sending notifications to various messaging services.
Stars: ✭ 727 (+295.11%)
Mutual labels:  hacktoberfest, messaging, line
Claudia Bot Builder
Create chat bots for Facebook Messenger, Slack, Amazon Alexa, Skype, Telegram, Viber, Line, GroupMe, Kik and Twilio and deploy to AWS Lambda in minutes
Stars: ✭ 1,717 (+833.15%)
Mutual labels:  chatbot, line
Bandcamp Scraper
A scraper for https://bandcamp.com
Stars: ✭ 137 (-25.54%)
Mutual labels:  api, hacktoberfest
Mojo Webqq
【重要通知:WebQQ将在2019年1月1日停止服务,此项目目前已停止维护,感谢大家四年来的一路陪伴】使用Perl语言(不会没关系)编写的smartqq/webqq客户端框架(非GUI),可通过插件提供基于HTTP协议的api接口供其他语言或系统调用
Stars: ✭ 1,755 (+853.8%)
Mutual labels:  api, chatbot
Brain.js
brain.js is a GPU accelerated library for Neural Networks written in JavaScript.
Stars: ✭ 12,358 (+6616.3%)
Mutual labels:  api, hacktoberfest
Water Monitoring System
Water Monitoring System is an IOT based Liquid Level Monitoring system that has mechanisms to keep the user alerted in case of liquid overflow or when tank depletes.
Stars: ✭ 122 (-33.7%)
Mutual labels:  api, hacktoberfest
Core
The server component of API Platform: hypermedia and GraphQL APIs in minutes
Stars: ✭ 2,004 (+989.13%)
Mutual labels:  api, hacktoberfest
Sampleapis
This repository is a playground for API's. These are just a collection of items that you can utilize for learning purposes.
Stars: ✭ 157 (-14.67%)
Mutual labels:  api, hacktoberfest
Mailcare
[MIRRORING REPOSITORY] See https://gitlab.com/mailcare/mailcare. MailCare is an open source disposable email address services. Accessible via web browser or API to protect your privacy right now.
Stars: ✭ 136 (-26.09%)
Mutual labels:  api, hacktoberfest
Smoke
💨 Simple yet powerful file-based mock server with recording abilities
Stars: ✭ 142 (-22.83%)
Mutual labels:  api, hacktoberfest
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-34.24%)
Mutual labels:  api, hacktoberfest
Emberclear
Encrypted Chat. No History. No Logs.
Stars: ✭ 157 (-14.67%)
Mutual labels:  hacktoberfest, messaging
Blinkpy
A Python library for the Blink Camera system
Stars: ✭ 174 (-5.43%)
Mutual labels:  api, hacktoberfest
Stream Chat Android
Stream Chat official Android SDK. The tutorial covers how to build your own chat experience using either Java or Kotlin.
Stars: ✭ 165 (-10.33%)
Mutual labels:  hacktoberfest, messaging
Rails api base
API boilerplate project for Ruby On Rails 6
Stars: ✭ 172 (-6.52%)
Mutual labels:  api, hacktoberfest
Shoutrrr
Notification library for gophers and their furry friends.
Stars: ✭ 177 (-3.8%)
Mutual labels:  hacktoberfest, messaging

linebot

NPM Version NPM Downloads NPM Dependencies Build

🤖 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.

Installation

$ npm install linebot --save

Usage

var linebot = require('linebot');

var bot = linebot({
  channelId: CHANNEL_ID,
  channelSecret: CHANNEL_SECRET,
  channelAccessToken: CHANNEL_ACCESS_TOKEN
});

bot.on('message', function (event) {
  event.reply(event.message.text).then(function (data) {
    // success
  }).catch(function (error) {
    // error
  });
});

bot.listen('/linewebhook', 3000);

Using with your own Express.js server

const app = express();
const linebotParser = bot.parser();
app.post('/linewebhook', linebotParser);
app.listen(3000);

See examples folder for more examples.

API

LineBot object

linebot(config)

Create LineBot instance with specified configuration.

var bot = linebot({
  channelId: CHANNEL_ID,
  channelSecret: CHANNEL_SECRET,
  channelAccessToken: CHANNEL_ACCESS_TOKEN,
  verify: true // Verify 'X-Line-Signature' header (default=true)
});

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.on('message',      function (event) { });
bot.on('follow',       function (event) { });
bot.on('unfollow',     function (event) { });
bot.on('join',         function (event) { });
bot.on('leave',        function (event) { });
bot.on('memberJoined', function (event) { });
bot.on('memberLeft',   function (event) { });
bot.on('postback',     function (event) { });
bot.on('beacon',       function (event) { });

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.

See: Event.message.content()

LineBot.getUserProfile(userId)

Get user profile information of the user.

See: Event.source.profile()

LineBot.getGroupMemberProfile(groupId, userId)

Get user profile of a member in a group.

LineBot.getGroupMember(groupId)

Get userId of all members in a group.

See: Event.source.member()

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.

See: Event.source.member()

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).

See: Get number of followers

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 message
event.reply('Hello, world').then(function (data) {
  // success
}).catch(function (error) {
  // error
});

// reply multiple text messages
event.reply(['Hello, world 1', 'Hello, world 2']);

// reply message object
event.reply({ type: 'text', text: 'Hello, world' });

// reply multiple message object
event.reply([
  { type: 'text', text: 'Hello, world 1' },
  { type: 'text', text: 'Hello, world 2' }
]);

event.reply({
  type: 'image',
  originalContentUrl: 'https://example.com/original.jpg',
  previewImageUrl: 'https://example.com/preview.jpg'
});

event.reply({
  type: 'video',
  originalContentUrl: 'https://example.com/original.mp4',
  previewImageUrl: 'https://example.com/preview.jpg'
});

event.reply({
  type: 'audio',
  originalContentUrl: 'https://example.com/original.m4a',
  duration: 240000
});

event.reply({
  type: 'location',
  title: 'my location',
  address: '〒150-0002 東京都渋谷区渋谷2丁目21−1',
  latitude: 35.65910807942215,
  longitude: 139.70372892916203
});

event.reply({
  type: 'sticker',
  packageId: '1',
  stickerId: '1'
});

event.reply({
  type: 'imagemap',
  baseUrl: 'https://example.com/bot/images/rm001',
  altText: 'this is an imagemap',
  baseSize: { height: 1040, width: 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 }
  }]
});

event.reply({
  type: 'template',
  altText: 'this is a buttons template',
  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'
    }]
  }
});

event.reply({
  type: 'template',
  altText: 'this is a confirm template',
  template: {
    type: 'confirm',
    text: 'Are you sure?',
    actions: [{
      type: 'message',
      label: 'Yes',
      text: 'yes'
    }, {
      type: 'message',
      label: 'No',
      text: 'no'
    }]
  }
});

event.reply({
  type: 'template',
  altText: 'this is a carousel template',
  template: {
    type: 'carousel',
    columns: [{
      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'
      }]
    }]
  }
});

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 chat
  • LineBot.getGroupMemberProfile(event.source.groupId, event.source.userId) if bot is in a group
  • LineBot.getRoomMemberProfile(event.source.roomId, event.source.userId) if bot is in a chat room
event.source.profile().then(function (profile) {
  event.reply('Hello ' + profile.displayName);
});

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 group
  • LineBot.getRoomMember(event.source.roomId) if bot is in a chat room
event.source.member().then(function (member) {
  console.log(member.memberIds);
});

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)

event.message.content().then(function (content) {
  console.log(content.toString('base64'));
});

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].