Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/react-use-intercom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ Used to retrieve all methods bundled with Intercom. These are based on the offic
| 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`
| showSpace | (spaceName: IntercomSpace) => void | Opens the Messenger with the specified space
| showNews | (newsId: number) => void | Opens the Messenger with the specified news item by `newsId`
| showTicket | (ticketId: number) => void | Opens the Messenger with the specified ticket by `ticketId`
| showConversation | (conversationId: number) => void | Opens the Messenger with the specified conversation by `conversationId`
| hideNotifications | (hidden: boolean) => void | Controls the visibility of Intercom notifications

#### Example
```ts
Expand Down Expand Up @@ -183,8 +185,10 @@ const HomePage = () => {
showArticle,
startSurvey,
showSpace,
showNews,
showTicket,
showConversation
showConversation,
hideNotifications,
} = useIntercom();

const bootWithProps = () => boot({ name: 'Russo' });
Expand All @@ -202,8 +206,10 @@ const HomePage = () => {
const handleShowArticle = () => showArticle(123456);
const handleStartSurvey = () => startSurvey(123456);
const handleShowSpace = () => showSpace('tasks');
const handleShowNews = () => showNews(123);
const handleShowTicket = () => showTicket(123);
const handleShowConversation = () => showConversation(123);
const handleHideNotifications = () => hideNotifications(true);

return (
<>
Expand All @@ -230,8 +236,10 @@ const HomePage = () => {
<button onClick={handleShowArticle}>Open article in Messenger</button>
<button onClick={handleStartSurvey}>Start survey in Messenger</button>
<button onClick={handleShowSpace}>Open space in Messenger</button>
<button onClick={handleShowNews}>Open news in Messenger</button>
<button onClick={handleShowTicket}>Open ticket in Messenger</button>
<button onClick={handleShowConversation}>Open conversation in Messenger</button>
<button onClick={handleHideNotifications}>Hide notifications</button>
</>
);
};
Expand Down
11 changes: 11 additions & 0 deletions packages/react-use-intercom/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,15 @@ export const IntercomProvider: React.FC<
[ensureIntercom],
);

const hideNotifications = React.useCallback(
(hidden: boolean) => {
ensureIntercom('hideNotifications', () => {
IntercomAPI('hideNotifications', hidden);
});
},
[ensureIntercom],
);

const providerValue = React.useMemo<IntercomContextValues>(() => {
return {
boot,
Expand All @@ -312,6 +321,7 @@ export const IntercomProvider: React.FC<
showNews,
showTicket,
showConversation,
hideNotifications,
};
}, [
boot,
Expand All @@ -333,6 +343,7 @@ export const IntercomProvider: React.FC<
showNews,
showTicket,
showConversation,
hideNotifications,
]);

return (
Expand Down
13 changes: 11 additions & 2 deletions packages/react-use-intercom/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ export type IntercomMethod =
| 'showSpace'
| 'showNews'
| 'showTicket'
| 'showConversation';
| 'showConversation'
| 'hideNotifications';

export type RawIntercomProps = RawMessengerAttributes & RawDataAttributes;

Expand All @@ -280,7 +281,7 @@ export type IntercomBootProps = {

export type LogLevel = 'info' | 'error' | 'warn';

export type IntercomSpace = 'home' | 'messages' | 'help' | 'news' | 'tasks';
export type IntercomSpace = 'home' | 'messages' | 'help' | 'news' | 'tasks' | 'tickets';

export type IntercomContextValues = {
/**
Expand Down Expand Up @@ -476,6 +477,14 @@ export type IntercomContextValues = {
* @see {@link https://developers.intercom.com/installing-intercom/web/methods/#intercomshowconversation-conversationid}
*/
showConversation: (conversationId: number) => void;
/**
* Controls the visibility of Intercom notifications
*
* @see {@link https://developers.intercom.com/installing-intercom/web/methods/#intercomhidenotifications-hidden}
*
* @param hidden `true` to hide notifications, `false` to show them
*/
hideNotifications: (hidden: boolean) => void;
};

export type IntercomProviderProps = {
Expand Down
Loading