Messaging APIs は、ボット開発に必要な API を集めたモノ リポジトリです。
メッセンジャー、LINE などの複数のプラットフォームで同様の API を使用してボットを構築するのに役立ちます。一度学習すれば、クロスプラットフォーム ボットの作成が容易になります。
ボットを構築するためのフレームワークを探している場合は、Botender がニーズに合うかもしれません。これはメッセージング 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
次に、メッセンジャー API を呼び出すためのMessengerClient
を作成します。
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
次に、LINE API を呼び出すためのLineClient
を作成します。
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
次に、Slack API を呼び出すためのSlackOAuthClient
またはSlackWebhookClient
を作成します。
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
次に、Telegram API を呼び出すTelegramClient
を作成します。
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
次に、Viber API を呼び出すためのViberClient
を作成します。
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
次に、Wechat API を呼び出すためのWechatClient
を作成します。
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 ファイルに文書化されています。
MIT © ヨクトル