在資訊卡中新增文字和圖片
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁說明如何在資訊卡中新增及格式化文字和圖片。
如要進一步瞭解如何建構資訊卡,請參閱「為 Google Chat 應用程式建構資訊卡」。
使用資訊卡建構工具設計及預覽即時通訊應用程式的訊息和使用者介面:
開啟「資訊卡建立工具」
必要條件
已設定為接收及回應互動事件的 Google Chat 應用程式。如要建立互動式 Chat 應用程式,請根據要使用的應用程式架構,完成下列其中一個快速入門導覽:
新增圖片或圖示
本節說明如何在資訊卡中加入圖片、圖片元件和圖示等視覺元素。
新增圖片
Image
小工具
會顯示 HTTPS 網址上託管的 PNG 或 JPG 圖片。
顯示圖片的寬度會填滿顯示卡片的整個寬度,高度則會調整以維持圖片的長寬比。Image
小工具支援使用者點選圖片時發生的onclick
動作。onclick
動作範例包括:
- 使用
OpenLink
開啟超連結,例如 Google Chat 開發人員說明文件的超連結 https://developers.google.com/chat
。
- 執行會執行自訂函式的動作,例如呼叫 API。
Image
小工具具有下列限制:
- 僅支援 PNG 和 JPG 圖片。
- 主機網址必須為
HTTPS
。
- 為確保資訊卡效能良好,建議圖片大小上限為 2 MB。
以下是包含 Image
小工具的資訊卡。畫面上會顯示 Google Chat 開發人員說明文件到達網頁圖片。使用者點選圖片後,Google Chat 開發人員說明文件會在新分頁中開啟。
新增圖片元件
Image
小工具是樣式有限的圖片,您可以使用 imageCompent
小工具,將 cropStyle
和 borderStyle
套用至圖片。
以下範例顯示格線中的兩張圖片,其中一張圖片經過裁剪:
您可以套用 cropStyle
調整圖片元件的形狀。你可以為圖片套用下列形狀:
- 使用
SQUARE
裁剪成正方形。
- 使用
CIRCLE
裁剪為圓形。
- 使用
RECTANGLE_CUSTOM
即可套用自訂顯示比例的矩形裁剪。舉例來說,您可以使用 RECTANGLE_4_3
套用顯示比例為 4:3 的矩形裁剪。
以下範例顯示格狀檢視中的五張圖片,每張圖片都套用了不同的 cropStyle
:
新增圖示
Icon
小工具代表內建圖示或自訂圖示。在資訊卡中新增圖示,即可執行下列任一操作:
以下是包含 Icon
元件和內建圖示的資訊卡:
下表列出可供資訊卡訊息使用的內建圖示:
flight |
AIRPLANE |
bookmark |
書籤 |
directions_bus |
BUS |
directions_car |
CAR |
schedule |
時鐘 |
confirmation_number |
CONFIRMATION_NUMBER_ICON |
subject |
DESCRIPTION |
attach_money |
DOLLAR |
mail |
電子郵件 |
event_seat |
EVENT_SEAT |
flight_land |
FLIGHT_ARRIVAL |
flight_takeoff |
FLIGHT_DEPARTURE |
hotel |
HOTEL |
grade |
HOTEL_ROOM_TYPE |
insert_invitation |
邀請 |
location_on |
MAP_PIN |
card_membership |
會員 |
people |
MULTIPLE_PEOPLE |
person |
PERSON |
local_phone |
電話 |
restaurant |
RESTAURANT_ICON |
shopping_cart |
SHOPPING_CART |
grade |
STAR |
store |
商店 |
local_play |
TICKET |
train |
TRAIN |
videocam |
VIDEO_CAMERA |
play_circle_filled |
VIDEO_PLAY |
在資訊卡中新增文字
本節說明如何在資訊卡中新增及設定文字格式。
新增一段格式化文字
TextParagraph
小工具會顯示一段文字,並可選擇性套用 HTML 格式。設定這些小工具的文字內容時,只要加入對應的 HTML 標記即可。如要進一步瞭解支援的 HTML 標記,請參閱設定資訊卡中顯示的文字格式。
舉例來說,段落文字可套用下列格式:
- 使用 HTML
<b>
、<u>
、<i>
標記,顯示粗體、底線或斜體文字。
- 使用 HTML 連結至網站
<a href="https://www.google.com">hyperlinks</a>
。
- 使用 HTML
<font color="#ea9999">font tags</font>
新增顏色。
每個 TextParagraph
小工具都會以新段落的形式呈現,可視為類似於 HTML <p>
標記。
以下是包含兩個 TextParagraph
小工具的資訊卡,用於顯示兩個段落,並採用簡單的 HTML 格式:
新增可收合的文字段落
使用者可視需要展開文字段落,查看更多資訊。
這個小工具非常適合呈現長篇內容或額外詳細資料,使用者選取後即可探索,打造動態互動式使用者體驗。
顯示含有裝飾性元素的文字
DecoratedText
小工具會顯示文字,並提供選用的版面配置和功能。例如:
- 使用
startIcon
在文字前方顯示 icon
。
- 在文字前顯示標題 (使用
topLabel
)。
- 使用
button
新增可點選的按鈕,或使用 switchControl
新增可切換的切換鈕。
如要以簡單易懂的互動方式呈現資訊,請使用 DecoratedText
小工具。這個小工具非常適合用於聯絡人資訊卡、訂單狀態更新和工作單通知等用途。
DecoratedText
小工具支援簡單的 HTML 文字格式。設定這些小工具的文字內容時,只要加入對應的 HTML 標記即可。如要進一步瞭解支援的 HTML 標記,請參閱訊息格式。
以下是包含 DecoratedText
小工具的資訊卡,用來顯示電子郵件地址、上線狀態、電話號碼和網站等聯絡人詳細資料:
疑難排解
如果 Google Chat 應用程式或資訊卡傳回錯誤,Chat 介面會顯示「發生錯誤」訊息。或「無法處理您的要求」。有時 Chat UI 不會顯示任何錯誤訊息,但 Chat 應用程式或資訊卡會產生非預期的結果,例如資訊卡訊息可能不會顯示。
即使 Chat 使用者介面未顯示錯誤訊息,只要開啟 Chat 應用程式的錯誤記錄功能,系統就會提供說明性錯誤訊息和記錄資料,協助您修正錯誤。如需查看、偵錯及修正錯誤的相關協助,請參閱「排解及修正 Google Chat 錯誤」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[[["\u003cp\u003eThis page guides you on adding and formatting text and images within Google Chat cards to enhance their visual appeal and interactivity.\u003c/p\u003e\n"],["\u003cp\u003eYou can incorporate images, icons, and formatted text paragraphs using various widgets and HTML formatting options.\u003c/p\u003e\n"],["\u003cp\u003eLearn how to use \u003ccode\u003eImage\u003c/code\u003e, \u003ccode\u003eimageComponent\u003c/code\u003e, \u003ccode\u003eIcon\u003c/code\u003e, \u003ccode\u003eTextParagraph\u003c/code\u003e, and \u003ccode\u003eDecoratedText\u003c/code\u003e widgets to build engaging cards.\u003c/p\u003e\n"],["\u003cp\u003eLeverage built-in or custom icons, apply cropping and border styles to images, and add interactive elements like buttons or hyperlinks.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the troubleshooting section for assistance if you encounter any errors while implementing these features.\u003c/p\u003e\n"]]],[],null,["# Add text and images to cards\n\nThis page explains how to add and format text and images to cards.\n\nTo learn more about building cards, see\n[Build cards for Google Chat apps](/workspace/chat/design-components-card-dialog).\n\n\n*** ** * ** ***\n\nUse the Card Builder to design and preview messaging and user interfaces for Chat apps:\n[Open the Card Builder](https://addons.gsuite.google.com/uikit/builder)\n\n*** ** * ** ***\n\n\u003cbr /\u003e\n\nPrerequisites\n-------------\n\n\nA Google Chat app that's configured to receive and respond to [interaction events](/workspace/chat/receive-respond-interactions). To create an\ninteractive Chat app, complete one of the following quickstarts based\non the [app architecture](/workspace/chat/structure) that you want to use:\n\n- [HTTP service](/workspace/chat/quickstart/gcf-app) with Google Cloud Functions\n- [Google Apps Script](/workspace/chat/quickstart/apps-script-app)\n- [Google Cloud Dialogflow CX](/workspace/chat/build-dialogflow-chat-app-natural-language)\n- [Google Cloud Pub/Sub](/workspace/chat/quickstart/pub-sub)\n\nAdd images or icons\n-------------------\n\nThis section explains how to add visual elements to cards such as images,\nimage components, and icons.\n\n### Add an image\n\n[`Image` widget](/workspace/chat/api/reference/rest/v1/cards#image)\ndisplays a PNG or JPG image hosted on an HTTPS URL.\nThe displayed image's width fills the entire width of the displayed card, and\nits height adjusts to maintain the image's aspect ratio. The `Image` widget\nsupports\n[`onclick` actions](/workspace/chat/api/reference/rest/v1/cards#OnClick_1)\nthat occur when users click the image. Example of `onclick` actions include:\n\n- Open a hyperlink with [`OpenLink`](/workspace/chat/api/reference/rest/v1/cards#OpenLink_1), such as a hyperlink to the Google Chat developer documentation, `https://developers.google.com/chat`.\n- Run an [action](/workspace/chat/api/reference/rest/v1/cards#action) that runs a custom function, like calling an API.\n\nThe `Image` widget has the following limitations:\n\n- Only PNG and JPG images are supported.\n- The host URL must be `HTTPS`.\n- To ensure performant cards, maximum recommended image size is 2MB.\n\nThe following is a card consisting of an `Image` widget. It displays the\nGoogle Chat developer documentation landing page image. When users click the\nimage, the Google Chat developer documentation opens in a new tab.\n\n### Add an image component\n\nThe `Image` widget is an image with limited styling. An\n[`imageCompent` widget](/workspace/chat/api/reference/rest/v1/cards#imagecomponent)\nlets you apply `cropStyle` and `borderStyle` to an image.\n\nThe following example shows two images in a grid where one of the images is\ncropped:\n\nYou can adjust the shape of an image component by applying a\n[`cropStyle`](/workspace/chat/api/reference/rest/v1/cards#imagecropstyle).\nThere are several shapes to apply to an image:\n\n- Use `SQUARE` to apply a square crop.\n- Use `CIRCLE` to apply a circular crop.\n- Use `RECTANGLE_CUSTOM` to apply a rectangular crop with a custom aspect ratio. For example, you can use `RECTANGLE_4_3` to apply a rectangular crop with a 4:3 aspect ratio.\n\nThe following example shows five images in a grid with a different `cropStyle`\napplied to each image:\n\n### Add an icon\n\nThe\n[`Icon` widget](/workspace/chat/api/reference/rest/v1/cards#textparagraph)\nrepresents either a\n[built-in](/workspace/chat/format-messages#builtinicons)\nicon or\n[custom](/workspace/chat/format-messages#customicons)\nicon. You add icons to cards to do any of the following:\n\n- Display a standalone icon.\n- Display an icon in front of related text, as part of a [`DecoratedText`](/workspace/chat/decorated-text) widget.\n- Display an icon as an interactive button, as part of a [`ButtonList`](/workspace/chat/button-list) widget.\n\nThe following is a card consisting of an `Icon` component with a built-in icon:\n\nThe following table lists the built-in icons that are available for card messages:\n\n|-------------------|---------------------|---------------------|------------------------------|\n| flight | **AIRPLANE** | bookmark | **BOOKMARK** |\n| directions_bus | **BUS** | directions_car | **CAR** |\n| schedule | **CLOCK** | confirmation_number | **CONFIRMATION_NUMBER_ICON** |\n| subject | **DESCRIPTION** | attach_money | **DOLLAR** |\n| mail | **EMAIL** | event_seat | **EVENT_SEAT** |\n| flight_land | **FLIGHT_ARRIVAL** | flight_takeoff | **FLIGHT_DEPARTURE** |\n| hotel | **HOTEL** | grade | **HOTEL_ROOM_TYPE** |\n| insert_invitation | **INVITE** | location_on | **MAP_PIN** |\n| card_membership | **MEMBERSHIP** | people | **MULTIPLE_PEOPLE** |\n| person | **PERSON** | local_phone | **PHONE** |\n| restaurant | **RESTAURANT_ICON** | shopping_cart | **SHOPPING_CART** |\n| grade | **STAR** | store | **STORE** |\n| local_play | **TICKET** | train | **TRAIN** |\n| videocam | **VIDEO_CAMERA** | play_circle_filled | **VIDEO_PLAY** |\n\nAdd text to a card\n------------------\n\nThis section explains how to add and format text in a card.\n\n### Add a paragraph of formatted text\n\nThe\n[`TextParagraph` widget](/workspace/chat/api/reference/rest/v1/cards#textparagraph)\ndisplays a paragraph of text with optional HTML formatting. When setting\nthe text content of these widgets, just include the corresponding HTML tags.\nFor more information about which HTML tags are supported, see\n[Format text that appears in cards](/workspace/chat/format-messages#card-formatting).\n\nFor example, the following formatting is available for paragraph text:\n\n- Display bold, underlined, or italicized text with HTML `\u003cb\u003e`, `\u003cu\u003e`, `\u003ci\u003e` tags.\n- Link to websites with HTML `\u003ca href=\"https://www.google.com\"\u003ehyperlinks\u003c/a\u003e`.\n- Add some color with HTML `\u003cfont color=\"#ea9999\"\u003efont tags\u003c/font\u003e`.\n\nEach `TextParagraph` widget renders as a new paragraph, and can be thought of\nas similar to an HTML `\u003cp\u003e` tag.\n\nThe following is a card consisting of two `TextParagraph` widgets used to\ndisplay two paragraphs with simple HTML formatting:\n\n#### Add a collapsible text paragraph\n\nThe collapsible text paragraphs let users reveal more information on demand.\nThis widget is perfect for presenting lengthy content or additional details that\ncan be explored when selected, creating a dynamic and interactive user\nexperience.\n\n### Display text with decorative elements\n\nThe\n[`DecoratedText` widget](/workspace/chat/api/reference/rest/v1/cards#DecoratedText)\ndisplays text with optional layout and capabilities. For example:\n\n- Display an `icon` in front of the text with `startIcon`.\n- Show a title before the text with `topLabel`.\n- Add a clickable button with `button` or switchable toggle with `switchControl`.\n\nUse the `DecoratedText` widget when you need to present information in an\neasy-to-consume and interactive way. The widget is perfect for use cases such as\ncontact cards, order status updates, and work ticket notifications.\n\nThe `DecoratedText` widget supports simple text HTML formatting. When setting\nthe text content of these widgets, just include the corresponding HTML tags. For\nmore information about which HTML tags are supported, see\n[Card text formatting](/workspace/chat/format-messages#view_text_formatting_sent_in_a_message).\n\nThe following is a card consisting of a `DecoratedText` widget used to display\ncontact details, such as email address, online status, phone number, and\nwebsite:\n\nTroubleshoot\n------------\n\n\nWhen a Google Chat app or\n[card](/workspace/chat/create-messages#create) returns an error, the\nChat interface surfaces a message saying \"Something went wrong.\"\nor \"Unable to process your request.\" Sometimes the Chat UI\ndoesn't display any error message, but the Chat app or\ncard produces an unexpected result; for example, a card message might not\nappear.\n\n\nAlthough an error message might not display in the Chat UI,\ndescriptive error messages and log data are available to help you fix errors\nwhen error logging for Chat apps is turned on. For help viewing,\ndebugging, and fixing errors, see\n[Troubleshoot and fix Google Chat errors](/workspace/chat/troubleshoot).\n\nRelated topics\n--------------\n\n- [View Chat app samples](/workspace/chat/samples) that use cards.\n- [`Image`](/workspace/chat/api/reference/rest/v1/cards#image)\n- [`imageCompent`](/workspace/chat/api/reference/rest/v1/cards#imagecomponent)\n- [`cropStyle`](/workspace/chat/api/reference/rest/v1/cards#imagecropstyle)\n- [`Icon`](/workspace/chat/api/reference/rest/v1/cards#textparagraph)\n- [`TextParagraph`](/workspace/chat/api/reference/rest/v1/cards#textparagraph)\n- [`DecoratedText`](/workspace/chat/api/reference/rest/v1/cards#DecoratedText)"]]