Answered

@intercom/messenger-js-sdk with React

  • 20 May 2024
  • 1 reply
  • 538 views

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?

icon

Best answer by cameron.gumley 31 May 2024, 14:49

View original

1 reply

Userlevel 3
Badge +4

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. 

Reply