Class DecoratedText

DecoratedText

這個小工具會顯示文字,並可選擇加上裝飾。可能的按鍵包括圖示、上方標籤和下方標籤。使用 setText(text)DecoratedTextDecoratedTextsetTopLabel(text)setBottomLabel(text) 其中一個鍵,設定文字內容和其中一個鍵。這個類別旨在取代 KeyValue

適用於 Google Workspace 外掛程式和 Google Chat 應用程式。

const decoratedText =
    CardService.newDecoratedText().setText('Text').setTopLabel('TopLabel');

const multilineDecoratedText = CardService.newDecoratedText()
                                   .setText('Text')
                                   .setTopLabel('TopLabel')
                                   .setWrapText(true)
                                   .setBottomLabel('BottomLabel');

方法

方法傳回類型簡短說明
addEventAction(eventAction)Widget新增可在小工具上執行的事件動作。
setAuthorizationAction(action)DecoratedText設定授權動作,在點選物件時開啟授權流程的網址。
setBottomLabel(text)DecoratedText設定要當做鍵使用的標籤文字,並顯示在文字內容下方。
setButton(button)DecoratedText設定顯示在文字右側的 Button
setComposeAction(action, composedEmailType)DecoratedText設定動作,在點選物件時撰寫電子郵件草稿。
setEndIcon(endIcon)DecoratedText設定顯示在內容右側的選用 IconImage
setId(id)Widget設定指派的專屬 ID,用於識別要變動的小工具。
setOnClickAction(action)DecoratedText設定在點選物件時執行的動作。
setOnClickOpenLinkAction(action)DecoratedText設定動作,在點選物件時於分頁中開啟網址。
setOpenLink(openLink)DecoratedText設定點選物件時要開啟的網址。
setStartIcon(startIcon)DecoratedText設定要在文字內容前顯示的選用 IconImage
setSwitchControl(switchToSet)DecoratedText設定顯示在內容右側的 Switch
setText(text)DecoratedText設定要用做值使用的文字。
setTopLabel(text)DecoratedText設定要用做鍵的標籤文字,並顯示在文字內容上方。
setVisibility(visibility)Widget設定小工具的顯示設定。
setWrapText(wrapText)DecoratedText設定值文字應顯示在一行或多行。

內容詳盡的說明文件

addEventAction(eventAction)

新增可在小工具上執行的事件動作。

參數

名稱類型說明
eventActionEventAction要新增的 EventAction

回攻員

Widget - 鏈結用的物件。


setAuthorizationAction(action)

設定授權動作,在點選物件時開啟授權流程的網址。系統隨即會在新視窗中開啟網址。使用者完成授權流程並返回應用程式後,外掛程式會重新載入。

UI 物件只能設定 setOpenLink(openLink)setOnClickAction(action)setOnClickOpenLinkAction(action)setAuthorizationAction(action)setComposeAction(action, composedEmailType) 的其中一個。

// ...

const action = CardService.newAuthorizationAction().setAuthorizationUrl('url');
CardService.newTextButton().setText('Authorize').setAuthorizationAction(action);

參數

名稱類型說明
actionAuthorizationAction這個物件會指定點選這個元素時要採取的授權動作。

回攻員

DecoratedText - 這個物件,用於鏈結。


setBottomLabel(text)

設定要當做鍵使用的標籤文字,並顯示在文字內容下方。

參數

名稱類型說明
textString標籤文字。

回攻員

DecoratedText - 這個物件,用於鏈結。


setButton(button)

設定顯示在文字右側的 ButtonDecoratedText 只能支援一個按鈕或一個切換鈕。

參數

名稱類型說明
buttonButton新增按鈕。

回攻員

DecoratedText - 這個物件,用於鏈結。


setComposeAction(action, composedEmailType)

設定動作,在點選物件時撰寫電子郵件草稿。UI 物件只能設定 setOpenLink(openLink)setOnClickAction(action)setOnClickOpenLinkAction(action)setAuthorizationAction(action)setComposeAction(action, composedEmailType) 的其中一個。

Action 參數必須指定回呼函式,該函式會傳回使用 ComposeActionResponseBuilder.setGmailDraft(draft) 設定的 ComposeActionResponse 物件。

// ...

const action = CardService.newAction().setFunctionName('composeEmailCallback');
CardService.newTextButton()
    .setText('Compose Email')
    .setComposeAction(action, CardService.ComposedEmailType.REPLY_AS_DRAFT);

// ...

function composeEmailCallback(e) {
  const thread = GmailApp.getThreadById(e.threadId);
  const draft = thread.createDraftReply('This is a reply');
  return CardService.newComposeActionResponseBuilder()
      .setGmailDraft(draft)
      .build();
}

參數

