502(坏的网关)时,做一个POST机器人

我只用HTTP-GET和普通的JS构build了一个非常简单的交互式BOT。 有时候我有BOT做时间密集型的处理,需要40秒才能回复。 在这种情况下,我得到了POST的下面的响应。

  1. 那么,这是预期的回报?

  2. 我做了什么样的改变,才能得到有意义的答复,而不是把这种情况看作是真正的错误?

  3. 任何其他build议来处理这种情况?

谢谢!

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)在开始长时间运行之前,对用户作出响应。 有一些worker作业执行长时间的操作(Azure Function?),并在完成后将结果作为主动消息发送给: https : //docs.microsoft.com/en-us/bot-framework/nodejs/bot-build设者-的NodeJS,积极的消息