Messaging API เป็น repo แบบโมโนที่รวบรวม API ที่จำเป็นสำหรับการพัฒนาบอท
ช่วยให้คุณสร้างบอทโดยใช้ API ที่คล้ายกันสำหรับหลายแพลตฟอร์ม เช่น Messenger, LINE เรียนรู้ครั้งเดียวและทำให้การเขียนบอทข้ามแพลตฟอร์มง่ายขึ้น
หากคุณกำลังมองหากรอบงานเพื่อสร้างบอทของคุณ Bottender อาจเหมาะกับความต้องการของคุณ มันถูกสร้างขึ้นบน Messaging 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
เพื่อเรียกใช้ Wechat 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
MIT © Yoctol