2

I have created a bot on recast.ai which I want to integrate with slack. Now it's bot connector is asking for end point of my bot running at localhost (forwarded by ngrok). Now my question is:

  1. My bot is actually running at recast.ai (which I have created & trained) not on my machine then how can I forward it (same as Microsoft LUIS, I believe)?
  2. I am supposed to develop a parser for my recast.ai bot & host it then what is what is bot connector meant for?
achedeuzot
  • 3,659
  • 4
  • 38
  • 48
Vaibhav Singh
  • 123
  • 1
  • 8

1 Answers1

3

Your bot is not running on Recast.AI. Recast.AI is a platform and an API where you can train a bot to understand users's input. But you need to create a script that received user's input and send it to Recast.AI API to analyse it.

Bot Connector helps you to connect your script to any channels (like messenger or slack) and receive all the user's input from these channels.

So you need to run your script (aka your bot) in local, with ngrok and set this URL in the bot connector interface to receive each messages from your users.

if you make your bot in NodeJs, your script will look like this:

npm install --save recastai recastai-botconnector express body-parser 

your file index.js:

/* module imports */
const BotConnector = require('recastai-botconnector')
const recastai = require('recastai')
const express = require('express')
const bodyParser = require('body-parser')

/* Bot Connector connection */
const myBot = new BotConnector({ userSlug: 'YOUR_USER_SLUG', botId: 'YOUR_BOT_ID', userToken: 'YOUR_USER_TOKEN' })

/* Recast.AI API connection */
const client = new recastai.Client('YOUR_REQUEST_TOKEN')

/* Server setup */
const app = express()
const port = 5000

app.use(bodyParser.json())
app.post('/', (req, res) => myBot.listen(req, res))
app.listen(port, () => console.log('Bot running on port', port))

/* When a bot receive a message */
myBot.onTextMessage(message => {
  console.log(message)
  const userText = message.content.attachment.content
  const conversationToken = message.senderId

  client.textConverse(userText, { conversationToken })
    .then(res => {
      // We get the first reply from Recast.AI or a default reply
      const reply = res.reply() || 'Sorry, I didn\'t understand'

      const response = {
        type: 'text',
        content: reply,
      }

      return message.reply(response)
    })
    .then(() => console.log('Message successfully sent'))
    .catch(err => console.error(`Error while sending message: ${err}`))
})

and run your bot

node index.js
Jasmine
  • 31
  • 2