Skip to content

Commit c67cc33

Browse files
authored
Merge pull request #834 from devrnt/sdk-parity-methods-attrs
Add startConversation method and missing Messenger/data attributes.
2 parents 9a81a7e + 7322d54 commit c67cc33

5 files changed

Lines changed: 70 additions & 0 deletions

File tree

‎.changeset/wise-mangos-hunt.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-use-intercom': minor
3+
---
4+
5+
Add the `startConversation` method and support for the `linkColor`, `themeMode`, `messengerStyleId`, `hideNotifications` and `pageTitle` attributes

‎packages/react-use-intercom/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Used to retrieve all methods bundled with Intercom. These are based on the offic
142142
| show | () => void | shows the Messenger, will call `onShow` if supplied to `IntercomProvider` |
143143
| showMessages | () => void | shows the Messenger with the message list |
144144
| showNewMessage | (content?: string) => void | shows the Messenger as if a new conversation was just created. If `content` is passed, it will fill in the message composer |
145+
| startConversation | (message: string) => void | opens the Messenger and immediately starts a new conversation with the supplied `message` |
145146
| getVisitorId | () => string | gets the visitor id |
146147
| startTour | (tourId: number) => void | starts a tour based on the `tourId` |
147148
| startChecklist | (checklistId: number) => void | starts a checklist based on the `checklistId` |
@@ -178,6 +179,7 @@ const HomePage = () => {
178179
show,
179180
showMessages,
180181
showNewMessage,
182+
startConversation,
181183
getVisitorId,
182184
startTour,
183185
startChecklist,
@@ -195,6 +197,7 @@ const HomePage = () => {
195197
const updateWithProps = () => update({ name: 'Ossur' });
196198
const handleNewMessages = () => showNewMessage();
197199
const handleNewMessagesWithContent = () => showNewMessage('content');
200+
const handleStartConversation = () => startConversation('Hello');
198201
const handleGetVisitorId = () => console.log(getVisitorId());
199202
const handleStartTour = () => startTour(123);
200203
const handleStartChecklist = () => startChecklist(456);
@@ -226,6 +229,7 @@ const HomePage = () => {
226229
<button onClick={handleNewMessagesWithContent}>
227230
Show new message with pre-filled content
228231
</button>
232+
<button onClick={handleStartConversation}>Start conversation</button>
229233
<button onClick={handleGetVisitorId}>Get visitor id</button>
230234
<button onClick={handleStartTour}>Start tour</button>
231235
<button onClick={handleStartChecklist}>Start checklist</button>

‎packages/react-use-intercom/src/mappers.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export const mapMessengerAttributesToRawMessengerAttributes = (
2424
session_duration: attributes.sessionDuration,
2525
action_color: attributes.actionColor,
2626
background_color: attributes.backgroundColor,
27+
link_color: attributes.linkColor,
28+
theme_mode: attributes.themeMode,
29+
messenger_style_id: attributes.messengerStyleId,
30+
hide_notifications: attributes.hideNotifications,
2731
});
2832

2933
const mapDataAttributesCompanyToRawDataAttributesCompany = (
@@ -75,6 +79,7 @@ export const mapDataAttributesToRawDataAttributes = (
7579
mapDataAttributesCompanyToRawDataAttributesCompany,
7680
),
7781
intercom_user_jwt: attributes.intercomUserJwt,
82+
page_title: attributes.pageTitle,
7883
...attributes.customAttributes,
7984
});
8085

‎packages/react-use-intercom/src/provider.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@ export const IntercomProvider: React.FC<
300300
[ensureIntercom],
301301
);
302302

