Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

app.js 2.2 KB

You have to be logged in to leave a comment. Sign In
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  1. // This loads the environment variables from the .env file
  2. require('dotenv-extended').load();
  3. var builder = require('botbuilder');
  4. var restify = require('restify');
  5. // Setup Restify Server
  6. var server = restify.createServer();
  7. server.listen(process.env.port || process.env.PORT || 3978, function () {
  8. console.log('%s listening to %s', server.name, server.url);
  9. });
  10. // Create chat bot and listen to messages
  11. var connector = new builder.ChatConnector({
  12. appId: process.env.MICROSOFT_APP_ID,
  13. appPassword: process.env.MICROSOFT_APP_PASSWORD
  14. });
  15. server.post('/api/messages', connector.listen());
  16. var DialogLabels = {
  17. Hotels: 'Hotels',
  18. Flights: 'Flights',
  19. Support: 'Support'
  20. };
  21. var bot = new builder.UniversalBot(connector, [
  22. function (session) {
  23. // prompt for search option
  24. builder.Prompts.choice(
  25. session,
  26. 'Are you looking for a flight or a hotel?',
  27. [DialogLabels.Flights, DialogLabels.Hotels],
  28. {
  29. maxRetries: 3,
  30. retryPrompt: 'Not a valid option'
  31. });
  32. },
  33. function (session, result) {
  34. if (!result.response) {
  35. // exhausted attemps and no selection, start over
  36. session.send('Ooops! Too many attemps :( But don\'t worry, I\'m handling that exception and you can try again!');
  37. return session.endDialog();
  38. }
  39. // on error, start over
  40. session.on('error', function (err) {
  41. session.send('Failed with message: %s', err.message);
  42. session.endDialog();
  43. });
  44. // continue on proper dialog
  45. var selection = result.response.entity;
  46. switch (selection) {
  47. case DialogLabels.Flights:
  48. return session.beginDialog('flights');
  49. case DialogLabels.Hotels:
  50. return session.beginDialog('hotels');
  51. }
  52. }
  53. ]);
  54. bot.dialog('flights', require('./flights'));
  55. bot.dialog('hotels', require('./hotels'));
  56. bot.dialog('support', require('./support'))
  57. .triggerAction({
  58. matches: [/help/i, /support/i, /problem/i]
  59. });
  60. // log any bot errors into the console
  61. bot.on('error', function (e) {
  62. console.log('And error ocurred', e);
  63. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...