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

product-selection.js 2.4 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
  1. var _ = require('lodash');
  2. var builder = require('botbuilder');
  3. var products = require('../../services/products');
  4. var SimpleWaterfallDialog = require('./SimpleWaterfallDialog');
  5. var CarouselPagination = require('./CarouselPagination');
  6. var carouselOptions = {
  7. showMoreTitle: 'title_show_more',
  8. showMoreValue: 'show_more',
  9. selectTemplate: 'select',
  10. pageSize: 5,
  11. unknownOption: 'unknown_option'
  12. };
  13. var lib = new builder.Library('product-selection');
  14. // These steps are defined as a waterfall dialog,
  15. // but the control is done manually by calling the next func argument.
  16. lib.dialog('/',
  17. new SimpleWaterfallDialog([
  18. // First message
  19. function (session, args, next) {
  20. session.send('choose_category');
  21. next();
  22. },
  23. // Show Categories
  24. CarouselPagination.create(products.getCategories, products.getCategory, categoryMapping, carouselOptions),
  25. // Category selected
  26. function (session, args, next) {
  27. var category = args.selected;
  28. session.send('choose_bouquet_from_category', category.name);
  29. session.dialogData.category = category;
  30. session.message.text = null; // remove message so next step does not take it as input
  31. next();
  32. },
  33. // Show Products
  34. function (session, args, next) {
  35. var categoryName = session.dialogData.category.name;
  36. CarouselPagination.create(
  37. function (pageNumber, pageSize) { return products.getProducts(categoryName, pageNumber, pageSize); },
  38. products.getProduct,
  39. productMapping,
  40. carouselOptions
  41. )(session, args, next);
  42. },
  43. // Product selected
  44. function (session, args, next) {
  45. // this is last step, calling next with args will end in session.endDialogWithResult(args)
  46. next({ selection: args.selected });
  47. }
  48. ]));
  49. function categoryMapping(category) {
  50. return {
  51. title: category.name,
  52. imageUrl: category.imageUrl,
  53. buttonLabel: 'view_bouquets'
  54. };
  55. }
  56. function productMapping(product) {
  57. return {
  58. title: product.name,
  59. subtitle: '$ ' + product.price.toFixed(2),
  60. imageUrl: product.imageUrl,
  61. buttonLabel: 'choose_this'
  62. };
  63. }
  64. // Export createLibrary() function
  65. module.exports.createLibrary = function () {
  66. return lib.clone();
  67. };
Tip!

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

Comments

Loading...