forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
details.js
125 lines (118 loc) · 4.1 KB
/
details.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var util = require('util');
var builder = require('botbuilder');
var lib = new builder.Library('details');
// Recipient & Sender details
lib.dialog('/', [
function (session) {
builder.Prompts.text(session, 'ask_recipient_first_name');
},
function (session, args) {
session.dialogData.recipientFirstName = args.response;
builder.Prompts.text(session, 'ask_recipient_last_name');
},
function (session, args) {
session.dialogData.recipientLastName = args.response;
session.beginDialog('validators:phonenumber', {
prompt: session.gettext('ask_recipient_phone_number'),
retryPrompt: session.gettext('invalid_phone_number')
});
},
function (session, args) {
session.dialogData.recipientPhoneNumber = args.response;
session.beginDialog('validators:notes', {
prompt: session.gettext('ask_note'),
retryPrompt: session.gettext('invalid_note')
});
},
function (session, args) {
session.dialogData.note = args.response;
session.beginDialog('sender');
},
function (session, args) {
session.dialogData.sender = args.sender;
var details = {
recipient: {
firstName: session.dialogData.recipientFirstName,
lastName: session.dialogData.recipientLastName,
phoneNumber: session.dialogData.recipientPhoneNumber
},
note: session.dialogData.note,
sender: session.dialogData.sender
};
session.endDialogWithResult({ details: details });
}
]);
// Sender details
var UseSavedInfoChoices = {
Yes: 'yes',
No: 'edit'
};
lib.dialog('sender', [
function (session, args, next) {
var sender = session.userData.sender;
if (sender) {
// sender data previously saved
var promptMessage = session.gettext('use_this_email_and_phone_number', sender.email, sender.phoneNumber);
builder.Prompts.choice(session, promptMessage, [
session.gettext(UseSavedInfoChoices.Yes),
session.gettext(UseSavedInfoChoices.No)
]);
} else {
// no data
next();
}
},
function (session, args, next) {
if (args.response && args.response.entity === session.gettext(UseSavedInfoChoices.Yes) && session.userData.sender) {
// Use previously saved data, store it in dialogData
// Next steps will skip if present
session.dialogData.useSaved = true;
session.dialogData.email = session.userData.sender.email;
session.dialogData.phoneNumber = session.userData.sender.phoneNumber;
}
next();
},
function (session, args, next) {
if (session.dialogData.useSaved) {
return next();
}
session.beginDialog('validators:email', {
prompt: session.gettext('ask_email'),
retryPrompt: session.gettext('invalid_email')
});
},
function (session, args, next) {
if (session.dialogData.useSaved) {
return next();
}
session.dialogData.email = args.response;
session.beginDialog('validators:phonenumber', {
prompt: session.gettext('ask_phone_number'),
retryPrompt: session.gettext('invalid_phone_number')
});
},
function (session, args, next) {
if (session.dialogData.useSaved) {
return next();
}
session.dialogData.phoneNumber = args.response;
builder.Prompts.confirm(session, 'ask_save_info');
},
function (session, args) {
var sender = {
email: session.dialogData.email,
phoneNumber: session.dialogData.phoneNumber
};
// Save data?
var shouldSave = args.response;
if (shouldSave) {
session.userData.sender = sender;
}
// return sender information
session.endDialogWithResult({ sender: sender });
}
]);
// Export createLibrary() function
module.exports.createLibrary = function () {
return lib.clone();
};