All Projects → mathdroid → Node Line Messaging Api

mathdroid / Node Line Messaging Api

Licence: mit
Unofficial SDK for LINE Messaging API 🤖 💬

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Line Messaging Api

Node Telegram Bot Api
Telegram Bot API for NodeJS
Stars: ✭ 5,782 (+14002.44%)
Mutual labels:  bot, bot-framework
Line Bot Sdk Go
LINE Messaging API SDK for Go
Stars: ✭ 654 (+1495.12%)
Mutual labels:  bot, line
Line Bot Sdk Php
LINE Messaging API SDK for PHP
Stars: ✭ 601 (+1365.85%)
Mutual labels:  bot, line
Stealth
An open source Ruby framework for text and voice chatbots. 🤖
Stars: ✭ 481 (+1073.17%)
Mutual labels:  bot, bot-framework
Botframework Sdk
Bot Framework provides the most comprehensive experience for building conversation applications.
Stars: ✭ 6,673 (+16175.61%)
Mutual labels:  bot, bot-framework
Line Bot Sdk Java
LINE Messaging API SDK for Java
Stars: ✭ 484 (+1080.49%)
Mutual labels:  bot, line
Botbuilder Dotnet
Welcome to the Bot Framework SDK for .NET repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using .NET.
Stars: ✭ 631 (+1439.02%)
Mutual labels:  bot, bot-framework
Line Bot Sdk Ruby
LINE Messaging API SDK for Ruby
Stars: ✭ 425 (+936.59%)
Mutual labels:  bot, line
Notify
A dead simple Go library for sending notifications to various messaging services.
Stars: ✭ 727 (+1673.17%)
Mutual labels:  bot, line
Integrations
Connect your App to Multiple Messaging Channels with the W3C Open standard.
Stars: ✭ 721 (+1658.54%)
Mutual labels:  bot, line
Telegraf
Modern Telegram Bot Framework for Node.js
Stars: ✭ 5,178 (+12529.27%)
Mutual labels:  bot, bot-framework
Botframework Solutions
Welcome to the Bot Framework Solutions repository which is the home for a set of templates and solutions to help build advanced conversational experiences using Azure Bot Service and Bot Framework. Microsoft Bot Framework is a comprehensive framework for building enterprise-grade conversational AI experiences.
Stars: ✭ 965 (+2253.66%)
Mutual labels:  bot, bot-framework
Botbuilder Js
Welcome to the Bot Framework SDK for JavaScript repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using JavaScript.
Stars: ✭ 469 (+1043.9%)
Mutual labels:  bot, bot-framework
Slacker
Slack Bot Framework
Stars: ✭ 495 (+1107.32%)
Mutual labels:  bot, bot-framework
Botbuilder Python
The Microsoft Bot Framework provides what you need to build and connect intelligent bots that interact naturally wherever your users are talking, from text/sms to Skype, Slack, Office 365 mail and other popular services.
Stars: ✭ 457 (+1014.63%)
Mutual labels:  bot, bot-framework
Botman
A framework agnostic PHP library to build chat bots
Stars: ✭ 5,538 (+13407.32%)
Mutual labels:  bot, bot-framework
Botbuilder Tools
Welcome to the Bot Framework Tools repository, which is the home for a set of tools for developers building bots with the Microsoft Bot Framework
Stars: ✭ 402 (+880.49%)
Mutual labels:  bot, bot-framework
Poshbot
Powershell-based bot framework
Stars: ✭ 410 (+900%)
Mutual labels:  bot, bot-framework
Line Bot Sdk Nodejs
LINE Messaging API SDK for Node.js
Stars: ✭ 683 (+1565.85%)
Mutual labels:  bot, line
Lita Line
A Line adapter for Lita
Stars: ✭ 15 (-63.41%)
Mutual labels:  bot, line

node-line-messaging-api

Unofficial SDK for Line's Messaging API

npm install --save node-line-messaging-api

Usage

Example live bot (proofreader-dog)

const LineBot = require('node-line-messaging-api')
const {secret, token} = require('../config')
const {lint} = require('./api')

const Messages = LineBot.Messages
const PORT = process.env.PORT || 5050

const dog = new LineBot({
    secret,
    token,
    options: {
        port: PORT,
        tunnel: false,
        verifySignature: true,
        endpoint: '/'
    }
})

dog.on('webhook', ({port, endpoint}) => {
    console.log(`dog is online on http://localhost:${port}${endpoint}`)
})

dog.on('tunnel', ({url}) => {
    console.log(`tunnel to local machine created at ${url}`)
})