303+
const startConversation = React.useCallback(
304+
(message: string) => {
305+
ensureIntercom('startConversation', () => {
306+
IntercomAPI('startConversation', message);
307+
});
308+
},
309+
[ensureIntercom],
310+
);
311+
303312
const providerValue = React.useMemo<IntercomContextValues>(() => {
304313
return {
305314
boot,
@@ -311,6 +320,7 @@ export const IntercomProvider: React.FC<
311320
isOpen,
312321
showMessages,
313322
showNewMessage,
323+
startConversation,
314324
getVisitorId,
315325
startTour,
316326
startChecklist,
@@ -333,6 +343,7 @@ export const IntercomProvider: React.FC<
333343
isOpen,
334344
showMessages,
335345
showNewMessage,
346+
startConversation,
336347
getVisitorId,
337348
startTour,
338349
startChecklist,

‎packages/react-use-intercom/src/types.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export type RawMessengerAttributes = {
88
session_duration?: number;
99
action_color?: string;
1010
background_color?: string;
11+
link_color?: string;
12+
theme_mode?: string;
13+
messenger_style_id?: string;
14+
hide_notifications?: boolean;
1115
};
1216

1317
export type MessengerAttributes = {
@@ -63,6 +67,30 @@ export type MessengerAttributes = {
6367
* @see {@link https://www.w3schools.com/cssref/css_colors.asp}
6468
*/
6569
backgroundColor?: string;
70+
/** Used for the color of links in the messenger
71+
*
72+
* @remarks The color string can be any valid CSS: "color name", "hex" or "rgb"
73+
* @see {@link https://www.w3schools.com/cssref/css_colors.asp}
74+
*/
75+
linkColor?: string;
76+
/** Set the color mode of the messenger
77+
*
78+
* @remarks Possible values: "light", "dark" or "system"
79+
* @see {@link https://developers.intercom.com/installing-intercom/web/attributes-objects}
80+
*/
81+
themeMode?: 'light' | 'dark' | 'system';
82+
/** Load a specific messenger style configuration by its id
83+
*
84+
* @remarks Useful when you have multiple messenger styles configured for your workspace
85+
* @see {@link https://developers.intercom.com/installing-intercom/web/attributes-objects}
86+
*/
87+
messengerStyleId?: string;
88+
/** Hide the in-app notifications when the messenger is booted
89+
*
90+
* @remarks To toggle notifications at runtime after boot, use the `hideNotifications` method instead
91+
* @see {@link https://developers.intercom.com/installing-intercom/web/attributes-objects}
92+
*/
93+
hideNotifications?: boolean;
6694
};
6795

6896
export type RawDataAttributesCompany = {
@@ -136,6 +164,7 @@ export type RawDataAttributes = {
136164
company?: RawDataAttributesCompany;
137165
companies?: RawDataAttributesCompany[];
138166
intercom_user_jwt?: string;
167+
page_title?: string;
139168
customAttributes?: Record<string, any>;
140169
};
141170

@@ -224,6 +253,12 @@ export type DataAttributes = {
224253
* @see {@link https://www.intercom.com/help/en/articles/10589769-authenticating-users-in-the-messenger-with-json-web-tokens-jwts}
225254
*/
226255
intercomUserJwt?: string;
256+
/**
257+
* The title of the current page, used to track page views
258+
*
259+
* @see {@link https://developers.intercom.com/installing-intercom/web/attributes-objects}
260+
*/
261+
pageTitle?: string;
227262
/**
228263
* You can do this anytime by adding additional key/value pairs to your intercomSettings code snippet
229264
* These should be raw snake_cased
@@ -249,6 +284,7 @@ export type IntercomMethod =
249284
| 'show'
250285
| 'showMessages'
251286
| 'showNewMessage'
287+
| 'startConversation'
252288
| 'startSurvey'
253289
| 'onHide'
254290
| 'onShow'
@@ -364,6 +400,15 @@ export type IntercomContextValues = {
364400
* ```
365401
*/
366402
showNewMessage: (prePopulatedContent?: string) => void;
403+
/**
404+
* Opens the Messenger and immediately starts a new conversation by sending the
405+
* supplied message on behalf of the current user.
406+
*
407+
* @see {@link https://developers.intercom.com/installing-intercom/web/methods/#intercomstartconversation-message}
408+
*
409+
* @param message The message to send to start the conversation
410+
*/
411+
startConversation: (message: string) => void;
367412
/**
368413
* A visitor is someone who goes to your site but does not use the messenger.
369414
* You can track these visitors via the visitor `user_id`.

0 commit comments

Comments
 (0)