request access token you will need to configure your bot.




git clone https://github.com/RecastAI/bot-messenger.git
./ngrok http 5000
https://*******ngrok.io you get, you will need it for the next step.Recast.AI access tokenToken of your PageThe token of your Webhookvim config.js
const config = {}
config.pageAccessToken = 'PAGE_TOKEN'
config.validationToken = 'ABCD1234'
config.recastToken = 'RECAST_TOKEN'
config.language = 'en'
module.exports = config
npm install
npm start



client.textConverse(message.body, { conversationToken: senderID }) To use this method you need to pass the user’s input, and a unique conversation token. This token can be the senderId of the messenger chat. This token will create for each users a specific conversation with your bot.res.reply() To get the first reply of your bot.res.replies To get an array of all your replies. res.action Get the object action. When an action is complete you will have the action.done = true and you will be able to trigger a specific behavior.replyMessage(sendeID,YOUR_TEXT) to send a basic text message.replyButton(senderID, options) to send a basic button, if you whant a more complete button I advise to check the function replyButton in the bot.js file && the [Faceboook doc for button] (https://developers.facebook.com/docs/messenger-platform/send-api-reference#message).function handleMessage(event) {
const senderID = event.sender.id
const messageText = event.message.text
const messageAttachments = event.message.attachments
if (messageText) {
client.textConverse(messageText, { conversationToken: senderID }).then((res) => {
const reply = res.reply() /* To get the first reply of your bot. */
const replies = res.replies /* An array of all your replies */
const action = res.action /* Get the object action. You can use 'action.done' to trigger a specification action when it's at true. */
if (!reply) {
const options = {
messageText: null,
buttonTitle: 'My first button', /* Option of your button. */
buttonUrl: 'https://recast.ai/', /* If you like more option check out ./facebook.js the function replyButton, and look up */
buttonType: 'web_url', /* the facebook doc for button https://developers.facebook.com/docs/messenger-platform/send-api-reference#message */
elementsTitle: 'I don\'t get it :(',
}
replyButton(senderID, options) /* to reply a button */
} else {
if (action && action.done === true) {
console.log('action is done')
// Use external services: use res.memory('notion') if you got a notion from this action
}
let promise = Promise.resolve()
replies.forEach(rep => {
promise = promise.then(() => replyMessage(senderID,rep))
})
promise.then(() => {
console.log('ok')
})
}
}).catch(err => {
console.log(err)
})
} else if (messageAttachments) {
replyMessage(senderID, 'Message with attachment received')
}
}
Henri Floren - Recast.AI
henri.floren@recast.ai
You can follow us on Twitter at @recastai for updates and releases.
Copyright © [2016] Recast.AI
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.