react-use-intercom
Advanced tools
Comparing version 5.3.0 to 5.4.0
@@ -225,3 +225,3 @@ import * as React from 'react'; | ||
}; | ||
type IntercomMethod = 'boot' | 'shutdown' | 'update' | 'hide' | 'show' | 'showMessages' | 'showNewMessage' | 'startSurvey' | 'onHide' | 'onShow' | 'onUnreadCountChange' | 'onUserEmailSupplied' | 'trackEvent' | 'getVisitorId' | 'startTour' | 'startChecklist' | 'showArticle' | 'showSpace' | 'showNews'; | ||
type IntercomMethod = 'boot' | 'shutdown' | 'update' | 'hide' | 'show' | 'showMessages' | 'showNewMessage' | 'startSurvey' | 'onHide' | 'onShow' | 'onUnreadCountChange' | 'onUserEmailSupplied' | 'trackEvent' | 'getVisitorId' | 'startTour' | 'startChecklist' | 'showArticle' | 'showSpace' | 'showNews' | 'showTicket' | 'showConversation'; | ||
type RawIntercomProps = RawMessengerAttributes & RawDataAttributes; | ||
@@ -418,2 +418,17 @@ type RawIntercomBootProps = { | ||
showNews: (newsId: number) => void; | ||
/** | ||
* If 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. | ||
* @see {@link https://developers.intercom.com/installing-intercom/web/methods/#intercomshowticket-ticketid} | ||
*/ | ||
showTicket: (ticketId: number) => void; | ||
/** | ||
* You can show a conversation programatically in the Messenger by calling showConversation method | ||
* | ||
* @see {@link https://developers.intercom.com/installing-intercom/web/methods/#intercomshowconversation-conversationid} | ||
*/ | ||
showConversation: (conversationId: number) => void; | ||
}; | ||
@@ -420,0 +435,0 @@ type IntercomProviderProps = { |
@@ -25,7 +25,7 @@ 'use strict'; | ||
var ae=Object.defineProperty;var R=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var F=(e,t,n)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,m=(e,t)=>{for(var n in t||(t={}))H.call(t,n)&&F(e,n,t[n]);if(R)for(var n of R(t))K.call(t,n)&&F(e,n,t[n]);return e};var G=(e,t)=>{var n={};for(var c in e)H.call(e,c)&&t.indexOf(c)<0&&(n[c]=e[c]);if(e!=null&&R)for(var c of R(e))t.indexOf(c)<0&&K.call(e,c)&&(n[c]=e[c]);return n};var p=(e,t)=>{let n="[react-use-intercom]";switch(e){case"info":console.log(`${n} ${t}`);break;case"warn":console.warn(`${n} ${t}`);break;case"error":console.error(`${n} ${t}`);break;default:console.log(`${n} ${t}`);}};var h=typeof window=="undefined",A=e=>(Object.keys(e).forEach(t=>{e[t]&&typeof e[t]=="object"?A(e[t]):e[t]===void 0&&delete e[t];}),e);var se=(e,...t)=>{if(!h&&window.Intercom)return window.Intercom.apply(null,[e,...t]);p("error",`${e} Intercom instance is not initalized yet`);},s=se;var ce=o__namespace.createContext(void 0),P=ce;var ie=(e,t=0)=>{var n=window,c=n.Intercom;if(typeof c=="function")c("reattach_activator"),c("update",n.intercomSettings);else {var w=document,l=function(){l.c(arguments);};l.q=[],l.c=function(u){l.q.push(u);},n.Intercom=l;var f=function(){setTimeout(function(){var u=w.createElement("script");u.type="text/javascript",u.async=!0,u.src="https://widget.intercom.io/widget/"+e;var d=w.getElementsByTagName("script")[0];d.parentNode.insertBefore(u,d);},t);};document.readyState==="complete"?f():n.attachEvent?n.attachEvent("onload",f):n.addEventListener("load",f,!1);}},X=ie;var me=e=>({custom_launcher_selector:e.customLauncherSelector,alignment:e.alignment,vertical_padding:e.verticalPadding,horizontal_padding:e.horizontalPadding,hide_default_launcher:e.hideDefaultLauncher,session_duration:e.sessionDuration,action_color:e.actionColor,background_color:e.backgroundColor}),Y=e=>m({company_id:e.companyId,name:e.name,created_at:e.createdAt,plan:e.plan,monthly_spend:e.monthlySpend,user_count:e.userCount,size:e.size,website:e.website,industry:e.industry},e.customAttributes),le=e=>({type:e.type,image_url:e.imageUrl}),ue=e=>{var t;return m({email:e.email,user_id:e.userId,created_at:e.createdAt,name:e.name,phone:e.phone,last_request_at:e.lastRequestAt,unsubscribed_from_emails:e.unsubscribedFromEmails,language_override:e.languageOverride,utm_campaign:e.utmCampaign,utm_content:e.utmContent,utm_medium:e.utmMedium,utm_source:e.utmSource,utm_term:e.utmTerm,avatar:e.avatar&&le(e.avatar),user_hash:e.userHash,company:e.company&&Y(e.company),companies:(t=e.companies)==null?void 0:t.map(Y)},e.customAttributes)},b=e=>A(m(m({},me(e)),ue(e)));var de=we=>{var k=we,{appId:e,autoBoot:t=!1,autoBootProps:n,children:c,onHide:w,onShow:l,onUnreadCountChange:f,onUserEmailSupplied:u,shouldInitialize:d=!h,apiBase:v,initializeDelay:ee}=k,te=G(k,["appId","autoBoot","autoBootProps","children","onHide","onShow","onUnreadCountChange","onUserEmailSupplied","shouldInitialize","apiBase","initializeDelay"]);let g=o__namespace.useRef(!1),y=o__namespace.useRef(!1),_=Object.keys(te).filter(r=>!r.startsWith("data-"));_.length>0&&p("warn",["some invalid props were passed to IntercomProvider. ",`Please check following props: ${_.join(", ")}.`].join(""));let C=o__namespace.useCallback(r=>{if(!window.Intercom&&!d){p("warn","Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`");return}let i=m(m({app_id:e},v&&{api_base:v}),r&&b(r));window.intercomSettings=i,s("boot",i),g.current=!0;},[v,e,d]),[x,I]=o__namespace.useState(!1),oe=o__namespace.useCallback(()=>{I(!1),w&&w();},[w,I]),re=o__namespace.useCallback(()=>{I(!0),l&&l();},[l,I]);!h&&d&&!y.current&&(X(e,ee),s("onHide",oe),s("onShow",re),s("onUserEmailSupplied",u),f&&s("onUnreadCountChange",f),t&&C(n),y.current=!0);let a=o__namespace.useCallback((r,i)=>{if(!window.Intercom&&!d){p("warn","Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`");return}if(!g.current){p("warn",[`"${r}" was called but Intercom has not booted yet. `,`Please call 'boot' before calling '${r}' or `,"set 'autoBoot' to true in the IntercomProvider."].join(""));return}return i()},[d]),S=o__namespace.useCallback(()=>{g.current&&(s("shutdown"),delete window.intercomSettings,g.current=!1);},[]),D=o__namespace.useCallback(()=>{g.current&&(s("shutdown"),delete window.Intercom,delete window.intercomSettings,g.current=!1);},[]),M=o__namespace.useCallback(()=>{a("update",()=>{let r=Math.floor(new Date().getTime()/1e3);s("update",{last_request_at:r});});},[a]),E=o__namespace.useCallback(r=>{a("update",()=>{if(!r){M();return}let i=b(r);window.intercomSettings=m(m({},window.intercomSettings),i),s("update",i);});},[a,M]),T=o__namespace.useCallback(()=>{a("hide",()=>{s("hide");});},[a]),$=o__namespace.useCallback(()=>{a("show",()=>s("show"));},[a]),N=o__namespace.useCallback(()=>{a("showMessages",()=>{s("showMessages");});},[a]),V=o__namespace.useCallback(r=>{a("showNewMessage",()=>{r?s("showNewMessage",r):s("showNewMessage");});},[a]),z=o__namespace.useCallback(()=>a("getVisitorId",()=>s("getVisitorId")),[a]),L=o__namespace.useCallback(r=>{a("startTour",()=>{s("startTour",r);});},[a]),q=o__namespace.useCallback(r=>{a("startChecklist",()=>{s("startChecklist",r);});},[a]),O=o__namespace.useCallback((r,i)=>{a("trackEvent",()=>{i?s("trackEvent",r,i):s("trackEvent",r);});},[a]),B=o__namespace.useCallback(r=>a("showArticle",()=>{s("showArticle",r);}),[a]),U=o__namespace.useCallback(r=>a("showSpace",()=>{s("showSpace",r);}),[a]),W=o__namespace.useCallback(r=>{a("startSurvey",()=>{s("startSurvey",r);});},[a]),j=o__namespace.useCallback(r=>a("showNews",()=>{s("showNews",r);}),[a]),ne=o__namespace.useMemo(()=>({boot:C,shutdown:S,hardShutdown:D,update:E,hide:T,show:$,isOpen:x,showMessages:N,showNewMessage:V,getVisitorId:z,startTour:L,startChecklist:q,trackEvent:O,showArticle:B,startSurvey:W,showSpace:U,showNews:j}),[C,S,D,E,T,$,x,N,V,z,L,q,O,B,W,U,j]);return o__namespace.createElement(P.Provider,{value:ne},c)},Z=()=>{let e=o__namespace.useContext(P);if(e===void 0)throw new Error('"useIntercom" must be used within `IntercomProvider`.');return e};var pe=()=>Z(); | ||
var ce=Object.defineProperty;var R=Object.getOwnPropertySymbols;var G=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var K=(e,r,a)=>r in e?ce(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,m=(e,r)=>{for(var a in r||(r={}))G.call(r,a)&&K(e,a,r[a]);if(R)for(var a of R(r))J.call(r,a)&&K(e,a,r[a]);return e};var Q=(e,r)=>{var a={};for(var c in e)G.call(e,c)&&r.indexOf(c)<0&&(a[c]=e[c]);if(e!=null&&R)for(var c of R(e))r.indexOf(c)<0&&J.call(e,c)&&(a[c]=e[c]);return a};var p=(e,r)=>{let a="[react-use-intercom]";switch(e){case"info":console.log(`${a} ${r}`);break;case"warn":console.warn(`${a} ${r}`);break;case"error":console.error(`${a} ${r}`);break;default:console.log(`${a} ${r}`);}};var h=typeof window=="undefined",A=e=>(Object.keys(e).forEach(r=>{e[r]&&typeof e[r]=="object"?A(e[r]):e[r]===void 0&&delete e[r];}),e);var ie=(e,...r)=>{if(!h&&window.Intercom)return window.Intercom.apply(null,[e,...r]);p("error",`${e} Intercom instance is not initalized yet`);},s=ie;var me=o__namespace.createContext(void 0),b=me;var le=(e,r=0)=>{var a=window,c=a.Intercom;if(typeof c=="function")c("reattach_activator"),c("update",a.intercomSettings);else {var w=document,l=function(){l.c(arguments);};l.q=[],l.c=function(u){l.q.push(u);},a.Intercom=l;var f=function(){setTimeout(function(){var u=w.createElement("script");u.type="text/javascript",u.async=!0,u.src="https://widget.intercom.io/widget/"+e;var d=w.getElementsByTagName("script")[0];d.parentNode.insertBefore(u,d);},r);};document.readyState==="complete"?f():a.attachEvent?a.attachEvent("onload",f):a.addEventListener("load",f,!1);}},Z=le;var ue=e=>({custom_launcher_selector:e.customLauncherSelector,alignment:e.alignment,vertical_padding:e.verticalPadding,horizontal_padding:e.horizontalPadding,hide_default_launcher:e.hideDefaultLauncher,session_duration:e.sessionDuration,action_color:e.actionColor,background_color:e.backgroundColor}),ee=e=>m({company_id:e.companyId,name:e.name,created_at:e.createdAt,plan:e.plan,monthly_spend:e.monthlySpend,user_count:e.userCount,size:e.size,website:e.website,industry:e.industry},e.customAttributes),de=e=>({type:e.type,image_url:e.imageUrl}),pe=e=>{var r;return m({email:e.email,user_id:e.userId,created_at:e.createdAt,name:e.name,phone:e.phone,last_request_at:e.lastRequestAt,unsubscribed_from_emails:e.unsubscribedFromEmails,language_override:e.languageOverride,utm_campaign:e.utmCampaign,utm_content:e.utmContent,utm_medium:e.utmMedium,utm_source:e.utmSource,utm_term:e.utmTerm,avatar:e.avatar&&de(e.avatar),user_hash:e.userHash,company:e.company&&ee(e.company),companies:(r=e.companies)==null?void 0:r.map(ee)},e.customAttributes)},k=e=>A(m(m({},ue(e)),pe(e)));var we=ge=>{var P=ge,{appId:e,autoBoot:r=!1,autoBootProps:a,children:c,onHide:w,onShow:l,onUnreadCountChange:f,onUserEmailSupplied:u,shouldInitialize:d=!h,apiBase:v,initializeDelay:oe}=P,re=Q(P,["appId","autoBoot","autoBootProps","children","onHide","onShow","onUnreadCountChange","onUserEmailSupplied","shouldInitialize","apiBase","initializeDelay"]);let g=o__namespace.useRef(!1),y=o__namespace.useRef(!1),_=Object.keys(re).filter(t=>!t.startsWith("data-"));_.length>0&&p("warn",["some invalid props were passed to IntercomProvider. ",`Please check following props: ${_.join(", ")}.`].join(""));let C=o__namespace.useCallback(t=>{if(!window.Intercom&&!d){p("warn","Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`");return}let i=m(m({app_id:e},v&&{api_base:v}),t&&k(t));window.intercomSettings=i,s("boot",i),g.current=!0;},[v,e,d]),[x,I]=o__namespace.useState(!1),ne=o__namespace.useCallback(()=>{I(!1),w&&w();},[w,I]),ae=o__namespace.useCallback(()=>{I(!0),l&&l();},[l,I]);!h&&d&&!y.current&&(Z(e,oe),s("onHide",ne),s("onShow",ae),s("onUserEmailSupplied",u),f&&s("onUnreadCountChange",f),r&&C(a),y.current=!0);let n=o__namespace.useCallback((t,i)=>{if(!window.Intercom&&!d){p("warn","Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`");return}if(!g.current){p("warn",[`"${t}" was called but Intercom has not booted yet. `,`Please call 'boot' before calling '${t}' or `,"set 'autoBoot' to true in the IntercomProvider."].join(""));return}return i()},[d]),S=o__namespace.useCallback(()=>{g.current&&(s("shutdown"),delete window.intercomSettings,g.current=!1);},[]),D=o__namespace.useCallback(()=>{g.current&&(s("shutdown"),delete window.Intercom,delete window.intercomSettings,g.current=!1);},[]),M=o__namespace.useCallback(()=>{n("update",()=>{let t=Math.floor(new Date().getTime()/1e3);s("update",{last_request_at:t});});},[n]),T=o__namespace.useCallback(t=>{n("update",()=>{if(!t){M();return}let i=k(t);window.intercomSettings=m(m({},window.intercomSettings),i),s("update",i);});},[n,M]),E=o__namespace.useCallback(()=>{n("hide",()=>{s("hide");});},[n]),$=o__namespace.useCallback(()=>{n("show",()=>s("show"));},[n]),N=o__namespace.useCallback(()=>{n("showMessages",()=>{s("showMessages");});},[n]),V=o__namespace.useCallback(t=>{n("showNewMessage",()=>{t?s("showNewMessage",t):s("showNewMessage");});},[n]),z=o__namespace.useCallback(()=>n("getVisitorId",()=>s("getVisitorId")),[n]),L=o__namespace.useCallback(t=>{n("startTour",()=>{s("startTour",t);});},[n]),q=o__namespace.useCallback(t=>{n("startChecklist",()=>{s("startChecklist",t);});},[n]),O=o__namespace.useCallback((t,i)=>{n("trackEvent",()=>{i?s("trackEvent",t,i):s("trackEvent",t);});},[n]),B=o__namespace.useCallback(t=>n("showArticle",()=>{s("showArticle",t);}),[n]),U=o__namespace.useCallback(t=>n("showSpace",()=>{s("showSpace",t);}),[n]),W=o__namespace.useCallback(t=>{n("startSurvey",()=>{s("startSurvey",t);});},[n]),j=o__namespace.useCallback(t=>n("showNews",()=>{s("showNews",t);}),[n]),F=o__namespace.useCallback(t=>n("showTicket",()=>{s("showTicket",t);}),[n]),H=o__namespace.useCallback(t=>n("showConversation",()=>{s("showConversation",t);}),[n]),se=o__namespace.useMemo(()=>({boot:C,shutdown:S,hardShutdown:D,update:T,hide:E,show:$,isOpen:x,showMessages:N,showNewMessage:V,getVisitorId:z,startTour:L,startChecklist:q,trackEvent:O,showArticle:B,startSurvey:W,showSpace:U,showNews:j,showTicket:F,showConversation:H}),[C,S,D,T,E,$,x,N,V,z,L,q,O,B,W,U,j,F,H]);return o__namespace.createElement(b.Provider,{value:se},c)},te=()=>{let e=o__namespace.useContext(b);if(e===void 0)throw new Error('"useIntercom" must be used within `IntercomProvider`.');return e};var fe=()=>te(); | ||
exports.IntercomProvider = de; | ||
exports.useIntercom = pe; | ||
exports.IntercomProvider = we; | ||
exports.useIntercom = fe; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
@@ -7,3 +7,3 @@ { | ||
"homepage": "https://github.com/devrnt/react-use-intercom#readme", | ||
"version": "5.3.0", | ||
"version": "5.4.0", | ||
"license": "MIT", | ||
@@ -10,0 +10,0 @@ "main": "dist/index.js", |
@@ -152,2 +152,4 @@ <p align="center"><img src="https://raw.githubusercontent.com/devrnt/react-use-intercom/main/assets/logo.png" alt="Logo" height="120px" style="margin-top: 20px;"/></p> | ||
| showSpace | (spaceName: IntercomSpace) => void | Opens the Messenger with the specified space | ||
| 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` | ||
@@ -184,3 +186,5 @@ #### Example | ||
startSurvey, | ||
showSpace | ||
showSpace, | ||
showTicket, | ||
showConversation | ||
} = useIntercom(); | ||
@@ -203,2 +207,4 @@ | ||
const handleShowSpace = () => showSpace('tasks'); | ||
const handleShowTicket = () => showTicket(123); | ||
const handleShowConversation = () => showConversation(123); | ||
@@ -230,2 +236,4 @@ return ( | ||
<button onClick={handleShowSpace}>Open space in Messenger</button> | ||
<button onClick={handleShowTicket}>Open ticket in Messenger</button> | ||
<button onClick={handleShowConversation}>Open conversation in Messenger</button> | ||
</> | ||
@@ -232,0 +240,0 @@ ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
99976
559
296