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. 确认您要在正确的 Cloud 项目中启用 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特定于渠道的响应