如何在 Dialogflow NodeJS 客户端中设置自定义平台 [英] How to set a custom platform in Dialogflow NodeJS Client

查看:17
本文介绍了如何在 Dialogflow NodeJS 客户端中设置自定义平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 dialogflow-fulfillment 创建了一个 webhook,以根据情况正确返回不同的数据在平台上,包括我为另一项服务创建的自定义.我已经测试了我的 webhook 并且知道如果我将 originalDetectIntentRequest.source 更改为我的自定义负载中使用的平台,它可以工作.

I have created a webhook using dialogflow-fulfillment to correctly return different data depending on the platform, including a custom one I created for another service. I've tested my webhook and know that if I change the originalDetectIntentRequest.source to the platform used in my custom payload it works.

{
    "payload": {
        "jokes-api": {
            "success": true,
            "text": "These are some jokes",
        }
    },
    "outputContexts": []
}

我可以使用 dialogflow-nodejs-client-v2's sessions.detectIntent 以获得响应,但完整返回时平台设置为 PLATFORM_UNSPECIFIED,而不是我想要的自定义有效负载.

I am able to use dialogflow-nodejs-client-v2's sessions.detectIntent to get a response, but the fullfilment comes back with the platform set as PLATFORM_UNSPECIFIED, and not the custom payloads I want.

[{
    "responseId": "c56c462f-bb3b-434a-b318-3739f58e6f6d",
    "queryResult": {
        "fulfillmentMessages": [{
            "platform": "PLATFORM_UNSPECIFIED",
            "card": {
                "buttons": [],
                "title": "Jokes",
                "subtitle": "These are some jokes",
                "imageUri": ""
            },
            "message": "card"
        }],
        "queryText": "tell me a joke",
        /* ... */
        "intent": {
            "name": "projects/my-jokes/agent/intents/56887375-3047-4993-8e14-53b20dd02697",
            "displayName": "Jokes",
            /* ... */
        },
        "intentDetectionConfidence": 0.8999999761581421,
    }
}]

查看我的 webhook 的日志,我可以看到 originalDetectIntentRequest 对象存在,但未设置源.

Looking at the logs for my webhook, I can see that the originalDetectIntentRequest object is present, but source is not set.

{
  "responseId": "c56c462f-bb3b-434a-b318-3739f58e6f6d",
  "queryResult": {
    "queryText": "tell me a joke",
    "speechRecognitionConfidence": 0.9602501,
    /* ... */
    "intent": {
      "name": "projects/my-jokes/agent/intents/56887375-3047-4993-8e14-53b20dd02697",
      "displayName": "Jokes"
    },
    /* ... */
  },
  "originalDetectIntentRequest": {
    "payload": {
    }
  },
  "session": "projects/my-jokes/agent/sessions/12345"
}

如何在 dialogflow-nodejs-client-v2 中设置平台或源以获得所需的响应?

How can I set the platform or source in dialogflow-nodejs-client-v2 to get the desired responses?

推荐答案

sessions.detectIntent API 有 queryParams 参数,该参数有一个名为 payload.这就是原始有效载荷"的所在.平台的名称进入该结构的 source 字段.所以你的 detectIntent 调用应该是这样的:

sessions.detectIntent API has queryParams parameter which has a field called payload. That's where the "original payload" goes. The name of the platform goes into the source field of that structure. So your detectIntent call should look something like this:

sessionClient.detectIntent({
    session: sessionClient.sessionPath('<project_id>', '<session_id>'),
    queryInput: {
        text: {
            text: '<query>',
            languageCode: 'en-US'
        }
    },
    queryParams: {
        payload: {
            fields: {
                source: {
                    stringValue: '<platform>',
                    kind: 'stringValue'
                }
            }
        }
    }
})

我能够通过使用slack"作为平台名称来模拟 Slack 集成调用.我还能够为自定义平台名称返回自定义负载.有效载荷在 queryResult.webhookPayload 字段中返回.

I was able to simulate Slack integration call by using 'slack' as a platform name. I was also able to return a custom payload for a custom platform name. The payload is returned in queryResult.webhookPayload field.

这篇关于如何在 Dialogflow NodeJS 客户端中设置自定义平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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