-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomniretry.js
55 lines (44 loc) · 1.9 KB
/
omniretry.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
46
47
48
49
50
51
52
53
54
55
import BaseChatMessage from 'lightningsnapin/baseChatMessage';
import { track } from 'lwc';
const CHAT_CONTENT_CLASS = 'chat-content';
const AGENT_USER_TYPE = 'agent';
const CHASITOR_USER_TYPE = 'chasitor';
const SUPPORTED_USER_TYPES = [AGENT_USER_TYPE, CHASITOR_USER_TYPE];
/**
* Displays a chat message using the inherited api messageContent and is styled based on the inherited api userType and messageContent api objects passed in from BaseChatMessage.
*/
export default class ChatMessageDefaultUI extends BaseChatMessage {
@track messageStyle = '';
isSupportedUserType(userType) {
return SUPPORTED_USER_TYPES.some((supportedUserType) => supportedUserType === userType);
}
connectedCallback() {
if (this.isSupportedUserType(this.userType)) {
//alert(this.userType + ': ' + this.messageContent.value);
if (this.userType == 'agent' && this.messageContent.value == 'Boo. Agents are NOT available.')
{
//We need to delay and call the retry
//this.messageStyle = 'hideM';
this.messageStyle = `${CHAT_CONTENT_CLASS} ${this.userType}`;
setTimeout(function()
{
//alert('We can call a refresh here!');
//Send this message back to the bot from the chasitor
window.postMessage(
{
message: "Are Agents Available?",
type: "chasitor.sendMessage"
},
window.parent.location.href
);
}, 5000);
}
else
{
this.messageStyle = `${CHAT_CONTENT_CLASS} ${this.userType}`;
}
} else {
throw new Error('Unsupported user type passed in: ${this.userType}');
}
}
}