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

hotels.js 2.6 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
73
74
75
76
77
78
79
80
81
82
83
  1. var builder = require('botbuilder');
  2. var Store = require('./store');
  3. module.exports = [
  4. // Destination
  5. function (session) {
  6. session.send('Welcome to the Hotels finder!');
  7. builder.Prompts.text(session, 'Please enter your destination');
  8. },
  9. function (session, results, next) {
  10. session.dialogData.destination = results.response;
  11. session.send('Looking for hotels in %s', results.response);
  12. next();
  13. },
  14. // Check-in
  15. function (session) {
  16. builder.Prompts.time(session, 'When do you want to check in?');
  17. },
  18. function (session, results, next) {
  19. session.dialogData.checkIn = results.response.resolution.start;
  20. next();
  21. },
  22. // Nights
  23. function (session) {
  24. builder.Prompts.number(session, 'How many nights do you want to stay?');
  25. },
  26. function (session, results, next) {
  27. session.dialogData.nights = results.response;
  28. next();
  29. },
  30. // Search...
  31. function (session) {
  32. var destination = session.dialogData.destination;
  33. var checkIn = new Date(session.dialogData.checkIn);
  34. var checkOut = checkIn.addDays(session.dialogData.nights);
  35. session.send(
  36. 'Ok. Searching for Hotels in %s from %d/%d to %d/%d...',
  37. destination,
  38. checkIn.getMonth() + 1, checkIn.getDate(),
  39. checkOut.getMonth() + 1, checkOut.getDate());
  40. // Async search
  41. Store
  42. .searchHotels(destination, checkIn, checkOut)
  43. .then(function (hotels) {
  44. // Results
  45. session.send('I found in total %d hotels for your dates:', hotels.length);
  46. var message = new builder.Message()
  47. .attachmentLayout(builder.AttachmentLayout.carousel)
  48. .attachments(hotels.map(hotelAsAttachment));
  49. session.send(message);
  50. // End
  51. session.endDialog();
  52. });
  53. }
  54. ];
  55. // Helpers
  56. function hotelAsAttachment(hotel) {
  57. return new builder.HeroCard()
  58. .title(hotel.name)
  59. .subtitle('%d stars. %d reviews. From $%d per night.', hotel.rating, hotel.numberOfReviews, hotel.priceStarting)
  60. .images([new builder.CardImage().url(hotel.image)])
  61. .buttons([
  62. new builder.CardAction()
  63. .title('More details')
  64. .type('openUrl')
  65. .value('https://www.bing.com/search?q=hotels+in+' + encodeURIComponent(hotel.location))
  66. ]);
  67. }
  68. Date.prototype.addDays = function (days) {
  69. var date = new Date(this.valueOf());
  70. date.setDate(date.getDate() + days);
  71. return date;
  72. };
Tip!

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

Comments

Loading...