簡體   English   中英

代碼中我的對話流請求有什么問題(它適用於郵遞員)?

[英]What is the problem of my dialogflow request in the code (it works with postman)?

我的聊天機器人應用程序有問題。 我只是沒有找到錯誤,為什么我不能根據我對代碼的請求調用對話流 api 它與來自 postman 的完全相同的請求一起工作。 甚至對話流支持也說請求是正確的。

可以以某種方式從對話流中阻止它嗎? 或者它不會自動將 javascript 代碼更改為 json object?

下面我向您發送我的應用程序的代碼(代碼段 1)、代碼請求的實際結果(代碼段 2)、我使用 postman 時返回的想要的結果(代碼段 3),以及對話流中的意圖(屏幕截圖 1)。

代碼片段 1:我的應用程序的代碼

const fetchAnswerFromDialogflow = async (userInput, currentChatbotInEdit) => {

const config = {
      headers: {
        Authorization: "Bearer " + clientToken,
        "Content-Type": "application/json; charset=utf-8",
      },
    };

const request = {
      queryParams: {
        contexts: [
          {
            name:
              `projects/myteachingbot-arxmxd/agent/sessions/myteachingbot-session${state.sessionId}/contexts/Chatbotcontext726`,
            lifespanCount: 1,
          },
          {
            name:
              `projects/myteachingbot-arxmxd/agent/sessions/myteachingbot-session${state.sessionId}/contexts/Chatbotcontext7262`
              inputContext1,
            lifespanCount: 1,
          },
        ],
        resetContexts: true,
      },
      queryInput: {
        text: {
          text: userInput,
          languageCode: "en-US",
        },
      },
    };
try {
      const res = await axios.post(
        `https://dialogflow.googleapis.com/v2/projects/myteachingbot-arxmxd/agent/sessions/myteachingbot-session${state.sessionId}:detectIntent`,
        request,
        config
      );
      console.log(res);

}

代碼片段2:代碼請求的實際結果

{
  "responseId": "8a9ead3d-f3ea-4a75-b110-257454069382-425db6e2",
  "queryResult": {
    "queryText": "start",
    "parameters": {},
    "languageCode": "en"
  }
}

代碼片段 3:我從 postman 返回的想要的結果:

{
  "responseId": "f8ea7646-576a-4789-a88f-d0f80416de84-425db6e2",
  "queryResult": {
    "queryText": "start",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Frage 1",
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            "Frage 1"
          ]
        }
      }
    ],
    "intent": {
      "name": "projects/myteachingbot-arxmxd/agent/intents/70aa4273-5368-4a40-acc3-484c8ad415df",
      "displayName": "Frage7261"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "en"
  }
}

對話流控制台中的意圖屏幕截圖

如果您提供的 Intent 是您希望觸發的 Intent - 它不會被任何訓練短語觸發,因為已為其設置了事件。

如果該事件作為檢測意圖請求的一部分發送,則 Dialogflow 只會觸發包含事件的意圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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