Skip to content

Commit ef92468

Browse files
committed
feat(open-supportbot): add the openSupportBot API
Improve openChat annotations
1 parent 323b555 commit ef92468

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

src/index.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,16 @@ export function hideMessenger() {
352352
}
353353

354354
/**
355-
* Opens a chat within the messenger.
355+
* Opens a chat interface
356356
*
357-
* - For an empty chatId, a new chat is opened. Any provided message appears in the chat input. If the support bot is active, it will initiate.
358-
* - If a chat with the provided chatId exists, that chat will open, and any message will be ignored.
359-
* - If a chat doesn't exist, the home is opened.
360-
* - Note: Using this function outside a click event handler may lead to issues on iOS Safari.
357+
* - Reveals the `messenger` if hidden.
358+
* - For an undefined `chatId`, a new chat is created. Any provided `message` populates the chat input. The support bot initializes if active.
359+
* - If a chat with the given `chatId` exists, the chat will open, and the `message` parameter will be disregarded.
360+
* - If no matching chat exists, the `home` view opens.
361+
* - Caution: Utilizing this function outside a click event may cause issues in iOS Safari.
361362
*
362-
* @param {string | number | undefined} chatId - The ID of the chat to open.
363-
* @param {string | undefined} message - Message to appear in the chat input.
363+
* @param {string | number | undefined} chatId - ID of the chat to reveal.
364+
* @param {string | undefined} message - Optional text to populate the chat input field.
364365
* @see https://developers.channel.io/docs/web-channelio#openchat
365366
*/
366367
export function openChat(chatId?: string | number, message?: string) {
@@ -375,6 +376,32 @@ export function openChat(chatId?: string | number, message?: string) {
375376
window.ChannelIO('openChat', chatId, message);
376377
}
377378

379+
/**
380+
* Initiates a chat by triggering a specified support bot.
381+
*
382+
* - Reveals the `messenger` if hidden.
383+
* - Activates the support bot identified by the given `supportBotId`.
384+
* - No action is taken if `supportBotId` is not specified.
385+
* - Shows an error page if a support bot with the specified `supportBotId` does not exist.
386+
* - Populates the chat input with `message` upon support bot completion if provided.
387+
* - Caution: Utilizing this function outside a click event may cause issues in iOS Safari.
388+
*
389+
* @param {string} supportBotId - Identifier of the targeted support bot.
390+
* @param {string | undefined} message - Optional message to populate the chat input field post support bot action.
391+
* @see https://developers.channel.io/docs/web-channelio#opensupportbot
392+
*/
393+
export function openSupportBot(supportBotId: string, message?: string) {
394+
if(isSSR) {
395+
console.error('openSupportBot is only executable on browser.');
396+
return;
397+
}
398+
if(!window.ChannelIO) {
399+
console.error('ChannelIO is not loaded. Please call loadScript() before openSupportBot().');
400+
return;
401+
}
402+
window.ChannelIO('openSupportBot', supportBotId, message);
403+
}
404+
378405
export interface EventProperty {
379406
[key: string]: string | number | boolean | null;
380407
}

0 commit comments

Comments
 (0)