Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #11 from ElementoLab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
alexsigaras committed Jul 11, 2018
2 parents 270a466 + b0a044d commit f6251cc
Show file tree
Hide file tree
Showing 4 changed files with 668 additions and 311 deletions.
25 changes: 25 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const configs = require('./config/configs');
const _ = require('underscore');
var fs = require('fs');
var client = require('./lib/client');
var handlebars = require('node-handlebars');
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

//=========================================================
// Bot Setup
Expand All @@ -33,6 +35,29 @@ bot.recognizer(recognizer);

// Configure PMKB Client. ENV variables are stored in Azure.
const pmkbClient = new PMKBClient(process.env.PMKB_HOST, process.env.PMKB_USER, process.env.PMKB_PASS);
var path = __dirname + '/views';
var views = handlebars.create({partialsDir: path});

server.get('/index.html', function (req, res) {
var url = 'https://webchat.botframework.com/api/tokens';
var botKey = process.env.MICROSOFT_WEB_CHAT_SECRET_KEY;
var speechKey = process.env.MICROSOFT_SPEECH_API_KEY;
var botToken = getBotToken(url, botKey);
views.engine(path + '/index.html', {botToken: botToken, speechKey: speechKey}, function(err, html) {
if (err) {
throw err;
}
res.end(html);
});
});

function getBotToken(url, key) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", url, false); // false for synchronous request'
xmlHttp.setRequestHeader("Authorization", "BotConnector " + key);
xmlHttp.send(null);
return xmlHttp.responseText;
}

//=========================================================
// Bot Dialogs
Expand Down
Loading

0 comments on commit f6251cc

Please sign in to comment.