Skip to content

Commit

Permalink
Fixed the duplicate welcome bug and created a unique user ID
Browse files Browse the repository at this point in the history
  • Loading branch information
VasuBhog committed Aug 4, 2020
1 parent ac7098e commit 9c022ec
Showing 1 changed file with 51 additions and 42 deletions.
93 changes: 51 additions & 42 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,51 +47,60 @@ export function deactivate() {
function getWebViewContent() {
return `<!DOCTYPE html>
<html>
<head>
<script
crossorigin="anonymous"
src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"
></script>
<style>
html,
body {
height: 100%;
}
<head>
<script crossorigin="anonymous" src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<style>
html,
body {
height: 100%;
}
body {
margin: 0;
}
body {
margin: 0;
}
#webchat {
height: 100%;
width: 100%;
}
</style>
#webchat {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<body>
<div id="webchat" role="main"></div>
<script>
var request = new XMLHttpRequest();
var webChatToken;
request.open("POST",'https://directline.botframework.com/v3/directline/tokens/generate', true);
request.setRequestHeader("Authorization", 'Bearer ' + 'L9N5vQbHbOE.3ktVdAJQasxq_-1s0RoAkndtKnYjSyRya2tB7Q3GpqA');
request.setRequestHeader('Accept', 'application/json');
request.send();
request.onreadystatechange = function () {
if (request.readyState === request.DONE) {
var response = request.responseText;
var obj = JSON.parse(response);
webChatToken = obj.token;
}
console.log(webChatToken);
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({ token: webChatToken }),
},
document.getElementById('webchat')
);};
var webChatToken;
const userID = "dl_"+ Math.random().toString(36).substr(2, 9);
var body = {
"user": {
"id": userID
}
};
var request = new XMLHttpRequest();
request.open("POST", 'https://directline.botframework.com/v3/directline/tokens/generate', true);
request.setRequestHeader("Authorization", 'Bearer ' + 'L9N5vQbHbOE.3ktVdAJQasxq_-1s0RoAkndtKnYjSyRya2tB7Q3GpqA');
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.setRequestHeader('Accept', 'application/json');
request.send(JSON.stringify(body));
request.onreadystatechange = function () {
if (request.readyState === request.DONE) {
var response = request.responseText;
console.log(response);
var obj = JSON.parse(response);
webChatToken = obj.token;
}
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({ token: webChatToken }),
},
document.getElementById('webchat')
);
document.querySelector('#webchat > *').focus();
};
</script>
</body>
</html>`;
}
</body>
</html>`;
}

0 comments on commit 9c022ec

Please sign in to comment.