我正在尝试根据 echo example 启动并运行 Skype 机器人。但我正在努力向我的应用程序成功发布。当我向 /v1/chat
发送帖子时,我得到的状态为 201(成功创建),正文中没有任何内容。我的 console.log
也没有打印任何内容,这让我相信 botService.on('personalMessage', ...)
函数没有运行。有谁知道这些 POST 请求应该如何格式化?我似乎在文档中找不到任何内容。
我的代码:
const fs = require('fs');
const restify = require('restify');
const skype = require('skype-sdk');
const botService = new skype.BotService({
messaging: {
botId: '28:<bot’s id="ID176db9ab-e313-4d76-a60c-bc2a280e9825">',
serverUrl : "https://apis.skype.com",
requestTimeout : 15000,
appId: process.env.APP_ID,
appSecret: process.env.APP_SECRET
}
});
botService.on('contactAdded', (bot, data) => {
console.log('contact added');
bot.reply('Hello ${data.fromDisplayName}!', true);
});
botService.on('personalMessage', (bot, data) => {
console.log('message incoming');
console.log(data);
bot.reply('Hey ${data.from}. Thank you for your message: "${data.content}".', true);
});
const server = restify.createServer();
server.post('/v1/chat', skype.messagingHandler(botService));
const port = process.env.PORT || 8080;
server.listen(port);
console.log('Listening for incoming requests on port ' + port);
最佳答案
最终编辑和解决方案:我认为这个问题是由 Heroku 造成的(可能是他们的免费层 1 dyno 造成的)。经过一番努力,我将程序上传到Azure,现在运行良好。
<小时/>可能的解决方案:您需要更改 server.post 命令中的服务器地址。如果您的程序在“https:\www.yourwebsite.com/v1/chat”中运行,则需要修改此;
server.post('/v1/chat', skype.messagingHandler(botService));
对此;
server.post('https:\\www.yourwebsite.com/v1/chat', skype.messagingHandler(botService));
当然,不要忘记指定您的应用程序 ID、机器人 ID 和应用程序 key 。如果您没有密码,则需要在 Skype 申请页面中生成密码。
<小时/>我对OP有确切的问题。我遵循了教程,但它没有指定如何修改我们的代码以符合我们的服务器。因此,运行程序后它只返回这个;
{"code":"ResourceNotFound","message":"/不存在"}
在 Skype Bot 网页的 Echo 示例中;它说;
"We'll assume the bot's URL for messaging was set to https://echobot.azurewebsites.net/v1/chat during registration."
关于node.js - Skype 机器人以空 body 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36363518/