Advertisement
Guest User

Untitled

a guest
Mar 30th, 2022
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.18 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>My Bot</title>
  5.     <link rel="stylesheet" href="style.min.css" />
  6.   </head>
  7.   <body>
  8.     <div>
  9.       <div id="heading">
  10.         <!-- Change the h1 text to change the bot name -->
  11.         <div class="headingFirst">
  12.           <h1 class="chatboth1header">My Bot</h1>
  13.         </div>
  14.         <div class="headingSecond"></div>
  15.       </div>
  16.       <div id="webchat" role="main"></div>
  17.     </div>
  18.     <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
  19.     <script>
  20.       const styleSet = window.WebChat.createStyleSet({
  21.         // Add styleOptions to customize Web Chat canvas
  22.         bubbleBackground: "rgba(0, 0, 255, .1)",
  23.         bubbleFromUserBackground: "rgba(0, 255, 0, .1)",
  24.         rootHeight: "100%",
  25.         rootWidth: "100%",
  26.         backgroundColor: "white",
  27.         hideUploadButton: false,
  28.         userAvatarBackgroundColor: "white",
  29.         botAvatarBackgroundColor: "white",
  30.       });
  31.       // Set the avatar options.
  32.       const avatarOptions = {
  33.         backgroundColor: "white",
  34.         botAvatarBackgroundColor: "rgba(255, 255, 255, 1)",
  35.         // accent: 'rgba(255, 255, 255, 1)',
  36.         botAvatarInitials: "MPID",
  37.         userAvatarInitials: "ME",
  38.       };
  39.       // Add your BOT ID below
  40.       const BOT_ID = "my_bot_id";
  41.       const theURL =
  42.         "https://powerva.microsoft.com/api/botmanagement/v1/directline/directlinetoken?botId=" +
  43.         BOT_ID;
  44.  
  45.       const directLineTokenString = "directLineToken";
  46.  
  47.       const getDirectLineToken = async () => {
  48.         if (!sessionStorage) return undefined;
  49.  
  50.         const now = Date.now();
  51.  
  52.         let tokenItem = undefined;
  53.  
  54.         try {
  55.           tokenItem = JSON.parse(sessionStorage.getItem(directLineTokenString));
  56.         } catch (err) {
  57.           console.error("An error occurred: " + err);
  58.         }
  59.  
  60.         // If there is no token in storage or the token has expired
  61.         if (!tokenItem || (tokenItem && now > tokenItem.expiration)) {
  62.          try {
  63.            const res = await fetch(theURL);
  64.             const result = await res.json();
  65.             const tokenStorageItem = {
  66.               token: result.token,
  67.               expiration: now + result.expires_in * 1000,
  68.             };
  69.             sessionStorage.setItem(
  70.               directLineTokenString,
  71.               JSON.stringify(tokenStorageItem)
  72.             );
  73.             return result.token;
  74.           } catch (err) {
  75.             sessionStorage.removeItem(directLineTokenString);
  76.             console.error("An error occurred: " + err);
  77.             return undefined;
  78.           }
  79.         } else {
  80.           return tokenItem.token;
  81.         }
  82.       };
  83.  
  84.       (async function () {
  85.         const token = await getDirectLineToken();
  86.         window.WebChat.renderWebChat(
  87.           {
  88.             directLine: window.WebChat.createDirectLine({ token }),
  89.             styleSet,
  90.             store: store,
  91.             styleOptions: styleOptions,
  92.           },
  93.           document.getElementById("webchat")
  94.         );
  95.       })().catch(async (err) => {
  96.         console.error("An error occurred: " + err);
  97.       });
  98.     </script>
  99.   </body>
  100. </html>
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement