2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
2020-03-07 18:09:41 +00:00
|
|
|
<div id="app" class="woot-widget-wrap" :class="{ 'is-mobile': isMobile }">
|
2019-10-29 07:20:54 +00:00
|
|
|
<router-view />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapActions } from 'vuex';
|
2020-01-17 08:06:05 +00:00
|
|
|
import { setHeader } from 'widget/helpers/axios';
|
|
|
|
import { IFrameHelper } from 'widget/helpers/utils';
|
2019-10-29 07:20:54 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'App',
|
2020-03-07 18:09:41 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isMobile: false,
|
|
|
|
};
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
mounted() {
|
2020-04-19 18:10:28 +00:00
|
|
|
const { websiteToken } = window.chatwootWebChannel;
|
2019-10-30 05:13:11 +00:00
|
|
|
if (IFrameHelper.isIFrame()) {
|
|
|
|
IFrameHelper.sendMessage({
|
|
|
|
event: 'loaded',
|
|
|
|
config: {
|
|
|
|
authToken: window.authToken,
|
2019-11-25 18:40:27 +00:00
|
|
|
channelConfig: window.chatwootWebChannel,
|
2019-10-30 05:13:11 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
setHeader('X-Auth-Token', window.authToken);
|
|
|
|
}
|
2019-11-25 18:40:27 +00:00
|
|
|
this.setWidgetColor(window.chatwootWebChannel);
|
2019-10-30 05:13:11 +00:00
|
|
|
|
|
|
|
window.addEventListener('message', e => {
|
2020-02-05 05:57:22 +00:00
|
|
|
const wootPrefix = 'chatwoot-widget:';
|
|
|
|
const isDataNotString = typeof e.data !== 'string';
|
|
|
|
const isNotFromWoot = isDataNotString || e.data.indexOf(wootPrefix) !== 0;
|
|
|
|
|
|
|
|
if (isNotFromWoot) return;
|
|
|
|
|
|
|
|
const message = JSON.parse(e.data.replace(wootPrefix, ''));
|
2019-10-30 05:13:11 +00:00
|
|
|
if (message.event === 'config-set') {
|
|
|
|
this.fetchOldConversations();
|
2020-02-05 05:57:22 +00:00
|
|
|
this.fetchAvailableAgents(websiteToken);
|
2019-11-10 17:28:55 +00:00
|
|
|
} else if (message.event === 'widget-visible') {
|
|
|
|
this.scrollConversationToBottom();
|
2020-01-01 17:00:43 +00:00
|
|
|
} else if (message.event === 'set-current-url') {
|
|
|
|
window.refererURL = message.refererURL;
|
2020-03-07 18:09:41 +00:00
|
|
|
} else if (message.event === 'toggle-close-button') {
|
|
|
|
this.isMobile = message.showClose;
|
2020-04-10 11:12:37 +00:00
|
|
|
} else if (message.event === 'push-event') {
|
|
|
|
this.$store.dispatch('events/create', { name: message.eventName });
|
2020-04-03 07:34:58 +00:00
|
|
|
} else if (message.event === 'set-label') {
|
|
|
|
this.$store.dispatch('conversationLabels/create', message.label);
|
|
|
|
} else if (message.event === 'remove-label') {
|
|
|
|
this.$store.dispatch('conversationLabels/destroy', message.label);
|
|
|
|
} else if (message.event === 'set-user') {
|
|
|
|
this.$store.dispatch('contacts/update', message);
|
2019-10-30 05:13:11 +00:00
|
|
|
}
|
|
|
|
});
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
2020-01-01 17:00:43 +00:00
|
|
|
methods: {
|
|
|
|
...mapActions('appConfig', ['setWidgetColor']),
|
|
|
|
...mapActions('conversation', ['fetchOldConversations']),
|
2020-02-05 05:57:22 +00:00
|
|
|
...mapActions('agent', ['fetchAvailableAgents']),
|
2020-01-01 17:00:43 +00:00
|
|
|
scrollConversationToBottom() {
|
|
|
|
const container = this.$el.querySelector('.conversation-wrap');
|
|
|
|
container.scrollTop = container.scrollHeight;
|
|
|
|
},
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
@import '~widget/assets/scss/woot.scss';
|
|
|
|
</style>
|