forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shop.js
59 lines (56 loc) · 2.08 KB
/
shop.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
51
52
53
54
55
56
57
58
59
var util = require('util');
var builder = require('botbuilder');
var lib = new builder.Library('shop');
lib.dialog('/', [
function (session) {
// Ask for delivery address using 'address' library
session.beginDialog('address:/',
{
promptMessage: session.gettext('provide_delivery_address', session.message.user.name || session.gettext('default_user_name'))
});
},
function (session, args) {
// Retrieve address, continue to shop
session.dialogData.recipientAddress = args.address;
session.beginDialog('product-selection:/');
},
function (session, args) {
// Retrieve selection, continue to delivery date
session.dialogData.selection = args.selection;
session.beginDialog('delivery:date');
},
function (session, args) {
// Retrieve deliveryDate, continue to details
session.dialogData.deliveryDate = args.deliveryDate;
session.send('confirm_choice', session.dialogData.selection.name, session.dialogData.deliveryDate.toLocaleDateString());
session.beginDialog('details:/');
},
function (session, args) {
// Retrieve details, continue to billing address
session.dialogData.details = args.details;
session.beginDialog('address:billing');
},
function (session, args, next) {
// Retrieve billing address
session.dialogData.billingAddress = args.billingAddress;
next();
},
function (session, args) {
// Continue to checkout
var order = {
selection: session.dialogData.selection,
delivery: {
date: session.dialogData.deliveryDate,
address: session.dialogData.recipientAddress
},
details: session.dialogData.details,
billingAddress: session.dialogData.billingAddress
};
console.log('order', order);
session.beginDialog('checkout:/', { order: order });
}
]);
// Export createLibrary() function
module.exports.createLibrary = function () {
return lib.clone();
};