Skip to content

Commit fe3ce54

Browse files
authored
Add files via upload
1 parent 8d95353 commit fe3ce54

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

functions/index.js

+16-22
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ app.intent('Card Pin', (conv, {number}) => {
7272

7373

7474
app.intent('Lock Card', (conv) => {
75-
var fraud='You can call 8608178983 if you want to report a fraud. '
75+
var fraud='You can call (860)-817-8983 if you want to report a fraud. '
7676
var response='';
7777
if (cardChecked===false){
7878
response='Please say the last four digits of your card. ';
@@ -112,39 +112,34 @@ app.intent('Unlock Card', (conv) => {
112112

113113

114114
app.intent('Search Transaction', (conv, {Product}) => {
115+
115116
if (cardChecked===false){
116117
conv.ask('Please say the last four digits of your card first. ');
117118
return null;
118119
} else if (pinConfirmed===false){
119120
conv.ask('You cannot search transaction before entering the pin! Please say the pin number of your card first. ');
120121
} else if (currentCardLocked) {
121-
conv.ask('You card ending in ' +currentCardNum.toString() + ' is locked. Please unlock your card first to search your transaction. ');
122+
conv.ask('You card ending in ' +currentCardNum.toString() + ' is locked. Please unlock your card first, to search your transaction. ');
122123
}else{
124+
var totalSpending=0;
123125
const theProduct = Product.toLowerCase()
124126
const currRef = dbRef.doc(currentCardNum.toString()).collection('Transactions');
125127
var theResponse = '';
126128
return currRef.where('Item', '==', theProduct).get()
127129
.then((snapshot) => {
128130
if (snapshot.empty) {
129-
conv.ask('Hmm. It looks like there are no recent purchases on ' + theProduct + '. ');
130-
conv.ask('Anything else you need?');
131+
conv.ask('Hmm. It looks like there are no recent purchases on ' + theProduct + '. Anything else you need? ');
131132
return null;
132133
}
133134

134-
var totalSpending=0;
135-
136-
snapshot.forEach(doc => {
137-
const {Date, Item, Price, Timestamp} = doc.data();
138-
totalSpending+=Price;
139-
});
140-
conv.ask('You spent $'+ totalSpending+ ' on ' + Product+'. ');
141135

142136
snapshot.forEach(doc => {
143137
const {Date, Item, Price, Timestamp} = doc.data();
138+
totalSpending=totalSpending+Price;
144139
theResponse = theResponse + 'There was a transaction on ' + Date + ' for $' + Price + '. ';
145140
});
146-
147-
theResponse = theResponse + 'Anything else you need help with?';
141+
var totalSpent='You spent $'+ totalSpending+ ' on ' + Product+'. ';
142+
theResponse = totalSpent+ theResponse + ' Anything else you need help with?';
148143
conv.ask(theResponse);
149144
return null;
150145
}).catch((e) => {
@@ -162,7 +157,7 @@ app.intent('Current Balance', (conv) => {
162157
} else if (pinConfirmed===false){
163158
conv.ask('You cannot check your balance before entering the pin! Please say the pin number of your card first. ');
164159
} else if (currentCardLocked) {
165-
conv.ask('You card ending in ' +currentCardNum.toString() + ' is locked. Please unlock your card first to check your balance. ');
160+
conv.ask('You card ending in ' +currentCardNum.toString() + ' is locked. Please unlock your card first, to check your balance. ');
166161
}else {
167162
if(currentBalance.toString() !== ''){
168163
conv.ask('You owe $' + currentBalance.toString() + '. What would you like to do' + currentName + '?');
@@ -179,7 +174,7 @@ app.intent('SearchByDate', (conv, {theNumber, DateString}) => {
179174
} else if (pinConfirmed===false){
180175
conv.ask('You cannot check your balance before entering the pin! Please say the pin number of your card first. ');
181176
} else if (currentCardLocked) {
182-
conv.ask('You card ending in ' +currentCardNum.toString() + ' is locked. Please unlock your card first to check your transactions. ');
177+
conv.ask('You card ending in ' +currentCardNum.toString() + ' is locked. Please unlock your card first, to check your transactions. ');
183178
}else {
184179
var today = new Date();
185180
var currTimeStamp = Math.round((new Date()).getTime() / 1000);
@@ -217,7 +212,6 @@ app.intent('SearchByDate', (conv, {theNumber, DateString}) => {
217212
.then((snapshot) => {
218213
if (snapshot.empty) {
219214
conv.ask('The card ending in ' + currentCardNum.toString() + ' has no transactions in that timeframe. ');
220-
conv.ask('What else would you like to do?');
221215
return null;
222216
}
223217

@@ -248,14 +242,14 @@ app.intent('Change Pin', (conv, {theNumber}) => {
248242
} else if (pinConfirmed===false){
249243
response='You cannot change your pin before entering the current one! Please say the pin number of your card first. ';
250244
}else if (currentCardLocked) {
251-
response='You card ending in ' +currentCardNum.toString() + ' is locked. Please unlock your card first to change your pin. ';
245+
response='You card ending in ' +currentCardNum.toString() + ' is locked. Please unlock your card first, to change your pin. ';
252246
}else {
253247
const currRef = dbRef.doc(currentCardNum.toString());
254248
if(theNumber.toString() !== ''){
255249
var updateSingle = currRef.update({cardPin: theNumber.toString()});
256250
response='Your pin has been changed to ' + theNumber.toString() +'. Is there anything else you need' + currentName +'?';
257251
}else{
258-
response="Oops, sorry I didn't get that! Please try again. ";
252+
response="Oops, sorry I didn't get that! Please say something like 'Change pin to 1234'. ";
259253
}
260254
}
261255
conv.ask(response);
@@ -271,11 +265,11 @@ app.intent('Make Payment', (conv, {number})=> {
271265
} else if (pinConfirmed===false){
272266
response='You cannot make a payment without saying your cards PIN! Please say the PIN number of your card.';
273267
}else if (currentCardLocked) {
274-
response='You card ending in ' +currentCardNum.toString() + ' is locked. Please unlock your card first to make a payment. ';
268+
response='You card ending in ' +currentCardNum.toString() + ' is locked. Please unlock your card first, to make a payment. ';
275269
}else if (number !== ''){
276270
const currRef = dbRef.doc(currentCardNum.toString());
277-
const minPay= String(min(25,currentBalance));
278-
response='Your total balance is $' + String(currentBalance) + '. Your minimum payment is $' +minPay + '. ';
271+
var minPay= Math.min(25,currentBalance);
272+
response='Your total balance is $' + String(currentBalance) + '. Your minimum payment is $' +String(minPay) + '. ';
279273
const amountPaid = number.toString();
280274
var newBal=Number(currentBalance) - Number(number);
281275
newBal=newBal.toFixed(2);
@@ -301,7 +295,7 @@ app.intent('Help', (conv, {Help_input})=> {
301295
" I'm always here to answer your questions, help you stay on top of your finances and make everyday baking easier.. ";
302296
}
303297
response=response + 'I can help with things like making a payment, checking your balance, locking or unlocking your card, or checking your past transactions. ';
304-
response=response+ "You can say 'pay my bill' to make a payment or 'How much I spent on gas?' to check your recent gas purchases. ";
298+
response=response+ "You can say something like 'pay my bill' to make a payment or 'How much I spent on gas?' to check your recent gas purchases. ";
305299
response=response+ 'What would you like to do'+ currentName + '?';
306300
conv.ask(response);
307301
});

0 commit comments

Comments
 (0)