

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Amazon Connect 中支援的可自訂小工具程式碼片段欄位
<a name="supported-snippet-fields"></a>

下表列出您可以自訂的通訊小工具程式碼片段。表格後面的範例程式碼顯示如何使用程式碼片段欄位。


| 程式碼片段欄位 | Type | 說明 | 其他文件 | 
| --- | --- | --- | --- | 
| `snippetId` | String | 強制，自動產生 | N/A | 
| `styles` | String | 強制，自動產生 | N/A | 
| `supportedMessagingContentTypes` | 陣列 | 強制，自動產生 | N/A | 
| `customLaunchBehavior` | 物件 | 自訂網站呈現和啟動託管小工具圖示的方式 | [為託管於 Amazon Connect 中的網站自訂小工具啟動行為和按鈕圖示](customize-widget-launch.md)，本主題稍後 | 
| `authenticate` | 函式 | 在您的網站上啟用 JWT 安全性的回調函數 | [步驟 2：指定您希望顯示通訊小工具的網站網域](add-chat-to-website.md#chat-widget-domains)，在本節前面。 | 
| `customerDisplayName` | 函式 | 在聊天初始化時傳遞客戶顯示名稱 | [在 Amazon Connect 聊天啟動時傳遞客戶顯示名稱](pass-display-name-chat.md)，本節稍後。 | 
| `customStyles` | 物件 | 覆寫預設的 CSS 樣式 | [在 Amazon Connect 中傳遞自訂屬性以覆寫通訊小工具中的預設值](pass-custom-styles.md)，本節稍後。 | 
| `chatDurationInMinutes` | Number | 新開始聊天工作階段的總持續時間 | 預設值：1500 - 最少 60，最大：10080 | 
| `enableLogs` | Boolean | 啟用偵錯工具 | 預設：false | 
| `language` | String | Amazon Connect 可以為支援的 ISO-639 格式語言代碼進行翻譯。如需詳細資訊，請參閱 [ https://en.wikipedia.org/wiki/List\_of\_ISO\_639-1\_codes](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)。這不會翻譯自訂文字覆寫和訊息內容 (包括傳送的和接收的)。 | 預設值：en\_US。支援：'cs\_CZ'、'da\_DK'、'de\_DE'、'en\_AU'、'en\_CA'、'en\_GB'、'en\_US'、'es\_ES'、'fi\_FI'、'fr\_FR'、'hu\_HU'、'id\_ID'、'it\_IT'、'ja\_JP'、'ko\_KR'、'nl\_NL'、'nn\_NO'、'pt\_BR'、'pt\_PT'、'sk\_SK'、'sv\_SE'、'zh\_CN'、'zh\_TW' | 
| `disableCSM` | Boolean | 停用從通訊小工具追蹤用戶端指標的功能。 | 預設：false | 
| `nonce` | String | iframe 與客戶網站 csp 政策之間的握手值。範例：客戶 csp 允許 1234 隨機數值，拉入另一個腳本的 iframe 必須具有相同的 1234 隨機數值，讓瀏覽器知道是 iframe 父站點的可信任腳本。 | 預設值：未定義 | 
| `customizationObject` | 物件 | 自訂小工具版面配置和文字記錄 | 如需詳細資訊，請參閱本節稍後的 [Amazon Connect 聊天小工具的其他自訂](pass-customization-object.md)。 | 
| `contactAttributes` | 物件 | 直接從程式碼片段將屬性傳遞至聯絡流程，無需任何 JWT 設定 | 如需詳細資訊，請參閱[在聊天初始化時傳遞聯絡屬性](https://docs.aws.amazon.com/connect/latest/adminguide/pass-contact-attributes-chat.html)。 | 
| `customDisplayNames` | 物件 | 覆寫在 Amazon Connect 管理員網站中設定的系統或機器人顯示名稱和標誌組態。 | 如需詳細資訊，請參閱[如何覆寫通訊小工具的系統與機器人顯示名稱和標誌](https://docs.aws.amazon.com/connect/latest/adminguide/pass-custom-styles.html#pass-override-system)。 | 
| `contactMetadataHandler` | 函式 | 用來存取 contactId 的回呼函數。例如，新增事件接聽程式以處理如下的案例：在瀏覽器索引標籤關閉時使用 contactId 呼叫 StopContact 函數，或使用先前的 contactId 保有聊天持續性。 |  | 
| `registerCallback` | 物件 | 這樣可以為公開生命週期事件執行回呼。<br />如需詳細資訊，請參閱 [amazon-connect-chatjs](https://github.com/amazon-connect/amazon-connect-chatjs)。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/connect/latest/adminguide/supported-snippet-fields.html) | 
| `initialMessage` | String | 要傳送至新建立聊天的訊息。長度限制：最小值為 1，最大值為 1024。 | 若要使用初始訊息來調用在聯絡流程中設定的 Lex 機器人，請選取**使用訊息初始化機器人**選項來修改[取得客戶輸入流程區塊](get-customer-input.md)。如需詳細資訊，請參閱[如何設定取得客戶輸入流程區塊](get-customer-input.md#get-customer-input-properties)。 | 
| `authenticationParameters` | 物件 | 這會啟用 [驗證客戶](authenticate-customer.md) 流程區塊 | 如需詳細資訊，請參閱[啟用客戶身分驗證](enable-connect-managed-auth.md)。 | 
| `mockLexBotTyping` | Boolean | 為 Lex Bot 訊息啟用模擬輸入指標。 | 預設：false | 
| `customStartChat` | 函式 | 從您的後端呼叫 Start Chat API 的回呼函數。 | 如需詳細資訊，請參閱[使用自訂 Start Chat API 的託管小工具 UI](https://github.com/amazon-connect/amazon-connect-chat-interface#option-3-hosted-widget-ui-with-custom-start-chat-api)  | 

下列範例會示範如何將程式碼片段欄位新增至 HTML 指令碼，以將聊天小工具新增至您的網站。

```
(function(w, d, x, id) {   /* ... */})(window, document, 
'amazon_connect', 'widgetId');
 amazon_connect('snippetId', 'snippetId');
 amazon_connect('styles', /* ... */);
 amazon_connect('registerCallback', {
    // Custom event example
    // WIDGET_FRAME_CLOSED
    /**
     * This event is triggered when user clicks on the chat widget close button, 
     * either widget close button was clicked when error in the chat session or normally by the user. 
     * This event can be used for webview use cases to go back to main app
     * 
     * @param {string} status - The reason for widget closure
     *   - "error_chat": Indicates the user clicked on widget close button due to an error in the chat session
     *   - "close_chat": Indicates the user clicked on widget close button normally by the user
     */
    'WIDGET_FRAME_CLOSED': (eventName, { status }) => {
        // You can implement custom logic based on the status value(error_chat or close_chat)
        if (status == "error_chat") {
            // handle error chat
        } else if (status == "close_chat") {
            // handle close chat  
        } 
    },
    // System event example
    /**
     * chatDetails: { 
     *     contactId: string, 
     *     participantId: string,
     *     participantToken: string,
     * }
     * data: {
     *     AbsoluteTime?: string,
     *     ContentType?: string,
     *     Type?: string,
     *     ParticipantId?: string,
     *     DisplayName?: string,
     *     ParticipantRole?: string,
     *     InitialContactId?: string
     * }
     */
    'PARTICIPANT_JOINED': (eventName, { chatDetails, data }) => {
        alert(`${data.ParticipantRole} joined the chat.`);
    },
    'event_Name_3': callback(function),
    'event_Name_4': callback(function),
    // ...
}); 
amazon_connect('initialMessage', 'Your initial message string');
// ... 
amazon_connect('snippetFieldHere', /* ... */);
<script/>
```