2017-07-18 104 views
0

我已经使用Microsoft Bot Framework完成了Chat-bot。机器人在模拟器上运行良好。不过,我想把它托管到Heroku。Heroku托管Microsoft Bot Framework Chatbot不工作

我app.js代码:

var builder = require('botbuilder'); 
var restify = require('restify'); 
var apiairecognizer = require('api-ai-recognizer'); 
var request = require('request'); 

//========================================================= 
// Bot Setup 
//========================================================= 

// Setup Restify Server 
var server = restify.createServer(); 
server.listen(process.env.port || process.env.PORT || 3978, function() { 
    console.log('%s listening to %s', server.name, server.url); 
}); 

// Create chat bot 
var connector = new builder.ChatConnector({ 
    appId: "xxx", /*changed*/ 
    appPassword: "xxx" /*changed*/ 
}); 

server.post('/api/messages', connector.listen()); 
var bot = new builder.UniversalBot(connector); 


var recognizer = new apiairecognizer("xxx"); 
var intents = new builder.IntentDialog({ 
     recognizers: [recognizer] 
}); 

bot.dialog('/',intents); 

intents.matches('Intro',function(session, args){ 
    var fulfillment = builder.EntityRecognizer.findEntity(args.entities, 'fulfillment'); 
    if (fulfillment){ 
     var speech = fulfillment.entity; 
     session.send(speech); 
    }else{ 
     session.send('Sorry...not sure how to respond to that'); 
    } 
}); 

intents.matches('Default Fallback Intent',function(session, args){ 
    var fulfillment = builder.EntityRecognizer.findEntity(args.entities, 'fulfillment'); 
    if (fulfillment){ 
     var speech = fulfillment.entity; 
     session.send(speech); 
    }else{ 
     session.send('Sorry...not sure how to respond to that'); 
    } 
}); 

我尝试下面的命令来将其推到Heroku上:

  1. 远程Git RM Heroku的
  2. 的git的init
  3. 创建的文件.gitignore和它里面node_modules/
  4. git add。
  5. git的承诺-m “基本设置机器人做”
  6. Procfile和添加的代码 网:节点index.js
  7. 的Heroku创建
  8. 的Heroku的git:远程-a应用程序名称
  9. 混帐推的Heroku掌握
  10. Heroku的开放

我还通过短信端点消息端点更新:在机器人发展门户http://appname.herokuapp.com/api/messages

构建成功。如果我打开http://appname.herokuapp.com/api/messages,我看到{"code":"MethodNotAllowedError","message":"GET is not allowed"}并在开放{"code":"ResourceNotFound","message":"/ does not exist"}

我卡在这里。我想使用Bot注册门户提供的I Frame在页面上使用chat-bot。如何从这里开始并使机器人工作?

+0

由于端点是POST路由,因此会出现get错误。注册门户中的聊天工作? –

+0

您的服务器是否有有效的SSL证书?您的消息端点必须通过HTTPS提供有效的证书。 – nilsw

回答

1

我有同样的问题,通过这样做修复它。在app文件夹 打开终端/ PowerShell和键入以下

heroku config:set MICROSOFT_APP_ID=YOUR_APP_ID MICROSOFT_APP_PASSWORD=YOUR_APP_PASSWORD

0

这意味着你的机器人托管和工作。你的机器人基本上是只接受POST请求的API:

server.post('/api/messages', connector.listen()); 

所以,当您试图访问你的浏览器http://appname.herokuapp.com/api/messages你是一个GET请求,你的API不接受。

iFrame将成为您的机器人的前端,它将使用托管在heroku上的bot API。设置iFrame的说明如下:https://docs.microsoft.com/en-us/bot-framework/channel-connect-webchat

您可以通过单击右侧角落中将打开网络聊天的测试按钮来测试API是否在bot门户https://dev.botframework.com/bots?id=[your-bot-id]上工作。

相关问题