This repository was archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathapp.js
51 lines (38 loc) · 2.04 KB
/
app.js
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
/*-----------------------------------------------------------------------------
This Bot demonstrates how to use Azure DocumentDb for bot storage.
# RUN THE BOT:
-Using local DocumentDb emulator:
-Install DocumentDb emulator (https://docs.microsoft.com/en-us/azure/documentdb/documentdb-nosql-local-emulator)
-Start the DocumentDb emulator
-Set the environment variable NODE_TLS_REJECT_UNAUTHORIZED to the value 0
-Run the bot from the command line using "node app.js"
-Type anything, and the bot will respond showing the text you typed
-Using Azure DocumentDb
-Create a DocumentDb database (https://azure.microsoft.com/en-us/resources/videos/create-documentdb-on-azure/)
-Replace host, masterKey, database and collection to your preference in the code below
-Run the bot from the command line using "node app.js"
-Type anything, and the bot will respond showing the text you typed
-----------------------------------------------------------------------------*/
var builder = require('botbuilder');
var azure = require('../../');
var restify = require('restify');
var documentDbOptions = {
host: 'https://localhost:8081', // Host for local DocDb emulator
masterKey: 'C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==', // Fixed key for local DocDb emulator
database: 'botdocdb',
collection: 'botdata'
};
var docDbClient = new azure.DocumentDbClient(documentDbOptions);
var tableStorage = new azure.AzureBotStorage({ gzipData: false }, docDbClient);
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector, function (session) {
session.send("You said: %s", session.message.text);
}).set('storage', tableStorage);
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
server.post('/api/messages', connector.listen());