dog.on('text', async event => {
    try {
        const {displayName} = await dog.getProfileFromEvent(event)
        const {replyToken, message: {text}} = event
        const {suggestions, typos} = await lint(text)
        const replyText = `Woof! Hi ${displayName}!\n\nI've read your message:\n\n${text}`
        const replyBalloon = new Messages().addText(replyText)
        const reasons = suggestions.length && suggestions.map(({reason}) => reason).join('\n\n')
        if (reasons) replyBalloon.addSticker({packageId: 1, stickerId: 15}).addText(`My dog-sense 🐕 has some suggestions:\n\n${reasons}`)
        const words = typos.length && typos.map(({word, suggestions}) => `Error on word "${word}". Did you mean ${suggestions.join('/')}?`).join('\n\n')
        if (words) replyBalloon.addSticker({packageId: 1, stickerId: 10}).addText(`🤔🔥 A bit of typographical errors:\n\n${words}`)
        if (!reasons && !words) replyBalloon.addSticker({packageId: 1, stickerId: 14}).addText('Woof woof! I can\'t find any errors! 🐶 Nice job!')
        dog.replyMessage(replyToken, replyBalloon.commit())
    } catch ({message}) {
        console.log(message)
    }
})

Events

Listen-able events:

webhook

Emitted when webhook listener is created successfully. Emits {port, endpoint}.

tunnel

Emitted when local tunnel is created successfully for development. Emits {url}.

events

Emitted on all events, returns an array of events.

event

Emitted on all events, returns an array of events.

message, follow, unfollow, join, leave, postback, beacon

Emitted on parsing event types, returns that specific event.

text, image, video, audio, location, sticker, non-text, message-with-content

Emitted on parsing message types (more specific), returns that specific event. Can be made more specific according to source type. For example, Bot.on('image:user', fn) will run fn only if it receives an image message type from user source type (won't work in groups/rooms).

Webhook

By default, webhook will listen on port 5463. You should change it if it interferes with something.

Messages

Messages class is a helper in composing your messages.

API

LineBot

  • LineBot

    • new LineBot({secret, token, options})

    • .on(event, function callback (eventContent) {}) // Standard event listener. Events are shown above.

    • .onText(regexp, function callback (event, match) {}) // Executes callback everytime a message.text matches regexp

    • .multicast(channels, messages) => Promise

    • .replyMessage(replyToken, messages) => Promise

    • .pushMessage(channel, messages) => Promise

    • .getContent(messageId) => Promise

    • .getProfile(userId) => Promise

    • .getContentFromEvent(event) => Promise

    • .getProfileFromEvent(event) => Promise

    • .leaveChannel({groupId, roomId}) => Promise //pick one between groupId or roomId

  • Messages

    • new Messages() // creates an empty array of messages. Maximum 5 messages following LINE's spec.

    • .addRaw(message) // message Object following LINE's spec

    • .addText(message) // message may be a string or an object with .text property. Chainable.

    • .addImage({originalUrl, previewUrl}) // originalUrl and previewUrl must be a HTTPS link to a JPG or PNG image. (size < 1MB, width < 1024px)

    • .addAudio({originalUrl, duration}) // originalUrl must be a HTTPS link to m4a audio. duration is in milliseconds.

    • .addVideo({originalUrl, previewUrl}) // same as .addImage but mp4 < 10MB for the originalUrl.

    • .addLocation({title = 'My Location', address = 'Here\'s the location.', latitude, longitude}) // lat and lon is of number type

    • .addSticker({packageId, stickerId}) // both params are of number type. see https://devdocs.line.me/files/sticker_list.pdf

    • .addButtons({thumbnailImageUrl, altText, title, text, actions}) // Buttons template message. actions is an array of action objects. length of actions <=4

    • .addConfirm({altText, text, actions}) // confirmation type. actions max length = 2

    • .addCarousel({altText, columns}) // where columns is an array of column object. Column object is in the shape of {thumbnailImageUrl, title, text, actions}. actions is an array of action objects.

    • .addVideo, etc (WIP)

    • .commit() // returns the payload (array of messages)

Installation

npm install --save node-line-messaging-api

or

yarn add node-line-messaging-api

Deployment

  1. Prepare your cloud host, note IP Address.

  2. Provide HTTPS support for the webhook endpoint.

  3. Register for an account in business.line.me, choose Messaging API and then dev-trial.

  4. Open developers.line.me for your account, note the APP_SECRET.

  5. Issue a TOKEN and note it.

  6. Go to server whitelist, add your IP Address.

  7. Create your bot, input your APP_SECRET and TOKEN.

  8. Deploy to your cloud host, and wait for events to come in!

Contributing

PRs welcome. Open Issues first. ;)

License

The MIT License (MIT)

Copyright © 2016 Muhammad Mustadi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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