svelte-intercom v0.0.35
Svelte Intercom
Installation
npm install svelte-intercom
# pnpm add svelte-intercom
# yarn add svelte-intercomUsage
- Add the
IntercomProvidercomponent to your root layout
<!-- +layout.svelte -->
<script>
import {IntercomProvider} from 'svelte-intercom';
let {children} = $props();
</script>
<IntercomProvider
appId="yourAppId"
autoboot
bootOptions={{
actionColor: '#0f172a',
backgroundColor: '#475569',
}}
>
{@render children()}
</IntercomProvider>- use the
useIntercomstore
<!-- +page.svelte -->
<script>
import {useIntercom} from 'svelte-intercom';
const intercom = useIntercom();
</script>
<button
onclick={function () {
intercom.hide();
}}
>
Hide
</button>
<button
onclick={function () {
intercom.show();
}}
>
Show
</button>
<button
onclick={function () {
intercom.boot();
}}
>
Boot
</button>
<button
onclick={function () {
intercom.shutdown();
}}
>
Shutdown
</button>API Reference
IntercomProvider
Props
appIdYour intercom app ID
regionYour intercom app region
apiBaseYour intercom app api base
autobootWhether to boot intercom automatically
bootOptionsGlobal boot options. will be used everytime
bootis called including whenautobootis set totrueonHideCallback when messenger is hidden
onShowCallback when messenger is visible
onUserEmailSuppliedCallback when user supplied thier email in the messenger
onUnreadCountChangeCallback when unread messages count changes
useIntercom
the useIntercom does not accept anything and returns the following methods:
bootThe boot function can be used if at somepoint the shutdown function was called or
autobootis set tofalse.rebootCalls
shutdownthenbootreboot.softSimilar to
rebootexcept this will use the previously captured options fromupdate/bootshutdownIf 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.
shutdown.softSimilar to shutdown except this will not clear previously captured options from
update/bootso that it can be used on subsequent calls tobootshowThis 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.
hideThis will hide the main Messenger panel if it is open
showNewsIf you would like to trigger a news item in the Messenger, you can use the
showNewsmethod. The news item will be shown within the Messenger, and clicking the Messenger back button will return to the previous context. If the Messenger is closed when the method is called, it will be opened first and then the news item will be shown.showSpaceThis will open the Messenger as if a new conversation was just created.
startTourIf 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.
trackEventYou can submit an event using the
trackEventmethod. This will associate the event with the currently logged in user and send it to IntercomshowTicketIf you would like to trigger a ticket in the Messenger, you can use the
showTicketmethod. The ticket will be shown within the Messenger, and clicking the Messenger back button will return to the previous context. If the Messenger is closed when the method is called, it will be opened first and then the ticket will be shown.startSurveyIf you would like to trigger a survey in the Messenger, you can use the
startSurveymethod. The id of the survey can be found in the Additional ways to share your survey section of the survey editor as well as in the URL of the editor.showArticleIf you would like to trigger an article in the Messenger, you can use the
showArticlemethod. The article will be shown within the Messenger, and clicking the Messenger back button will return to the previous context. If the Messenger is closed when the method is called, it will be opened first and then the article will be shown.getVisitorIdA visitor is someone who goes to your site but does not use the messenger. You can track these visitors via the visitor user ID. This user ID can be used to retrieve the visitor or lead through the REST API.
showMessagesThis will open the Messenger on the message list session
showNewMessageThis will open the Messenger as if a new conversation was just created
startChecklistIf you would like to trigger a checklist in the Messenger, you can use the
startChecklistmethod. The id of the checklist can be found in the Additional ways to share your checklist section of the checklist editor as well as in the URL of the editor.showConversationYou can show a conversation programatically in the Messenger by calling
showConversationmethodhiddenWhether the messenger is hidden or not
getLauncherPropsReturns button props which can be used for custom launcher
<script> import {useIntercom} from 'svelte-intercom'; let intercom = useIntercom() </script> <button {...intercom.getLauncherProps()}> <ChatIcon /> <button>
Related
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago