Home

Awesome

Messaging APIs

Build Status coverage License: MIT

Messaging APIs is a mono repo which collects APIs needed for bot development.

It helps you build your bots using similar API for multiple platforms, e.g. Messenger, LINE. Learn once and make writing cross-platform bots easier.

If you are looking for a framework to build your bots, Bottender may suit for your needs. It is built on top of Messaging APIs and provides some powerful features for bot building.

Packages

PackageVersionPlatform
messaging-api-messengernpmMessenger
messaging-api-linenpmLINE
messaging-api-slacknpmSlack
messaging-api-telegramnpmTelegram
messaging-api-vibernpmViber
messaging-api-wechatnpmWeChat

Usage

Messenger

<img src="https://static.xx.fbcdn.net/rsrc.php/yg/r/4_vfHVmZ5XD.ico" alt="Messenger" width="100" />

Install messaging-api-messenger package from the registry:

npm i --save messaging-api-messenger

or

yarn add messaging-api-messenger

Then, create a MessengerClient to call Messenger APIs:

const { MessengerClient } = require('messaging-api-messenger');

// get accessToken from facebook developers website
const client = new MessengerClient({
  accessToken: 'ACCESS_TOKEN',
});

client.sendText(userId, 'Hello World').then(() => {
  console.log('sent');
});

Check out full API documentation for more detail information.

LINE

<img src="http://is5.mzstatic.com/image/thumb/Purple117/v4/01/c2/4d/01c24d99-4aae-71ea-24e2-d0b68f8c53d2/source/1200x630bb.jpg" alt="LINE" width="100" />

Install messaging-api-line package from the registry:

npm i --save messaging-api-line

or

yarn add messaging-api-line

Then, create a LineClient to call LINE APIs:

const { LineClient } = require('messaging-api-line');

// get accessToken and channelSecret from LINE developers website
const client = new LineClient({
  accessToken: 'ACCESS_TOKEN',
  channelSecret: 'CHANNEL_SECRET',
});

client.pushText(userId, 'Hello World').then(() => {
  console.log('pushed');
});

Check out full API documentation for more detail information.

Slack

<img src="https://cdn-images-1.medium.com/max/1200/1*TiKyhAN2gx4PpbOsiBhYcw.png" alt="Slack" width="100" />

Install messaging-api-slack package from the registry:

npm i --save messaging-api-slack

or

yarn add messaging-api-slack

Then, create a SlackOAuthClient or SlackWebhookClient to call Slack APIs:

const { SlackOAuthClient } = require('messaging-api-slack');

// get access token by setup OAuth & Permissions function to your app.
// https://api.slack.com/docs/oauth
const client = new SlackOAuthClient({
  accessToken: 'xoxb-000000000000-xxxxxxxxxxxxxxxxxxxxxxxx',
});

client.postMessage('#random', 'Hello World').then(() => {
  console.log('sent');
});
const { SlackWebhookClient } = require('messaging-api-slack');

// get webhook URL by adding a Incoming Webhook integration to your team.
// https://my.slack.com/services/new/incoming-webhook/
const client = new SlackWebhookClient({
  url: 'https://hooks.slack.com/services/XXXXXXXX/YYYYYYYY/zzzzzZZZZZ',
});

client.sendText('Hello World').then(() => {
  console.log('sent');
});

Check out full API documentation for more detail information.

Telegram

<img src="https://telegram.org/img/t_logo.png" alt="Telegram" width="100" />

Install messaging-api-telegram package from the registry:

npm i --save messaging-api-telegram

or

yarn add messaging-api-telegram

Then, create a TelegramClient to call Telegram APIs:

const { TelegramClient } = require('messaging-api-telegram');

// get accessToken from telegram [@BotFather](https://telegram.me/BotFather)
const client = new TelegramClient({
  accessToken: '12345678:AaBbCcDdwhatever',
});

client.sendMessage(chatId, 'Hello World').then(() => {
  console.log('sent');
});

Check out full API documentation for more detail information.

Viber

<img src="https://user-images.githubusercontent.com/3382565/31753411-0be75dfc-b456-11e7-9eea-b976d21fcc53.png" alt="Viber" width="100" />

Install messaging-api-viber package from the registry:

npm i --save messaging-api-viber

or

yarn add messaging-api-viber

Then, create a ViberClient to call Viber APIs:

const { ViberClient } = require('messaging-api-viber');

// get authToken from the "edit info" screen of your Public Account.
const client = new ViberClient({
  accessToken: 'AUTH_TOKEN',
  sender: {
    name: 'Sender',
  },
});

client.sendText(userId, 'Hello World').then(() => {
  console.log('sent');
});

Check out full API documentation for more detail information.

WeChat

<img src="https://user-images.githubusercontent.com/3382565/33652361-1dc854c6-daa4-11e7-997e-e1dedd818881.jpg" alt="WeChat" width="100" />

Install messaging-api-wechat package from the registry:

npm i --save messaging-api-wechat

or

yarn add messaging-api-wechat

Then, create a WechatClient to call Wechat APIs:

const { WechatClient } = require('messaging-api-wechat');

// get appId, appSecret from「微信公众平台-开发-基本配置」page
const client = new WechatClient({
  appId: 'APP_ID',
  appSecret: 'APP_SECRET',
});

client.sendText(userId, 'Hello World').then(() => {
  console.log('sent');
});

Check out full API documentation for more detail information.

Documentation

Change Log

Every release, along with the migration instructions, is documented on the CHANGELOG.md file.

License

MIT © Yoctol