[英]502(Bad gateway) when doing a POST to the bot
我正在仅使用HTTP-GET和纯JS构建非常简单的交互式BOT。 有时我需要BOT进行时间密集的处理,并且需要40秒钟才能回复。 在这种情况下,我得到以下关于POST的响应。
那么,这种回报是期望的吗?
我要进行哪些更改才能收到有意义的答复,而不将这种情况视为真正的错误?
还有其他建议可以解决这种情况吗?
谢谢!
502 (Bad Gateway)
{
"error": {
"code": "ServiceError",
"message": "Failed to send activity: bot returned an error"
}
}
发布请求
//send token and message
function sendMessage() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var responseObj = JSON.parse(this.responseText);
convMsgID =responseObj.id;
latestUserMessage = document.getElementById('textToSend').value;
showUserMessage();
document.getElementById('textToSend').value = "";
getReply();
}
else{
console.log("error :"+ this.responseText);
}
};
var postUrl = "https://directline.botframework.com/v3/directline/conversations/" + convID + "/activities";
xhttp.open("POST", postUrl, true);
var authToken="Bearer " + convToken;
xhttp.setRequestHeader("Authorization", authToken);
xhttp.setRequestHeader("Content-Type", "application/json");
var messageBody = '{"type": "message","from": {"id": "user1"},"text": "';
messageBody = messageBody + document.getElementById("textToSend").value;
messageBody = messageBody + '"}';
console.log("messageBody"+ messageBody);
xhttp.send(messageBody);
document.getElementById("send-icon").src="./send.png";
}
GET请求
function getReply() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var responseObj = JSON.parse(this.responseText);
console.log("length" + (responseObj.activities.length -1));
console.log("response :"+ responseObj.activities[responseObj.activities.length -1].text);
latestBotMessage = responseObj.activities[responseObj.activities.length - 1].text
showBotMessage();
}
else{
console.log("response"+ this.responseText);
}
};
var postUrl = "https://directline.botframework.com/v3/directline/conversations/" + convID + "/activities";
xhttp.open("GET", postUrl, true);
var authToken="Bearer " + convToken;
xhttp.setRequestHeader("Authorization", authToken);
xhttp.send();
}
1)是,如果漫游器回复时间超过15秒,则预期为502
2&3)在开始长期运行的过程之前对用户做出响应。 让某些工作人员执行长时间的操作(Azure功能?),完成后,将结果作为主动消息发送给用户: https : //docs.microsoft.com/zh-cn/bot-framework/nodejs/bot- builder-nodejs-proactive-messages
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.