簡體   English   中英

到機器人的POST時出現502(錯誤網關)

[英]502(Bad gateway) when doing a POST to the bot

我正在僅使用HTTP-GET和純JS構建非常簡單的交互式BOT。 有時我需要BOT進行時間密集的處理,並且需要40秒鍾才能回復。 在這種情況下,我得到以下關於POST的響應。

  1. 那么,這種回報是期望的嗎?

  2. 我要進行哪些更改才能收到有意義的答復,而不將這種情況視為真正的錯誤?

  3. 還有其他建議可以解決這種情況嗎?

謝謝!

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM