@@ -352,15 +352,16 @@ export function hideMessenger() {
352
352
}
353
353
354
354
/**
355
- * Opens a chat within the messenger.
355
+ * Opens a chat interface
356
356
*
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.
361
362
*
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 .
364
365
* @see https://developers.channel.io/docs/web-channelio#openchat
365
366
*/
366
367
export function openChat ( chatId ?: string | number , message ?: string ) {
@@ -375,6 +376,32 @@ export function openChat(chatId?: string | number, message?: string) {
375
376
window . ChannelIO ( 'openChat' , chatId , message ) ;
376
377
}
377
378
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
+
378
405
export interface EventProperty {
379
406
[ key : string ] : string | number | boolean | null ;
380
407
}
0 commit comments