Google Chat 訊息總覽

本頁面說明文字和資訊卡訊息的差異。

當 Chat 擴充應用程式傳送簡訊來傳達基本資訊時, 訊息會顯示為內嵌內容,就像使用者在 Google Chat 中撰寫訊息一樣 訊息。建立內容多於文字的訊息,或是 使用者可以互動的訊息,Chat 應用程式可以使用 資訊卡 即時通訊應用程式也可以利用資訊卡附加訊息。目的地: 提示使用者完成多步驟流程,例如填寫表單 即時通訊應用程式也可以建立會在新視窗中開啟的資訊卡, 對話方塊

簡訊剖析

在 Google Chat API 中,訊息會以 JSON 物件表示。在訊息中, 簡訊是以 text敬上 物件。

在下列項目中 例如,Chat 應用程式在聊天室中建立簡訊 我們有一群軟體開發人員 現在正面臨程式碼凍結問題

{
  "text": "Attention <users/all>: Code freeze starts at `11:59 am` Pacific Standard Time! If you need a little more time, type `/moreTime` and I'll push the code freeze back one hour."
}

JSON 會傳回下列訊息:

Google Chat 中宣布程式碼凍結的簡訊範例。

卡片訊息剖析

在 Google Chat API 中,訊息會以 JSON 物件表示。在郵件中 資訊卡呈現的 cardsV2敬上 陣列,且由下列項目組成:

  • 一或多個 CardWithId 物件
  • cardId,用於識別卡片並在特定訊息中限定範圍。 (不同訊息中的卡片可使用同一組 ID)。
  • card 物件,由以下項目組成:

    • header 物件 指定標題、副標題和顯示圖片等元素。
    • 一或多個 section 物件 每個 Pod 都至少包含一個小工具
    • 一或多個 widget 物件。 每個小工具都是一個複合物件,可以代表文字、圖像、 按鈕等物件類型

例如下列資訊卡訊息 headersectionwidget 物件:

在 Chat 中執行意見調查的 Chat 應用程式
資訊卡的聊天室
訊息

以下程式碼代表卡片訊息的 JSON:

JSON

{
  "cardsV2": [
    {
      "cardId": "unique-card-id",
      "card": {
        "header": {
          "title": "Sasha",
          "subtitle": "Software Engineer",
          "imageUrl": "https://developers.google.com/chat/images/quickstart-app-avatar.png",
          "imageType": "CIRCLE",
          "imageAltText": "Avatar for Sasha"
        },
        "sections": [
          {
            "header": "Contact Info",
            "collapsible": true,
            "uncollapsibleWidgetsCount": 1,
            "widgets": [
              {
                "decoratedText": {
                  "startIcon": {
                    "knownIcon": "EMAIL"
                  },
                  "text": "sasha@example.com"
                }
              },
              {
                "decoratedText": {
                  "startIcon": {
                    "knownIcon": "PERSON"
                  },
                  "text": "<font color=\"#80e27e\">Online</font>"
                }
              },
              {
                "decoratedText": {
                  "startIcon": {
                    "knownIcon": "PHONE"
                  },
                  "text": "+1 (555) 555-1234"
                }
              },
              {
                "buttonList": {
                  "buttons": [
                    {
                      "text": "Share",
                      "onClick": {
                        "openLink": {
                          "url": "https://example.com/share"
                        }
                      }
                    },
                    {
                      "text": "Edit",
                      "onClick": {
                        "action": {
                          "function": "goToView",
                          "parameters": [
                            {
                              "key": "viewType",
                              "value": "EDIT"
                            }
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        ]
      }
    }
  ]
}


您可以使用 Card Builder 設計及預覽即時通訊應用程式的 JSON 資訊卡訊息:

開啟資訊卡建立工具