From 6b4b5870b436baa64508ddf9ec9e131f8a67fd0e Mon Sep 17 00:00:00 2001 From: Jose10go <49805918+Jose10go@users.noreply.github.com> Date: Mon, 18 Dec 2023 10:44:42 +0000 Subject: [PATCH 1/7] Add startChecklist method --- packages/react-use-intercom/src/provider.tsx | 11 +++++++++++ packages/react-use-intercom/src/types.ts | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/react-use-intercom/src/provider.tsx b/packages/react-use-intercom/src/provider.tsx index d2e87bf..c6cd7cd 100644 --- a/packages/react-use-intercom/src/provider.tsx +++ b/packages/react-use-intercom/src/provider.tsx @@ -209,6 +209,15 @@ export const IntercomProvider: React.FC< [ensureIntercom], ); + const startChecklist = React.useCallback( + (checklistId: number) => { + ensureIntercom('startChecklist', () => { + IntercomAPI('startChecklist', checklistId); + }); + }, + [ensureIntercom], + ); + const trackEvent = React.useCallback( (event: string, metaData?: object) => { ensureIntercom('trackEvent', () => { @@ -260,6 +269,7 @@ export const IntercomProvider: React.FC< showNewMessage, getVisitorId, startTour, + startChecklist, trackEvent, showArticle, startSurvey, @@ -277,6 +287,7 @@ export const IntercomProvider: React.FC< showNewMessage, getVisitorId, startTour, + startChecklist, trackEvent, showArticle, startSurvey, diff --git a/packages/react-use-intercom/src/types.ts b/packages/react-use-intercom/src/types.ts index 0adc5fe..aa6c38f 100644 --- a/packages/react-use-intercom/src/types.ts +++ b/packages/react-use-intercom/src/types.ts @@ -244,6 +244,7 @@ export type IntercomMethod = | 'trackEvent' | 'getVisitorId' | 'startTour' + | 'startChecklist' | 'showArticle' | 'showSpace'; @@ -365,9 +366,22 @@ export type IntercomContextValues = { * the “Use tour everywhere” section must be turned on. * If you're calling this API using an invalid tour id, nothing will happen. * - * @see {@link https://developers.intercom.com/installing-intercom/docs/intercom-javascript#section-intercomstarttour-tourid} + * @see {@link https://developers.intercom.com/installing-intercom/docs/intercom-javascript#intercomstarttour-tourid} */ startTour: (tourId: number) => void; + /** + * Triggers a checklist based on an action a user or visitor takes in your site or application, + * You need to call this method with the id of the checklist you wish to show. + * + * The id of the checklist can be found in the “Aditional ways to share your checklist” section + * of the tour editor. + * + * @remarks Please note that checklists shown via this API must be published. + * If you're calling this API using an invalid tour id, nothing will happen. + * + * @see {@link https://developers.intercom.com/installing-intercom/web/methods/#intercomstartchecklist-checklistid} + */ + startChecklist: (checklistId: number) => void; /** * Submits an event, this will associate the event with the currently * tracked visitor, lead or user and send it to Intercom From 1505878cc6e193cde7402e569bd62bf3f2fba7ee Mon Sep 17 00:00:00 2001 From: Jose10go <49805918+Jose10go@users.noreply.github.com> Date: Mon, 18 Dec 2023 10:46:07 +0000 Subject: [PATCH 2/7] Add start checklist to README.md --- README.md | 4 ++++ packages/react-use-intercom/README.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index b95c2f2..7c34d69 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ Used to retrieve all methods bundled with Intercom. These are based on the offic | 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 | | getVisitorId | () => string | gets the visitor id | | startTour | (tourId: number) => void | starts a tour based on the `tourId` | +| startChecklist | (checklistId: number) => void | starts a checklist based on the `checklistId` | | trackEvent | (event: string, metaData?: object) => void | submits an `event` with optional `metaData` | showArticle | (articleId: string) => void | opens the Messenger with the specified article by `articleId` | startSurvey | (surveyId: number) => void | Trigger a survey in the Messenger by `surveyId` @@ -175,6 +176,7 @@ const HomePage = () => { showNewMessage, getVisitorId, startTour, + startChecklist, trackEvent, showArticle, startSurvey, @@ -187,6 +189,7 @@ const HomePage = () => { const handleNewMessagesWithContent = () => showNewMessage('content'); const handleGetVisitorId = () => console.log(getVisitorId()); const handleStartTour = () => startTour(123); + const handleStartChecklist= () => startChecklist(456); const handleTrackEvent = () => trackEvent('invited-friend'); const handleTrackEventWithMetaData = () => trackEvent('invited-frind', { @@ -213,6 +216,7 @@ const HomePage = () => { + +