2017-01-25 1 views
1

recast.ai私はスラックと統合したいボットを作成しました。 bot connectorはローカルホストで実行中のボットのエンドポイントを要求しています(ngrokが転送しました)。今私の質問は次のとおりです。リキャストボットコネクタ用の私のrecast.aiボットのエンドポイントURL

  1. 私のボットは、実際に私のマシン上で(私は訓練を受けた& を作成している)recast.aiでない実行されて、その後どのように私は( マイクロソフトLUISと同じ、私は信じている)、それを転送することができますか?
  2. 私は自分のrecast.aiボットのパーサーを開発することになっています&ホストそれ ボットコネクタの意味は何ですか?

答えて

2

ご使用のロボットはであり、Recast.AIでを実行していません。 Recast.AIは、ユーザーの入力を理解するためにボットをトレーニングできるプラットフォームとAPIです。しかし、ユーザーの入力を受け取り、それを分析するためにRecast.AI APIに送信するスクリプトを作成する必要があります。

ボットコネクタを使用すると、スクリプトを任意のチャンネル(メッセンジャーやスラックなど)に接続し、これらのチャンネルからすべてのユーザーの入力を受け取ることができます。

ngrokを使用してスクリプト(別名ボット)をローカルで実行し、ボットコネクタインターフェイスでこのURLを設定して、ユーザーからの各メッセージを受信する必要があります。

あなたがNodeJsであなたのボットを作る場合、スクリプトは次のようになります。

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

ファイルの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}`)) 
}) 

node index.js 
あなたのボットを実行します
関連する問題