import { IntercomSettings, intercomPoll } from './core' import { shell } from './shell' class Intercom { /** * Calling the update method with a JSON object of user details will update those fields on the current user in addition to logging an impression at the current URL and looking for new messages for the user. * * ## @example * * ```tsx * import { intercom } from `vtex.admin-shell-utils` * // other necessary imports here... * * const App = () => { * const { navigate } = useRuntime() * * return ( *
* ) *} * ``` * */ public update(intercomSettings: IntercomSettings) { intercomPoll(() => { shell.intercomSettings = { ...shell.intercomSettings, ...intercomSettings, } shell.Intercom!('update') }) } /** * If you have the Inbox product (combined with another product like Messages) you should call the Intercom shutdown method to clear your users’ conversations anytime they logout of your application. * Otherwise, the cookie we use to track who was most recently logged in on a given device or computer will keep these conversations in the Messenger for one week. * This method will effectively clear out any user data that you have been passing through the JS API. * * * ## @example * * ```tsx * import { intercom } from `vtex.admin-shell-utils` * // other necessary imports here... * * const App = () => { * return ( * * ) *} * ``` * */ public shutdown() { intercomPoll(() => shell.Intercom!('shutdown')) } /** * This will hide the main Messenger panel if it is open. It will not hide the Messenger Launcher. * * ## @example * * ```tsx * import { intercom } from `vtex.admin-shell-utils` * // other necessary imports here... * * const App = () => { * return ( * * ) *} * ``` * */ public hide() { intercomPoll(() => shell.Intercom!('hide')) } /** * This will show the Messenger. If there are no new conversations, it will open to the Messenger Home. If there are, it will open with the message list. * * ## @example * * ```tsx * import { intercom } from `vtex.admin-shell-utils` * // other necessary imports here... * * const App = () => { * return ( * * ) *} * ``` * */ public show() { intercomPoll(() => shell.Intercom!('show')) } /** * This will open the Messenger with the message list. * * ## @example * * ```tsx * import { intercom } from `vtex.admin-shell-utils` * // other necessary imports here... * * const App = () => { * return ( * * ) *} * ``` * */ public showMessages() { intercomPoll(() => shell.Intercom!('showMessages')) } /** * If you would like to trigger a tour based on an action a user or visitor takes in your site or application, you can use this API method. You need to call this method with the id of the tour you wish to show. The id of the tour can be found in the “Use tour everywhere” section of the tour editor. * Please note that tours shown via this API must be published and the “Use tour everywhere” section must be turned on. If you're calling this API using an invalid tour id, nothing will happen. * * ## @example * * ```tsx * import { intercom } from `vtex.admin-shell-utils` * // other necessary imports here... * * const App = () => { * useEffect(() => { * intercom.startTour(123) * }, []) * * return ( *