Google Chat

借助 Dialogflow CX 的 Google Chat 集成,您可以基于 Dialogflow CX 技术创建具有自然语言理解能力的 Google Chat 应用。

限制

设置 Google Chat

如需为代理设置 Google Chat 集成,您需要具备:

启用 Google Chat API

在使用 Google API 之前,您需要在 Google Cloud 项目中启用它们。您可以在单个 Google Cloud 项目中启用一个或多个 API。

  1. 在 https://console.cloud.google.com/中,启用 Google Chat API 和 Dialogflow API。

  2. 确认您要在正确的云项目 中启用 API,然后点击下一步

  3. 确认您要启用正确的 API,然后点击启用

通过 Dialogflow CX 进行设置

  1. 前往 Dialogflow CX 控制台
  2. 选择您的 Google Cloud 项目。
  3. 选择您的代理。
  4. 选择管理标签页。
  5. 点击左侧边栏菜单中的集成
  6. 点击 Google Chat 上的连接
  7. 填写以下必填信息:
    • 名称:向与此应用创建的内容互动或使用这些内容的用户显示的名称,例如在消息、搜索和 @提及中。例如 Dialogflow CX App
    • 头像网址:向与应用互动的用户显示的头像图片。指定一个托管一张方形(宽高比为 1:1)PNG 图片的 HTTPS 网址。建议的最小尺寸:256 x 256 像素。例如 https://developers.google.com/workspace/chat/images/quickstart-app-avatar.png
    • 说明:应用的说明。例如,A helpful bot that responds to real human conversation
  8. 选择环境 (如适用)。
  9. 输入电子邮件地址 ,以便向特定人员和群组提供此 Chat 应用(如适用)。
  10. 点击开始

测试

如需测试配置的应用,请在 Google Chat 聊天室中提及该应用,或向其发送私信。例如,

  1. 打开 Google Chat
  2. 点击发起新聊天
  3. 添加 1 位或多位用户 字段中,输入 Chat 应用的名称。
  4. 从结果中选择您的 Chat 应用。系统会打开一条私信。

富响应消息

富响应消息通过自定义载荷履行中提供支持。如需了解消息格式,请参阅 Google Chat 消息 API

短信

以下自定义载荷提供 Google Chat 短信

{
  "text": "Hello, world"
}

如果您使用的是 Chat 插件,以下自定义载荷提供 Google Chat 短信

        {
            hostAppDataAction: {
              chatDataAction: {
                createMessageAction: {
                  message: {
                    text: "Your pizza delivery is here!"
                  }
                }
              }
            }
        }

卡片消息

以下自定义载荷提供 Google Chat 卡片消息

{
  'cardsV2': [{
    'cardId': 'createCardMessage',
    'card': {
      'header': {
        'title': 'A card message!',
        'subtitle': 'Sent from Dialogflow CX',
        'imageUrl': 'https://developers.google.com/chat/images/chat-product-icon.png',
        'imageType': 'CIRCLE'
      },
      'sections': [
        {
          'widgets': [
            {
              'buttonList': {
                'buttons': [
                  {
                    'text': 'Read the docs!',
                    'onClick': {
                      'openLink': {
                        'url': 'https://developers.google.com/workspace/chat'
                      }
                    }
                  }
                ]
              }
            }
          ]
        }
      ]
    }
  }]
}

如果您使用的是 Chat 插件,以下自定义载荷提供 Google Chat 卡片消息

{
  "host_app_data_action": {
    "chat_data_action": {
      "create_message_action": {
        "message": {
          "cardsV2": [
            {
              "card_id": "basic1",
              "card": {
                "header": {
                  "title": "This is a card!",
                  "subtitle": "Sent from Conversational Agents (Dialogflow CX)",
                  "imageUrl": "https://developers.google.com/chat/images/chat-product-icon.png",
                  "imageType": "CIRCLE"
                },
                "sections": [
                  {
                    "widgets": [
                      {
                        "buttonList": {
                          "buttons": [
                            {
                              "text": "Open Google!",
                              "color": {
                                "red": 0.101960786,
                                "green": 0.4509804,
                                "blue": 0.9098039
                              },
                              "onClick": {
                                "openLink": {
                                  "url": "http://google.com"
                                }
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                ]
              }
            }
          ]
        }
      }
    }
  }
}

频道专用响应

配置后,当代理响应 Google Chat 消息时,系统会自动使用频道为 DF_CX_GOOGLE_CHAT频道专用响应