

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# Amazon Connect 中支持可自定义的小部件片段字段
<a name="supported-snippet-fields"></a>

下表列出了可以自定义的通信小部件片段字段。表格之后的代码示例显示了如何使用片段字段。


| 片段字段 | Type | 说明 | 其他文档 | 
| --- | --- | --- | --- | 
| `snippetId` | 字符串 | 必填，自动生成 | 不适用 | 
| `styles` | 字符串 | 必填，自动生成 | 不适用 | 
| `supportedMessagingContentTypes` | 数组 | 必填，自动生成 | 不适用 | 
| `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` | 数字 | 新开始的聊天会话的总时长 | 默认值：1500 - 最小 60，最大：10080 | 
| `enableLogs` | 布尔值 | 启用调试日志 | 默认：false | 
| `language` | 字符串 | 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` | 布尔值 | 禁止从通信小部件跟踪客户端指标。 | 默认：false | 
| `nonce` | 字符串 | 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_cn/connect/latest/adminguide/supported-snippet-fields.html) | 
| `initialMessage` | 字符串 | 要发送到新建聊天室的消息。长度限制：最小为 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` | 布尔值 | 为 Lex 机器人消息启用模拟键入指示器。 | 默认：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/>
```