UNPKG

@capgo/capacitor-crisp

Version:
106 lines (100 loc) 3.15 kB
'use strict'; var core = require('@capacitor/core'); const CapacitorCrisp = core.registerPlugin('CapacitorCrisp', { web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorCrispWeb()), }); class CapacitorCrispWeb extends core.WebPlugin { constructor() { super(); window.$crisp = []; const s = document.createElement('script'); s.src = 'https://client.crisp.chat/l.js'; s.async = true; document.getElementsByTagName('head')[0].appendChild(s); this.setAutoHide(); } setAutoHide() { window.$crisp.push(['safe', true], ['do', 'chat:hide'], [ 'on', 'chat:closed', () => { window.$crisp.push(['do', 'chat:hide']); }, ], [ 'on', 'message:received', () => { window.$crisp.push(['do', 'chat:show']); }, ]); } async configure(data) { window.CRISP_WEBSITE_ID = data.websiteID; } async openMessenger() { window.$crisp.push(['do', 'chat:show']); window.$crisp.push(['do', 'chat:open']); } async setTokenID(data) { window.CRISP_TOKEN_ID = data.tokenID; this.reset(); } async setUser(data) { if (data.nickname) { window.$crisp.push(['set', 'user:nickname', [data.nickname]]); } if (data.email) { window.$crisp.push(['set', 'user:email', [data.email]]); } if (data.phone) { window.$crisp.push(['set', 'user:phone', [data.phone]]); } if (data.avatar) { window.$crisp.push(['set', 'user:avatar', [data.avatar]]); } } async pushEvent(data) { window.$crisp.push(['set', 'session:event', [[[data.name, null, data.color]]]]); } async setCompany(data) { const meta = {}; if (data.url) { meta.url = data.url; } if (data.description) { meta.description = data.description; } if (data.employment) { meta.employment = data.employment; } if (data.geolocation) { meta.geolocation = data.geolocation; } window.$crisp.push(['set', 'user:company', [data.name, meta]]); } async setInt(data) { window.$crisp.push(['set', 'session:data', [[[data.key, data.value]]]]); } async setString(data) { window.$crisp.push(['set', 'session:data', [[[data.key, data.value]]]]); } async sendMessage(data) { window.$crisp.push(['do', 'message:send', ['text', data.value]]); } async setSegment(data) { window.$crisp.push(['set', 'session:segments', [[data.segment]]]); } async reset() { window.$crisp.push(['do', 'session:reset']); this.setAutoHide(); } async getPluginVersion() { return { version: 'web' }; } } var web = /*#__PURE__*/Object.freeze({ __proto__: null, CapacitorCrispWeb: CapacitorCrispWeb }); exports.CapacitorCrisp = CapacitorCrisp; //# sourceMappingURL=plugin.cjs.js.map