2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
|
|
|
<div id="app" class="woot-widget-wrap">
|
|
|
|
<router-view />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapActions } from 'vuex';
|
2019-10-30 05:13:11 +00:00
|
|
|
import { setHeader } from './helpers/axios';
|
|
|
|
|
|
|
|
export const IFrameHelper = {
|
|
|
|
isIFrame: () => window.self !== window.top,
|
|
|
|
sendMessage: msg => {
|
|
|
|
window.parent.postMessage(
|
|
|
|
`chatwoot-widget:${JSON.stringify({ ...msg })}`,
|
|
|
|
'*'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|
2019-10-29 07:20:54 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'App',
|
|
|
|
|
|
|
|
methods: {
|
2019-11-25 18:40:27 +00:00
|
|
|
...mapActions('appConfig', ['setWidgetColor']),
|
2019-10-29 07:20:54 +00:00
|
|
|
...mapActions('conversation', ['fetchOldConversations']),
|
2019-11-10 17:28:55 +00:00
|
|
|
scrollConversationToBottom() {
|
|
|
|
const container = this.$el.querySelector('.conversation-wrap');
|
|
|
|
container.scrollTop = container.scrollHeight;
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
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 => {
|
|
|
|
if (
|
|
|
|
typeof e.data !== 'string' ||
|
|
|
|
e.data.indexOf('chatwoot-widget:') !== 0
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const message = JSON.parse(e.data.replace('chatwoot-widget:', ''));
|
|
|
|
if (message.event === 'config-set') {
|
|
|
|
this.fetchOldConversations();
|
2019-11-10 17:28:55 +00:00
|
|
|
} else if (message.event === 'widget-visible') {
|
|
|
|
this.scrollConversationToBottom();
|
2019-10-30 05:13:11 +00:00
|
|
|
}
|
|
|
|
});
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
@import '~widget/assets/scss/woot.scss';
|
|
|
|
</style>
|