Messaging API 是一個單一儲存庫,收集機器人開發所需的 API。
它可以幫助您使用類似的 API 為多個平台(例如 Messenger、LINE)建立機器人。學習一次,讓編寫跨平台機器人變得更容易。
如果您正在尋找建立機器人的框架,Bottender 可能適合您的需求。它構建在訊息 API 之上,並為機器人構建提供了一些強大的功能。
包裹 | 版本 | 平台 |
---|---|---|
messaging-api-messenger | 信差 | |
messaging-api-line | 線 | |
messaging-api-slack | 鬆弛 | |
messaging-api-telegram | 電報 | |
messaging-api-viber | 維伯 | |
messaging-api-wechat | 微信 |
從註冊表安裝messaging-api-messenger
套件:
npm i --save messaging-api-messenger
或者
yarn add messaging-api-messenger
然後,建立一個MessengerClient
來呼叫 Messenger API:
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' ) ;
} ) ;
查看完整的 API 文件以獲取更多詳細資訊。
從註冊表安裝messaging-api-line
包:
npm i --save messaging-api-line
或者
yarn add messaging-api-line
然後,建立一個LineClient
來呼叫 LINE API:
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' ) ;
} ) ;
查看完整的 API 文件以獲取更多詳細資訊。
從註冊表安裝messaging-api-slack
包:
npm i --save messaging-api-slack
或者
yarn add messaging-api-slack
然後,建立SlackOAuthClient
或SlackWebhookClient
來呼叫 Slack API:
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' ) ;
} ) ;
查看完整的 API 文件以獲取更多詳細資訊。
從註冊表安裝messaging-api-telegram
套件:
npm i --save messaging-api-telegram
或者
yarn add messaging-api-telegram
然後,建立一個TelegramClient
來呼叫 Telegram API:
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' ) ;
} ) ;
查看完整的 API 文件以獲取更多詳細資訊。
從註冊表安裝messaging-api-viber
套件:
npm i --save messaging-api-viber
或者
yarn add messaging-api-viber
然後,建立一個ViberClient
來呼叫 Viber API:
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' ) ;
} ) ;
查看完整的 API 文件以獲取更多詳細資訊。
從註冊表安裝messaging-api-wechat
包:
npm i --save messaging-api-wechat
或者
yarn add messaging-api-wechat
然後,建立一個WechatClient
來呼叫微信API:
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' ) ;
} ) ;
查看完整的 API 文件以獲取更多詳細資訊。
每個版本以及遷移說明都記錄在 CHANGELOG.md 檔案中。
麻省理工學院 © Yoctol