-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchatbot.html
158 lines (127 loc) · 4.75 KB
/
chatbot.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ChatBot Power VA</title>
<!-- Font awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
body {
font-family: monospace;
}
div.chat-bot-wrapper {
position: fixed;
bottom: 0;
right: 0;
border: 0;
width: 400px;
}
#bot-btn {
float: right;
height: 42px;
width: auto;
background-color: rgb(11, 85, 106);
color: white;
font-size: 1.1em;
padding: 0 1em;
border-left: 1px solid white;
font-family: inherit;
font-weight: bold;
}
.timesheets-bot-title {
background-color: rgb(11, 85, 106);
color: white;
font-size: 1.1em;
height: 42px;
font-family: inherit;
padding: 0.7em 0 0 0.7em;
}
i {
margin-right: 0.2em;
}
#iFrameBot {
display: none;
border-left: 1px solid black;
}
</style>
</head>
<body>
<div class="chat-bot-wrapper">
<button id="bot-btn" onclick="showBot()"> <i class="fa-solid fa-robot"></i> Talk to the bot </button>
<div id='iFrameBot'>
<!-- <iframe -->
<!-- src="https://web.powerva.microsoft.com/environments/Default-0e79f3f3-4eeb-48ed-815e-2876c379e863/bots/new_bot_60a376f1f8394cb3a3953250c0307ecf/webchat" -->
<!-- frameborder="1" style="width: 100%; height: 500px;"></iframe> -->
<h1 class="timesheets-bot-title">Timesheets bot</h1>
<div id="webchat" role="main"></div>
</div>
</div>
<!-- Javascript -->
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<script>
// hide/show toggle bot
const botBtn = document.getElementById('bot-btn');
const iframeBot = document.getElementById('iFrameBot');
function showBot() {
if (iframeBot.style.display == "block") {
iframeBot.style.display = "none";
botBtn.innerHTML = "<i class='fa-solid fa-robot'></i> Talk to the bot";
} else {
iframeBot.style.display = "block";
botBtn.innerHTML = "X";
}
}
// make the bot starts with an automatic greeting
const styleOptions = {
// Add styleOptions to customize web chat canvas
hideUploadButton: true
};
// Add your BOT ID below
var BOT_ID = "60a376f1-f839-4cb3-a395-3250c0307ecf";
var theURL = "https://powerva.microsoft.com/api/botmanagement/v1/directline/directlinetoken?botId=" + BOT_ID;
const store = window.WebChat.createStore(
{},
({ dispatch }) => next => action => {
if (action.type === "DIRECT_LINE/CONNECT_FULFILLED") {
dispatch({
meta: {
method: "keyboard",
},
payload: {
activity: {
channelData: {
postBack: true,
},
//Web Chat will show the 'Greeting' System Topic message which has a trigger-phrase 'hello'
name: 'startConversation',
type: "event"
},
},
type: "DIRECT_LINE/POST_ACTIVITY",
});
}
return next(action);
}
);
fetch(theURL)
.then(response => response.json())
.then(conversationInfo => {
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({
token: conversationInfo.token,
}),
store: store,
styleOptions: styleOptions
},
document.getElementById('webchat')
);
})
.catch(err => console.error("An error occurred: " + err));
</script>
</body>
</html>