代码中的dialogflow请求有什么问题(与邮递员一起使用)? [英] What is the problem of my dialogflow request in the code (it works with postman)?

查看:95
本文介绍了代码中的dialogflow请求有什么问题(与邮递员一起使用)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的聊天机器人应用程序有问题。我只是没有发现为什么我无法用代码中的请求调用dialogflow API的错误,因为它很难与邮递员的相同请求一起使用。甚至dialogflow支持人员都说该请求是正确的。还是不会自动将javascript代码更改为json对象?


下面,我向您发送了我的应用程序代码(代码段1),这是代码请求的实际结果(代码段) 2),当我使用邮递员(代码片段3)时返回想要的结果,以及dialogflow中意图的屏幕截图(屏幕截图1)。


代码片段1 :我的应用程序代码

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

const config = {
标头:{
授权: Bearer + clientToken,
Content-Type: application / json; charset = utf-8,
},
};

const请求= {
queryParams:{
上下文:[
{
名称:
`projects / myteachingbot-arxmxd / agent / session / 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`,
请求,
配置
);
console.log(res);

}

代码段2:代码请求的实际结果

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

代码段3:返回的通缉结果邮递员:

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

解决方案

如果您提供的意图是您希望触发的意图,则不会被任何触发


Dialogflow仅在将事件作为检测意图请求的一部分发送时,才会触发包含该事件的意图。


I have a problem with my chatbot Application. I just don't find the mistake why I can't call the dialogflow api with my request from code tough it works with the exact same request from postman. Even the dialogflow support says that the request is correct.

Can it be blocked somehow from dialogflow? Or does it not automatically change the javascript code into a json object?

Below I send you the code of my application (code snippet 1), the actual result from the code request (code snippet 2), the wanted result as it comes back when I use postman (code snippet 3), and the screenshot of the intent in dialogflow (screenshot 1).

code snippet 1: code of my application

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);

}

code snippet 2: the actual result from the code request

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

code snippet 3: the wanted result that I get returned from 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"
  }
}

解决方案

If the Intent you've provided is the Intent you expect to be triggered - it won't be triggered by any of the Training Phrases since an Event is set for it.

Dialogflow will only trigger an Intent that contains an Event if that Event is sent as part of the Detect Intent request.

这篇关于代码中的dialogflow请求有什么问题(与邮递员一起使用)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