-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathshopper-agent-utils.js
More file actions
49 lines (45 loc) · 1.31 KB
/
shopper-agent-utils.js
File metadata and controls
49 lines (45 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2025, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
const onClient = typeof window !== 'undefined'
/**
* Launch the chat using the embedded service bootstrap API
*
* @function launchChat
* @returns {void}
*/
export function launchChat() {
if (!onClient) return
try {
// Launch chat using the embedded service bootstrap API
if (
window.embeddedservice_bootstrap &&
typeof window.embeddedservice_bootstrap.utilAPI.launchChat === 'function'
) {
window.embeddedservice_bootstrap.utilAPI.launchChat()
}
} catch (error) {
console.error('Shopper Agent: Error launching chat', error)
}
}
/**
* Open the shopper agent chat window
*
* Programmatically opens the embedded messaging widget by finding and clicking
* the embedded service chat button. This function can be called from custom
* UI elements like header buttons.
*
* @function openShopperAgent
* @returns {void}
*/
export function openShopperAgent() {
if (!onClient) return
try {
launchChat()
} catch (error) {
console.error('Shopper Agent: Error opening agent', error)
}
}