简体   繁体   English

重铸机器人连接器的recast.ai机器人的终点网址是什么

[英]what would be the end point url of my recast.ai bot for recast bot connector

I have created a bot on recast.ai which I want to integrate with slack. 我在recast.ai上创建了一个机器人,我想与slack集成。 Now it's bot connector is asking for end point of my bot running at localhost (forwarded by ngrok). 现在,它的机器人连接器正在询问我的机器人在localhost(由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)? 我的机器人实际上不在我的机器上的recast.ai(我创建并训练过的)上运行,然后如何转发它(我相信与Microsoft LUIS相同)?
  2. I am supposed to develop a parser for my recast.ai bot & host it then what is what is bot connector meant for? 我应该为recast.ai bot开发一个解析器并托管它,那么bot connector是什么意思?

Your bot is not running on Recast.AI. 您的漫游器未在Recast.AI上运行 Recast.AI is a platform and an API where you can train a bot to understand users's input. Recast.AI是一个平台和API,您可以在其中训练机器人以了解用户的输入。 But you need to create a script that received user's input and send it to Recast.AI API to analyse it. 但是您需要创建一个接收用户输入的脚本,并将其发送到Recast.AI API进行分析。

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. Bot Connector可帮助您将脚本连接到任何通道(例如Messenger或Slack),并从这些通道接收用户的所有输入。

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. 因此,您需要使用ngrok在本地运行脚本(也称为bot),并在bot连接器界面中设置此URL,以接收来自用户的每条消息。

if you make your bot in NodeJs, your script will look like this: 如果您在NodeJs中创建机器人,则脚本将如下所示:

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

your file index.js: 您的文件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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM