/examples/feature-azureSql/app.js

https://bitbucket.org/rollingstone99/botbuilder-azure-aeonx · JavaScript · 53 lines · 28 code · 8 blank · 17 comment · 2 complexity · b4795825659f4b950d4db9a6c438594c MD5 · raw file

  1. /*-----------------------------------------------------------------------------
  2. This Bot demonstrates how to use Azure SQL for bot storage.
  3. # RUN THE BOT:
  4. -Using Azure SQL
  5. -Create an Azure SQL database (https://docs.microsoft.com/en-us/azure/sql-database/sql-database-get-started-portal)
  6. -Replace userName, password, server, database, and table to your preference in the code below.
  7. -IMPORTANT: You should create your table before attempting to connect your bot to it.
  8. If you wish for the table to be created if it isn't initially found, you must add the key-value pair `enforceTable: true` to your SQL configuration. See Line 25.
  9. The minimal SQL script used to create the table is: `CREATE TABLE your_specified_table_name (id NVARCHAR(200), data NVARCHAR(1000), isCompressed BIT`
  10. -Set rowCollectionOnRequestCompletion to true to retrieve row content.
  11. -Run the bot from the command line using "node app.js"
  12. -Type anything, and the bot will respond showing the text you typed
  13. -----------------------------------------------------------------------------*/
  14. var builder = require('botbuilder');
  15. var azure = require('../../');
  16. var restify = require('restify');
  17. var sqlConfig = {
  18. userName: '<Your-DB-Login>',
  19. password: '<Your-DB-Login-Password>',
  20. server: '<Host>',
  21. // enforceTable: true, // If this property is not set to true it defaults to false. When false if the specified table is not found, the bot will throw an error.
  22. options: {
  23. database: '<DB-Name>',
  24. table: '<DB-Table>',
  25. encrypt: true,
  26. rowCollectionOnRequestCompletion: true
  27. }
  28. }
  29. var sqlClient = new azure.AzureSqlClient(sqlConfig);
  30. var sqlStorage = new azure.AzureBotStorage({ gzipData: false }, sqlClient);
  31. var connector = new builder.ChatConnector({
  32. appId: process.env.MICROSOFT_APP_ID,
  33. appPassword: process.env.MICROSOFT_APP_PASSWORD
  34. });
  35. var bot = new builder.UniversalBot(connector, function (session) {
  36. session.send("You said: %s", session.message.text);
  37. }).set('storage', sqlStorage);
  38. var server = restify.createServer();
  39. server.listen(process.env.port || process.env.PORT || 3978, function () {
  40. console.log('%s listening to %s', server.name, server.url);
  41. });
  42. server.post('/api/messages', connector.listen());