
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@intercom/messenger-js-sdk
Advanced tools
JS wrapper for easy use of our Messenger Client API on various commonly used web frameworks
$ npm install @intercom/messenger-js-sdk
or
yarn add @intercom/messenger-js-sdk
import Intercom from "@intercom/messenger-js-sdk";
If you have a React Remix project, please install Intercom via the named export like this:
import { Intercom } from "@intercom/messenger-js-sdk";
// ...
export default MyPage = () => {
Intercom({
app_id: constants.intercom_app_id,
user_id: user.id,
name: user.name,
email: user.email,
created_at: user.createdAt,
});
// ...
};
The package keeps track of any instances needed internally, therefore re-renders due to DOM changes won't trigger re-boot of the messenger.
import Intercom from "@intercom/messenger-js-sdk";
// ...
export class MyPage {
constructor() {
Intercom({
app_id: constants.intercom_app_id,
user_id: user.id,
name: user.name,
email: user.email,
created_at: user.createdAt,
});
}
// ...
}
The package keeps track of any instances needed internally, therefore re-renders due to DOM changes won't trigger re-boot of the messenger.
<script setup>
import Intercom from "@intercom/messenger-js-sdk";
Intercom({
app_id: constants.intercom_app_id,
user_id: user.id,
name: user.name,
email: user.email,
created_at: user.createdAt,
});
</script>
import Intercom from "@intercom/messenger-js-sdk";
Intercom({
app_id: constants.intercom_app_id,
user_id: user.id,
name: user.name,
email: user.email,
created_at: user.createdAt,
});
All methods described bellow can only be called after calling the initialization method Intercom({...}).
showimport { show } from '@intercom/messenger-js-sdk';
// ...
show()
This will show the Messenger ( it is called by default after initialization). If there are no new conversations, it will open to the Messenger Home. If there are, it will open with the message list.
shutdownIf 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.
import { shutdown } from '@intercom/messenger-js-sdk';
// ...
shutdown()
Deleting cookies
If you need to delete cookies created by the Messenger but are unable to use this method (e.g. because our JavaScript hasn’t been loaded), all cookies are prefixed with intercom- and are created on your domain.
updateCalling the update method with some new user data will trigger the JavaScript to look for new messages that should be displayed to the current user (the one whose details are in the window.intercomSettings variable) and show them if they exist.
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.
import { update } from '@intercom/messenger-js-sdk';
// ...
update({"name": "Inigo Montoya"});
hideThis will hide the main Messenger panel if it is open. It will not hide the Messenger Launcher.
import { hide } from '@intercom/messenger-js-sdk';
// ...
hide();
showThis 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.
import { show } from '@intercom/messenger-js-sdk';
// ...
show();
showSpaceThis 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.
import { showSpace } from "";
// ...
showSpace("home");
showSpace("messages");
showSpace("help");
showSpace("news");
showSpace("tasks");
showSpace("tickets"); // ...
showMessagesThis will open the Messenger on the message list session
import { showMessages } from '@intercom/messenger-js-sdk';
// ...
showMessages();
showNewMessageThis will open the Messenger as if a new conversation was just created.
This function can also take an optional second parameter, used to pre-populate the message composer as shown in the code example below:
No pre-populated message:
import { showNewMessage } from '@intercom/messenger-js-sdk';
// ...
showNewMessage();
With pre-populated message (only available with inbox product) :
import { showNewMessage } from '@intercom/messenger-js-sdk';
// ...
showNewMessage('pre-populated content');
onHide, onShowWhen we hide/show the messenger, you assign a callback hook into this event. This requires a function argument.
import { onHide, onShow } from "@intercom/messenger-js-sdk";
// ...
onHide(myOnHideCallback);
// ...
onShow(myOnShowCallback);
onUnreadCountChangeThis method allows you to register a function that will be called immediately when invoked, and again whenever the current number of unread messages changes.
import { onUnreadCountChange } from "@intercom/messenger-js-sdk";
// ...
onUnreadCountChange(function (unreadCount) {
// Do stuff...
});
hideNotificationsThis method allows you to control the visibility of notifications from messenger.
import { hideNotifications } from "@intercom/messenger-js-sdk";
// Hide notifications
hideNotifications(true);
// Show notifications
hideNotifications(false);
whoamiRetrieves the current user info from the session
import { whoami } from "@intercom/messenger-js-sdk";
// ...
var currentUser = whoami();
trackEventYou can submit an event using the trackEvent method. This will associate the event with the currently logged in user and send it to Intercom. The final parameter is a map that can be used to send optional metadata about the event.
You can also add custom information to events in the form of event metadata, which can be included in event based messages to your customers.
Without metadata:
import { trackEvent } from "@intercom/messenger-js-sdk";
// ...
trackEvent("event-name");
With metadata:
import { trackEvent } from "@intercom/messenger-js-sdk";
// ...
var exampleMetadata = {
invitee_email: "pi@example.org",
invite_code: "ADDAFRIEND",
};
// ...
trackEvent("event-name", exampleMetadata);
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.
import { getVisitorId } from "@intercom/messenger-js-sdk";
// ...
var currentVisitorID = getVisitorId();
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.
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. Nothing will happen if you call this API on mobile web as tours currently do not work on mobile.
import { startTour } from "@intercom/messenger-js-sdk";
// ...
startTour(tourId);
showArticleIf you would like to trigger an article in the Messenger, you can use the showArticle method. 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.
import { showArticle } from "@intercom/messenger-js-sdk";
// ...
showArticle(articleId);
showNewsIf you would like to trigger a news item in the Messenger, you can use the showNews method. 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.
import { showNews } from "@intercom/messenger-js-sdk";
// ...
showNews(newsItemId);
startSurveyIf you would like to trigger a survey in the Messenger, you can use the startSurvey method. 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.
Please note that surveys shown via this API must be live. If you're calling this API using an invalid survey id, nothing will happen.
import { startSurvey } from "@intercom/messenger-js-sdk";
// ...
startSurvey(surveyId);
startChecklistIf you would like to trigger a checklist in the Messenger, you can use the startChecklist method. 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.
Please note that checklists shown via this API must be live. If you're calling this API using an invalid checklist id, nothing will happen.
import { startChecklist } from "@intercom/messenger-js-sdk";
// ...
startChecklist(checklistId);
showTicketIf you would like to trigger a ticket in the Messenger, you can use the showTicket method. 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.
import { showTicket } from "@intercom/messenger-js-sdk";
// ...
showTicket(ticketId);
showConversationYou can show a conversation programatically in the Messenger by calling showConversation method
import { showConversation } from "@intercom/messenger-js-sdk";
// ...
showConversation(conversationId);
onUserEmailSuppliedWhen a visitor enters their email into the Messenger, you can hook into the event. This requires a function argument.
import { onUserEmailSupplied } from "@intercom/messenger-js-sdk";
// ...
onUserEmailSupplied(function () {
// Do stuff...
});
bootThe boot function can be used if at somepoint the shutdown function was called. This is also useful in situations like a one-page Javascript based application where the user may not be logged in when the page loads. You call this method with the standard intercomSettings object used for the initiate the widget.
import { boot } from "@intercom/messenger-js-sdk";
// ...
boot({
app_id: "abc12345",
email: "john.doe@example.com",
created_at: 1234567890,
name: "John Doe",
user_id: "9876",
});
| Attribute | Type | Description |
|---|---|---|
| app_id | string | The app_id of your Intercom app which will indicate |
| custom_launcher_selectorcustom_launcher_selector | string | The CSS selector of an element |
| alignment | string | Dictate the alignment of the default launcher |
| vertical_padding | integer | Move the default launcher icon |
| horizontal_padding | integer | Move the default launcher icon |
| hide_default_launcher | boolean | Hide the default launcher icon. |
| hide_notifications | boolean | Hide notifications from messenger. |
| session_duration | integer | Time in milliseconds for the Intercom |
| action_color | string* | Used in button links and more to highlight |
| background_color | string* | Used behind your team profile and other |
These attributes are used to update user/lead information.
When user_id / email is provided, it will be saved as a User record When no user_id / email is provided, it will be considered a Visitor record which is not seen in the Intercom dashboard. When a Visitor sends a message via the Intercom messenger they will be converted to a Lead which is viewable in the Intercom dashboard Any other attribute not listed below and not in the Messenger Attributes will be treated as a custom user attribute If the value of a custom user attribute is set to an empty string, or a string with the value "undefined", or "null", this will appear as Unknown in Platform. If a value is set for a custom user attribute that has been configured to prevent updates via the Messenger then this value will be ignored in the request.
| Attribute | Type | Description |
|---|---|---|
| string | The email address of the currently logged in user (Only applicable to users) | |
| user_id | string | The user_id address of the currently logged in user (Only applicable to users) |
| created_at | timestamp | The Unix timestamp (in seconds) when the user signed up to your app (Only applicable to users) |
| name | string | Name of the current user/lead |
| phone | string | Phone number of the current user/lead |
| last_request_at | timestamp | This value can't actually be set by the Javascript API (it automatically uses the time of the last request but is a this is a reserved attribute) |
| unsubscribed_from_emails | boolean | Sets the unsubscribe status of the record |
| language_override | string | Set the messenger language programmatically (instead of relying on browser language settings) |
| utm_campaign | string | UTM Campaign valueNote: All UTM parameters are updated automatically and can not be manually overidden |
| utm_content | string | UTM Content value |
| utm_medium | string | UTM Medium value |
| utm_source | string | UTM Source value |
| utm_term | string | UTM Term value |
| avatar | avatar object | Set the avatar/profile image associated to the current record (typically gathered via social profiles via email address) |
| user_hash | string | Used for identity verification (Only applicable to users) |
| company | company object | Current user's company (Only applicable to users) For field definitions see Company Object in the section below Note: Company ID and company name are the minimum requirements to pass a company into Intercom. |
| companies | array of company objects | An array of companies the user is associated to (Only applicable to users) |
| page_title | string | Used for keeping track of user page views. Default value is the document title property. |
| Attribute | Type | Description |
|---|---|---|
| widgetUrl | string | Optional custom widget URL to load a specific build version. Only needed in special circumstances. |
Further instructions on how to customize the messenger and using Intercom API can be found in our dev docs.
appId is being sent.live on your Intercom settings page.This package was made using plain JS. This means that it is not be limited to the frameworks mentioned.
👤 Intercom (https://www.intercom.com/)
Give a ⭐️ if this project helped you!
This project is MIT licensed.
Created with ❤️ by Intercom
FAQs
Beta - Npm package for Intercom Messenger Client SDK
The npm package @intercom/messenger-js-sdk receives a total of 443,277 weekly downloads. As such, @intercom/messenger-js-sdk popularity was classified as popular.
We found that @intercom/messenger-js-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.