Skip to content

Commit efbf3ae

Browse files
authored
Merge pull request #662 from Jose10go/main
Expose Start Checklist
2 parents 3a42c42 + 37de962 commit efbf3ae

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

.changeset/lazy-countries-obey.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+
Expose startChecklist method in useIntercom hook

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Used to retrieve all methods bundled with Intercom. These are based on the offic
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 |
145145
| getVisitorId | () => string | gets the visitor id |
146146
| startTour | (tourId: number) => void | starts a tour based on the `tourId` |
147+
| startChecklist | (checklistId: number) => void | starts a checklist based on the `checklistId` |
147148
| trackEvent | (event: string, metaData?: object) => void | submits an `event` with optional `metaData`
148149
| showArticle | (articleId: string) => void | opens the Messenger with the specified article by `articleId`
149150
| startSurvey | (surveyId: number) => void | Trigger a survey in the Messenger by `surveyId`
@@ -177,6 +178,7 @@ const HomePage = () => {
177178
showNewMessage,
178179
getVisitorId,
179180
startTour,
181+
startChecklist,
180182
trackEvent,
181183
showArticle,
182184
startSurvey,
@@ -189,6 +191,7 @@ const HomePage = () => {
189191
const handleNewMessagesWithContent = () => showNewMessage('content');
190192
const handleGetVisitorId = () => console.log(getVisitorId());
191193
const handleStartTour = () => startTour(123);
194+
const handleStartChecklist= () => startChecklist(456);
192195
const handleTrackEvent = () => trackEvent('invited-friend');
193196
const handleTrackEventWithMetaData = () =>
194197
trackEvent('invited-frind', {
@@ -215,6 +218,7 @@ const HomePage = () => {
215218
</button>
216219
<button onClick={handleGetVisitorId}>Get visitor id</button>
217220
<button onClick={handleStartTour}>Start tour</button>
221+
<button onClick={handleStartChecklist}>Start checklist</button>
218222
<button onClick={handleTrackEvent}>Track event</button>
219223
<button onClick={handleTrackEventWithMetaData}>
220224
Track event with metadata

packages/react-use-intercom/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Used to retrieve all methods bundled with Intercom. These are based on the offic
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 |
145145
| getVisitorId | () => string | gets the visitor id |
146146
| startTour | (tourId: number) => void | starts a tour based on the `tourId` |
147+
| startChecklist | (checklistId: number) => void | starts a checklist based on the `checklistId` |
147148
| trackEvent | (event: string, metaData?: object) => void | submits an `event` with optional `metaData`
148149
| showArticle | (articleId: string) => void | opens the Messenger with the specified article by `articleId`
149150
| startSurvey | (surveyId: number) => void | Trigger a survey in the Messenger by `surveyId`
@@ -175,6 +176,7 @@ const HomePage = () => {
175176
showNewMessage,
176177
getVisitorId,
177178
startTour,
179+
startChecklist,
178180
trackEvent,
179181
showArticle,
180182
startSurvey,
@@ -187,6 +189,7 @@ const HomePage = () => {
187189
const handleNewMessagesWithContent = () => showNewMessage('content');
188190
const handleGetVisitorId = () => console.log(getVisitorId());
189191
const handleStartTour = () => startTour(123);
192+
const handleStartChecklist = () => startChecklist(456);
190193
const handleTrackEvent = () => trackEvent('invited-friend');
191194
const handleTrackEventWithMetaData = () =>
192195
trackEvent('invited-frind', {
@@ -213,6 +216,7 @@ const HomePage = () => {
213216
</button>
214217
<button onClick={handleGetVisitorId}>Get visitor id</button>
215218
<button onClick={handleStartTour}>Start tour</button>
219+
<button onClick={handleStartChecklist}>Start checklist</button>
216220
<button onClick={handleTrackEvent}>Track event</button>
217221
<button onClick={handleTrackEventWithMetaData}>
218222
Track event with metadata

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ export const IntercomProvider: React.FC<
209209
[ensureIntercom],
210210
);
211211

212+
const startChecklist = React.useCallback(
213+
(checklistId: number) => {
214+
ensureIntercom('startChecklist', () => {
215+
IntercomAPI('startChecklist', checklistId);
216+
});
217+
},
218+
[ensureIntercom],
219+
);
220+
212221
const trackEvent = React.useCallback(
213222
(event: string, metaData?: object) => {
214223
ensureIntercom('trackEvent', () => {
@@ -268,6 +277,7 @@ export const IntercomProvider: React.FC<
268277
showNewMessage,
269278
getVisitorId,
270279
startTour,
280+
startChecklist,
271281
trackEvent,
272282
showArticle,
273283
startSurvey,
@@ -286,6 +296,7 @@ export const IntercomProvider: React.FC<
286296
showNewMessage,
287297
getVisitorId,
288298
startTour,
299+
startChecklist,
289300
trackEvent,
290301
showArticle,
291302
startSurvey,

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export type IntercomMethod =
244244
| 'trackEvent'
245245
| 'getVisitorId'
246246
| 'startTour'
247+
| 'startChecklist'
247248
| 'showArticle'
248249
| 'showSpace'
249250
| 'showNews';
@@ -366,9 +367,22 @@ export type IntercomContextValues = {
366367
* the “Use tour everywhere” section must be turned on.
367368
* If you're calling this API using an invalid tour id, nothing will happen.
368369
*
369-
* @see {@link https://developers.intercom.com/installing-intercom/docs/intercom-javascript#section-intercomstarttour-tourid}
370+
* @see {@link https://developers.intercom.com/installing-intercom/docs/intercom-javascript#intercomstarttour-tourid}
370371
*/
371372
startTour: (tourId: number) => void;
373+
/**
374+
* Triggers a checklist based on an action a user or visitor takes in your site or application,
375+
* You need to call this method with the id of the checklist you wish to show.
376+
*
377+
* The id of the checklist can be found in the “Aditional ways to share your checklist” section
378+
* of the tour editor.
379+
*
380+
* @remarks Please note that checklists shown via this API must be published.
381+
* If you're calling this API using an invalid tour id, nothing will happen.
382+
*
383+
* @see {@link https://developers.intercom.com/installing-intercom/web/methods/#intercomstartchecklist-checklistid}
384+
*/
385+
startChecklist: (checklistId: number) => void;
372386
/**
373387
* Submits an event, this will associate the event with the currently
374388
* tracked visitor, lead or user and send it to Intercom

0 commit comments

Comments
 (0)