Dialogflow es 使用dialogflow webhook的Google聊天自定义卡

Dialogflow es 使用dialogflow webhook的Google聊天自定义卡,dialogflow-es,google-workspace,dialogflow-es-fulfillment,hangouts-chat,google-chat,Dialogflow Es,Google Workspace,Dialogflow Es Fulfillment,Hangouts Chat,Google Chat,我正在尝试将DialogFlow机器人与Hangouts聊天(用于G套件)集成。我已经启用了DialogFlow上的集成,基本意图工作正常 为了使用fulfillment执行后端操作,我创建了一个firebase云函数,并将其添加为DialogFlow fulfillment页面上的webhook URL 我已经编写了云函数代码来识别意图,并为简单的文本响应生成Webhook响应格式。这是可行的,我看到firestore数据正在根据意图进行修改 然而,对于更复杂的意图,我希望更多地使用Chat提

我正在尝试将DialogFlow机器人与Hangouts聊天(用于G套件)集成。我已经启用了DialogFlow上的集成,基本意图工作正常

为了使用fulfillment执行后端操作,我创建了一个firebase云函数,并将其添加为DialogFlow fulfillment页面上的webhook URL

我已经编写了云函数代码来识别意图,并为简单的文本响应生成Webhook响应格式。这是可行的,我看到firestore数据正在根据意图进行修改

然而,对于更复杂的意图,我希望更多地使用Chat提供的基于动态卡的响应。为了实现这一点,我查看了dialogflow卡响应的文档

我在上看到了下面的代码。当我将其粘贴到hangouts custom payload下的dialogflow intent editor UI中时(禁用webhook集成后),它就可以工作了

{
  "hangouts": {
    "header": {
      "title": "Pizza Bot Customer Support",
      "subtitle": "pizzabot@example.com",
      "imageUrl": "..."
    },
    "sections": [{
      "widgets": [{
        "keyValue": {
          "icon": "TRAIN",
          "topLabel": "Order No.",
          "content": "12345"
        }
      },
      {
        "keyValue": {
          "topLabel": "Status",
          "content": "In Delivery"
        }
      }]
    },
    {
      "header": "Location",
      "widgets": [{
        "image": {
          "imageUrl": "https://dummyimage.com/600x400/000/fff"
        }
      }]
    },
    {
      "header": "Buttons - i could leave the header out",
      "widgets": [{
        "buttons": [{
          "textButton": {
            "text": "OPEN ORDER",
            "onClick": {
              "openLink": {
                "url": "https://example.com/orders/..."
              }
            }
          }
        }]
      }]
    }]
  }
}

这正是我需要的,但我需要webhook的响应我没有得到正确的响应格式来映射两者。

当我尝试将相同的代码与webhook集成时,我没有得到任何关于闲逛聊天的回复。当我检查dialogflow UI上的history部分时,下面是原始交互日志中提到的响应结构

{
  "queryText": "<redacted>",
  "parameters": {},
  "intent": {
    "id": "<redacted>",
    "displayName": "<redacted>",
    "priority": 500000,
    "webhookState": "WEBHOOK_STATE_ENABLED"
  },
  "intentDetectionConfidence": 1,
  "diagnosticInfo": {
    "webhook_latency_ms": 284
  },
  "languageCode": "en",
  "slotfillingMetadata": {
    "allRequiredParamsPresent": true
  },
  "id": "<redacted>",
  "sessionId": "<redacted>",
  "timestamp": "2020-07-30T12:05:29.094Z",
  "source": "agent",
  "webhookStatus": {
    "webhookUsed": true,
    "webhookPayload": {
      "hangouts": {
        "header": {
          "subtitle": "pizzabot@example.com",
          "title": "Pizza Bot Customer Support",
          "imageUrl": "..."
        },
        "sections": [
          {
            "widgets": [
              {
                "keyValue": {
                  "content": "12345",
                  "topLabel": "Order No.",
                  "icon": "TRAIN"
                }
              },
              {
                "keyValue": {
                  "topLabel": "Status",
                  "content": "In Delivery"
                }
              }
            ]
          },
          {
            "widgets": [
              {
                "image": {
                  "imageUrl": "https://dummyimage.com/600x400/000/fff"
                }
              }
            ],
            "header": "Location"
          },
          {
            "widgets": [
              {
                "buttons": [
                  {
                    "textButton": {
                      "text": "OPEN ORDER",
                      "onClick": {
                        "openLink": {
                          "url": "https://example.com/orders/..."
                        }
                      }
                    }
                  }
                ]
              }
            ],
            "header": "Buttons - i could leave the header out"
          }
        ]
      }
    },
    "webhookStatus": {
      "message": "Webhook execution successful"
    }
  },
  "agentEnvironmentId": {
    "agentId": "<redacted>",
    "cloudProjectId": "<redacted>"
  }
}
这里的json变量应该是我前面提到的json结构。现在,我可以使用不推荐使用的API映射到正确的响应格式。但是,我无法使用按钮将正确的响应发送到后端。这是我从前面的json修改的buttons字段

  "buttons": [
    {
      "textButton": {
        "text": "Click Me",
        "onClick": {
          "action": {
            "actionMethodName": "snooze",
            "parameters": [
              {
                "key": "time",
                "value": "1 day"
              },
              {
                "key": "id",
                "value": "123456"
              }
            ]
          }
        }
      }
    }
  ]

据我所知,在使用direct Dialogflow集成时,无法响应Google聊天(以前称为Hangouts聊天)按钮

问题在于按钮响应可以通过以下两种方式之一发送:

  • 一个事件将发送回bot代码,指示单击
  • 如大多数测试所示,使用
    onClick.openLink.url
    属性。 这将把点击它的人带到有问题的URL。但是一旦到了那里,你就被带出机器人的流程
但是,with Dialogflow的文档没有提供有关如何将此事件传递给Dialogflow的任何信息,上次我测试它时也没有


您可以使用Google Chat的API编写自己的集成,比如或,并让脚本调用Dialogflow来确定用户会触发什么意图(并确定回复或调用webhook进行额外处理)。在此方案下,您可以选择如何处理onClick事件。进行您自己的集成也为您提供了一种方法,这在使用Dialogflow集成时是不可能的。

感谢Allen在这方面的帮助,让我看看这些方法是否适用于我们
  "buttons": [
    {
      "textButton": {
        "text": "Click Me",
        "onClick": {
          "action": {
            "actionMethodName": "snooze",
            "parameters": [
              {
                "key": "time",
                "value": "1 day"
              },
              {
                "key": "id",
                "value": "123456"
              }
            ]
          }
        }
      }
    }
  ]