Skip to main content
Answered

@intercom/messenger-js-sdk with React


We are trying to use official @intercom/messenger-js-sdk with our react app.

https://www.npmjs.com/package/@intercom/messenger-js-sdk

We are calling Intercom instance in our App component

  Intercom({
    app_id: ...,
  });

and then updating user info when user data is available using following functions:
import { boot, shutdown, update } from "@intercom/messenger-js-sdk";

 

when there is no user data we are calling boot with only id,

boot({
    "app_id": "...",
})

and if there is user data, we are passing required properties to boot function

boot({
    "app_id": "...",
    "user_id": "...",
    "name": "...",
    "email": "...@......",
    "created_at": ....,
})

 

It seems that when calling with boot({ "app_id": "..."}), user data is not cleared and in chat we continue to receive messages as if user is still logged in.

Once boot() is called with user data, can it be rebooted with no data (for example, in scenario if user is logged out from our app and we want new chat instance without user data)?

 

Also, if the boot function is called before Intercom({ id: ... }) finishes initialising, Intercom functions (boot, shutdown, update) cease to work indefinitely and completely. This issue is evidenced by the lack of network calls when inspected, and the shutdown function failing to close the widget.

use case:

import Intercom from "@intercom/messenger-js-sdk";

function App() {
...

Intercom({
    app_id: ...,
  });

...
// custom hook that utilises Intercom functions
useIntercomInit(userData);
...

 

When using unofficial https://github.com/devrnt/react-use-intercom , everything seems to work without problems. Is there a way to resolve and achieve this with official sdk - @intercom/messenger-js-sdk?

Best answer by cameron.gumley

Hi @dev-mo -- Cam from the Intercom Support Engineering team here. 

Looks like you’ve been in touch with one of my teammates, Manuel, via Messenger who’s been able to get you some more details on this 👍

As Manuel mentioned, when using this npm package, you’ll want to use the hardShutdown API method (as described here) to close a logged-in Users session and clear their User data prior to make the “boot({ "app_id": "..."})” call you referenced in your message. 

View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+4
  • Intercom Team
  • 109 replies
  • Answer
  • May 31, 2024

Hi @dev-mo -- Cam from the Intercom Support Engineering team here. 

Looks like you’ve been in touch with one of my teammates, Manuel, via Messenger who’s been able to get you some more details on this 👍

As Manuel mentioned, when using this npm package, you’ll want to use the hardShutdown API method (as described here) to close a logged-in Users session and clear their User data prior to make the “boot({ "app_id": "..."})” call you referenced in your message. 


My team is also using the “@intercom/messenger-js-sdk” package from the docs in a react app.

We are calling the update method when some user data changes, but that is never reflected in intercomSettings or in the user data on the intercom side


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings