-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (38 loc) · 1.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { faker } from '@faker-js/faker';
import { chat as getChatConfig, paymentData } from './src/config';
import { SUPPORT_PURPOSE } from './src/config/env';
import ReactBotClient from './src/main';
import { intent } from './src/services/intentions';
// example entry point for the plugin
document.addEventListener('DOMContentLoaded', () => {
// DEV NOTE: this is needed to simulate retarded loading of the data
setTimeout(() => {
localStorage.setItem('__pd', JSON.stringify(paymentData));
}, 5000);
const id = faker.string.uuid();
!localStorage.getItem('__cid') && localStorage.setItem('__cid', id);
ReactBotClient({
root: document.querySelector('#chatbot-container'),
initialConfig: getChatConfig({
id,
// purpose: SUPPORT_PURPOSE,
close: {}
})
});
// example implementation from the plugin user side
// MOCKERIES FOR TESTING PURPOSES
intent.core.on(intent.type.email, (data) => {
// SUCCESS
setTimeout(() => {
intent.core.emit(intent.type.emailSuccess, 'great');
}, 3000);
// ERROR - EXISTING USER
// setTimeout(() => {
// intent.core.emit(intent.type.emailError, { status: 409, data: { buttonLink: '/some-link' } });
// }, 3000);
// ERROR - BLACKLISTED MAIL OR ELSE
// setTimeout(() => {
// intent.core.emit(intent.type.emailError, { status: 422, errors: { email: ['Email is invalid, please enter valid one'] } });
// }, 3000);
});
});