名稱類型說明
actionAction這個物件會指定點選這個元素時要採取的撰寫動作。
composedEmailTypeComposedEmailType列舉值,用於指定撰寫的草稿是獨立草稿還是回覆草稿。

回攻員

DecoratedText - 這個物件,用於鏈結。


setEndIcon(endIcon)

設定顯示在內容右側的選用 IconImageDecoratedText 只能支援一個按鈕、一個切換鈕或一個圖示。

參數

名稱類型說明
endIconIconImage要新增的圖示。

回攻員

DecoratedText - 這個物件,用於鏈結。


setId(id)

設定指派的專屬 ID,用於識別要變動的小工具。外掛程式僅支援小工具突變。

參數

名稱類型說明
idString小工具的 ID,最多 64 個字元,格式為 `[a-zA-Z0-9-]+`。

回攻員

Widget - 這個物件,用於鏈結。


setOnClickAction(action)

設定在點選物件時執行的動作。UI 物件只能設定 setOpenLink(openLink)setOnClickAction(action)setOnClickOpenLinkAction(action)setAuthorizationAction(action)setComposeAction(action, composedEmailType) 的其中一個。

Action 參數必須指定會傳回 ActionResponse 物件的回呼函式。

// ...

const action = CardService.newAction().setFunctionName('notificationCallback');
CardService.newTextButton()
    .setText('Create notification')
    .setOnClickAction(action);

// ...

function notificationCallback() {
  return CardService.newActionResponseBuilder()
      .setNotification(
          CardService.newNotification().setText('Some info to display to user'),
          )
      .build();
}

參數

名稱類型說明
actionAction點選這個元素時要採取的動作。

回攻員

DecoratedText - 這個物件,用於鏈結。


setOnClickOpenLinkAction(action)

設定動作,在點選物件時於分頁中開啟網址。如果需要建構網址,或除了建立 OpenLink 物件外,還需要採取其他動作,請使用這個函式。UI 物件只能設定 setOpenLink(openLink)setOnClickAction(action)setOnClickOpenLinkAction(action)setAuthorizationAction(action)setComposeAction(action, composedEmailType) 其中一個。

Action 參數必須指定回呼函式,該函式會傳回使用 ActionResponseBuilder.setOpenLink(openLink) 設定的 ActionResponse 物件。

// ...

const action = CardService.newAction().setFunctionName('openLinkCallback');
CardService.newTextButton()
    .setText('Open Link')
    .setOnClickOpenLinkAction(action);

// ...

function openLinkCallback() {
  return CardService.newActionResponseBuilder()
      .setOpenLink(CardService.newOpenLink().setUrl('https://www.google.com'))
      .build();
}

參數

名稱類型說明
actionAction這個物件會指定點選這個元素時要採取的開啟連結動作。

回攻員

DecoratedText - 這個物件,用於鏈結。


設定在點選物件時開啟的網址。如果網址已知且只需要開啟,請使用這項函式。UI 物件只能設定 setOpenLink(openLink)setOnClickAction(action)setOnClickOpenLinkAction(action)setAuthorizationAction(action)setComposeAction(action, composedEmailType) 其中一個。

參數

名稱類型說明
openLinkOpenLink說明要開啟網址的 OpenLink 物件。

回攻員

DecoratedText - 這個物件,用於鏈結。


setStartIcon(startIcon)

設定要在文字內容前顯示的選用 IconImage

參數

名稱類型說明
startIconIconImage要顯示的圖示。

回攻員

DecoratedText - 這個物件,用於鏈結。


setSwitchControl(switchToSet)

設定顯示在內容右側的 SwitchDecoratedText 只能支援一個按鈕或一個切換鈕。

參數

名稱類型說明
switchToSetSwitch要新增的切換鈕。

回攻員

DecoratedText - 這個物件,用於鏈結。


setText(text)

設定要用做值使用的文字。支援基本 HTML 格式。必填。

參數

名稱類型說明
textString這項小工具的文字內容。

回攻員

DecoratedText - 這個物件,用於鏈結。


setTopLabel(text)

設定要用做鍵的標籤文字,並顯示在文字內容上方。

參數

名稱類型說明
textString標籤文字。

回攻員

DecoratedText - 這個物件,用於鏈結。


setVisibility(visibility)

設定小工具的顯示設定。預設值為 `VISIBLE`。

參數

名稱類型說明
visibilityVisibility小工具的 Visibility

回攻員

Widget - 鏈結用的物件。


setWrapText(wrapText)

設定值文字應顯示在一行或多行。

參數

名稱類型說明
wrapTextBoolean如為 true,文字會換行並顯示在多行中。否則文字會遭到截斷。

回攻員

DecoratedText - 這個物件,用於鏈結。