0.3.0 • Published 6 years ago
botdown v0.3.0
botdown
The project's purpose let bot can reply message to any platform by Markdown format. So user can write code once, send to any where.
Usage
Install
npm i -g botdown
npm i botdown
Examples
Create message for line bot
import {Client} from '@line/bot-sdk'
import {Message} from 'botdown'
const client = new Client({
channelAccessToken: 'YOUR_CHANNEL_ACCESS_TOKEN',
channelSecret: 'YOUR_CHANNEL_SECRET'
})
// ignore how to get event, please refer line sdk document to get it
client.replyMessage(event.replyToken, Message(`pure text`).Line())
In FB, we call send API to send our message
function callSendAPI(sender_psid, response) {
// Construct the message body
let request_body = {
"recipient": {
"id": sender_psid
},
"message": response
}
// Send the HTTP request to the Messenger Platform
request({
"uri": "https://graph.facebook.com/v2.6/me/messages",
"qs": { "access_token": PAGE_ACCESS_TOKEN },
"method": "POST",
"json": request_body
}, (err, res, body) => {
if (!err) {
console.log('message sent!')
} else {
console.error("Unable to send message:" + err);
}
});
}
// ignore
let message = Message(`pure text`).FB()
callSendAPI(sender_psid, message)
// sender_psid you have to get from webhook_event.sender.id