2019-10-30 05:13:11 +00:00
|
|
|
import Cookies from 'js-cookie';
|
2020-04-03 07:34:58 +00:00
|
|
|
import { IFrameHelper } from '../sdk/IFrameHelper';
|
2019-10-30 05:13:11 +00:00
|
|
|
|
2020-04-03 07:34:58 +00:00
|
|
|
const runSDK = ({ baseUrl, websiteToken }) => {
|
|
|
|
const chatwootSettings = window.chatwootSettings || {};
|
|
|
|
window.$chatwoot = {
|
|
|
|
baseUrl,
|
|
|
|
hasLoaded: false,
|
|
|
|
hideMessageBubble: chatwootSettings.hideMessageBubble || false,
|
|
|
|
isOpen: false,
|
|
|
|
position: chatwootSettings.position || 'right',
|
|
|
|
websiteToken,
|
2019-10-29 07:20:54 +00:00
|
|
|
|
2020-04-03 07:34:58 +00:00
|
|
|
toggle() {
|
2020-04-10 11:12:37 +00:00
|
|
|
IFrameHelper.events.toggleBubble();
|
2020-04-03 07:34:58 +00:00
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
|
2020-04-03 07:34:58 +00:00
|
|
|
setUser(identifier, user) {
|
|
|
|
if (typeof identifier === 'string' || typeof identifier === 'number') {
|
|
|
|
window.$chatwoot.identifier = identifier;
|
|
|
|
window.$chatwoot.user = user || {};
|
|
|
|
IFrameHelper.sendMessage('set-user', {
|
|
|
|
identifier,
|
|
|
|
user: window.$chatwoot.user,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
throw new Error('Identifier should be a string or a number');
|
2019-10-29 07:20:54 +00:00
|
|
|
}
|
2020-01-17 08:06:05 +00:00
|
|
|
},
|
2019-10-30 05:13:11 +00:00
|
|
|
|
2020-04-03 07:34:58 +00:00
|
|
|
setLabel(label = '') {
|
|
|
|
IFrameHelper.sendMessage('set-label', { label });
|
|
|
|
},
|
2019-11-25 18:40:27 +00:00
|
|
|
|
2020-04-03 07:34:58 +00:00
|
|
|
removeLabel(label = '') {
|
|
|
|
IFrameHelper.sendMessage('remove-label', { label });
|
|
|
|
},
|
2019-11-25 18:40:27 +00:00
|
|
|
|
2020-04-03 07:34:58 +00:00
|
|
|
reset() {
|
|
|
|
if (window.$chatwoot.isOpen) {
|
2020-04-10 11:12:37 +00:00
|
|
|
IFrameHelper.events.toggleBubble();
|
2020-04-03 07:34:58 +00:00
|
|
|
}
|
2019-11-25 18:40:27 +00:00
|
|
|
|
2020-04-03 07:34:58 +00:00
|
|
|
Cookies.remove('cw_conversation');
|
|
|
|
const iframe = IFrameHelper.getAppFrame();
|
|
|
|
iframe.src = IFrameHelper.getUrl({
|
|
|
|
baseUrl: window.$chatwoot.baseUrl,
|
|
|
|
websiteToken: window.$chatwoot.websiteToken,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
2019-10-29 07:20:54 +00:00
|
|
|
|
2019-10-30 05:13:11 +00:00
|
|
|
IFrameHelper.createFrame({
|
|
|
|
baseUrl,
|
|
|
|
websiteToken,
|
|
|
|
});
|
2020-04-03 07:34:58 +00:00
|
|
|
};
|
2019-10-29 07:20:54 +00:00
|
|
|
|
|
|
|
window.chatwootSDK = {
|
2020-04-03 07:34:58 +00:00
|
|
|
run: runSDK,
|
2019-10-29 07:20:54 +00:00
|
|
|
};
|