Created
October 11, 2017 22:52
-
-
Save nwhitmont/bb9007271231728691b7225a9fd667b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
.env: | |
MICROSOFT_APP_ID= | |
MICROSOFT_APP_PASSWORD= | |
BING_MAPS_API_KEY= | |
package.json: | |
{ | |
"name": "botbuilder-location-example", | |
"version": "0.7.0", | |
"description": "Bing Location Control for Bot Framework Node.js SDK Example", | |
"repository": "https://github.com/Microsoft/BotBuilder-Location", | |
"author": "Microsoft Corp.", | |
"license": "MIT", | |
"scripts": { | |
"start": "node app" | |
}, | |
"dependencies": { | |
"botbuilder": "^3.11.0", | |
"botbuilder-location": "^2.0.0", | |
"dotenv-extended": "^2.0.1", | |
"restify": "^6.0.1" | |
} | |
} | |
*/ | |
// LOAD ENV VARS | |
require('dotenv-extended').load(); | |
// IMPORT NODE MODULES | |
var builder = require('botbuilder'); | |
var restify = require('restify'); | |
var locationDialog = require('botbuilder-location'); | |
// LOCAL VARS | |
var locationDialogOptions = { | |
prompt: 'Where should I ship your order?', | |
useNativeControl: true, | |
reverseGeocode: true, | |
skipFavorites: false, | |
skipConfirmationAsk: true, | |
requiredFields: | |
locationDialog.LocationRequiredFields.streetAddress | | |
locationDialog.LocationRequiredFields.locality | | |
locationDialog.LocationRequiredFields.region | | |
locationDialog.LocationRequiredFields.postalCode | | |
locationDialog.LocationRequiredFields.country | |
}; | |
// init restify server | |
var server = restify.createServer(); | |
server.listen(process.env.port || process.env.PORT || 3978, function () { | |
console.log(`${server.name} listening at: ${server.url}`); | |
}); | |
// init Bot Framework connector | |
var connector = new builder.ChatConnector({ | |
appId: process.env.MICROSOFT_APP_ID, | |
appPassword: process.env.MICROSOFT_APP_PASSWORD | |
}); | |
// init bot with connector config | |
var bot = new builder.UniversalBot(connector); | |
// bind connector to /api/messages endpoint | |
server.post('/api/messages', connector.listen()); | |
// add location dialog to bot library | |
bot.library(locationDialog.createLibrary(process.env.BING_MAPS_API_KEY)); | |
// configure default dialog handler | |
bot.dialog('/', [ | |
function (session) { | |
session.send('Welcome to the Bing Location Control demo.') | |
locationDialog.getLocation(session, locationDialogOptions); | |
}, | |
function (session, results) { | |
if (results.response) { | |
session.send(`Thanks, I will ship your item to: ${results.response.formattedAddress}`) | |
} | |
} | |
]); | |
// END OF LINE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment