-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
78 lines (62 loc) · 2.74 KB
/
index.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
window.onload = function() {
// var dispatcher = new cf.EventDispatcher();
// dispatcher.addEventListener(cf.FlowEvents.USER_INPUT_UPDATE, function(event) {
// var userInput = event.detail.tag._values[0]
// console.log(userInput)
// console.log(event)
// },
// false
// );
var conversationalForm = new window.cf.ConversationalForm.startTheConversation({
formEl: document.getElementById("form"),
context: document.getElementById("cf-context"),
robotImage: ("assets/img/kwesi2.png"),
userImage: ("assets/img/user1.png"),
// eventDispatcher: dispatcher,
submitCallback: function() {
// var formData = conversationalForm.getFormData();
// console.log(formData);
var formDataSerialized = conversationalForm.getFormData(true);
// console.log(formDataSerialized);
if (formDataSerialized['cfc-services'] == "bank-settings" ){
if (formDataSerialized['cfc-bank-settings'] == 'block-card') {
var card = formDataSerialized['block-card-card']
var message = `Card number ${card} has been blocked`
}
else if (formDataSerialized['cfc-bank-settings'] == 'travel-notification') {
var date = formDataSerialized['travel-notification-date']
var message = `Your travel notification has been set on ${date}`
}
else if (formDataSerialized['cfc-bank-settings'] == 'spend-limit') {
var amount = formDataSerialized['spend-limit-amount']
var card = formDataSerialized['spend-limit-card']
var message = `The spend limit for card ${card} has been set to GH${amount}`
}
else if (formDataSerialized['cfc-bank-settings'] == 'freeze-account') {
var account = formDataSerialized['freeze-account-account']
var message = `The account ${account} has been frozen`
}
else {
var message = 'Done!'
}
}
else{
if (formDataSerialized['cfc-services'] == 'check-balance'){
var message = 'You have a balance of GH50000'
}
else if (formDataSerialized['cfc-services'] == 'transfer-money') {
var amount = formDataSerialized['transfer-money-amount']
var recipient = formDataSerialized['transfer-money-recipient']
var message = `An amount of ${amount} has been transfered to ${recipient}`
}
else {
var message = 'Done!'
}
}
conversationalForm.addRobotChatResponse(message);
formDataSerialized['cfc-bank-settings'].length = 0;
// console.log(formDataSerialized)
conversationalForm.remapTagsAndStartFrom(1,1,true);
}
});
};