fix(basic.gblib): TOLIST fixed for empty values.

This commit is contained in:
Rodrigo Rodriguez 2021-08-14 19:29:27 -03:00
parent 3ad3459e4b
commit 49691710b9
5 changed files with 186 additions and 127 deletions

7
package-lock.json generated
View file

@ -1,6 +1,6 @@
{ {
"name": "botserver", "name": "botserver",
"version": "2.0.127", "version": "2.0.129",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -7559,6 +7559,11 @@
"integrity": "sha512-hpA5C/YrPjucXypHPPc0oJ1l9Hf6wWbiOL7Ik42cxnsUOhWiCB/fylKbKqqJalW9FgkNQCw16YO8uW9Hs0Iy1A==", "integrity": "sha512-hpA5C/YrPjucXypHPPc0oJ1l9Hf6wWbiOL7Ik42cxnsUOhWiCB/fylKbKqqJalW9FgkNQCw16YO8uW9Hs0Iy1A==",
"dev": true "dev": true
}, },
"date-diff": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/date-diff/-/date-diff-0.2.2.tgz",
"integrity": "sha512-D1Mq5j938ANAf4foPgAoh5Q45vkz5e5yEsi6TUeVvCcLs4KZMhy79hXHMc8zGh48bSb7iyiim2Vrpppi34/Rjw=="
},
"date-fns": { "date-fns": {
"version": "1.30.1", "version": "1.30.1",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.30.1.tgz", "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.30.1.tgz",

View file

@ -76,6 +76,7 @@
"botlib": "1.9.3", "botlib": "1.9.3",
"cli-spinner": "0.2.10", "cli-spinner": "0.2.10",
"core-js": "3.14.0", "core-js": "3.14.0",
"date-diff": "^0.2.2",
"dotenv-extended": "2.9.0", "dotenv-extended": "2.9.0",
"exceljs": "4.2.1", "exceljs": "4.2.1",
"express": "4.17.1", "express": "4.17.1",

View file

@ -39,6 +39,8 @@ import { GBServer } from '../../../src/app';
import { GBDeployer } from '../../core.gbapp/services/GBDeployer'; import { GBDeployer } from '../../core.gbapp/services/GBDeployer';
import { SecService } from '../../security.gbapp/services/SecService'; import { SecService } from '../../security.gbapp/services/SecService';
import { SystemKeywords } from './SystemKeywords'; import { SystemKeywords } from './SystemKeywords';
var DateDiff = require('date-diff');
/** /**
* Base services of conversation to be called by BASIC which * Base services of conversation to be called by BASIC which
@ -154,6 +156,55 @@ export class DialogKeywords {
return date.toLocaleString(this.getContentLocaleWithCulture(contentLocale), { weekday: 'short' }); return date.toLocaleString(this.getContentLocaleWithCulture(contentLocale), { weekday: 'short' });
} }
/**
* Returns an object ready to get information about difference in several ways
* like years, months or days.
*
* @example days = DATEDIFF date1, date2
*
*/
public dateDiff(date1, date2) {
let dt1 = date1;
let dt2 = date2;
if (!(dt1 instanceof Date)) {
dt1 = new Date(dt1);
}
if (!(dt2 instanceof Date)) {
dt2 = new Date(dt2);
}
return new DateDiff(date1, date2);
}
/**
* Returns specified date week day in format 'Mon'.
*
* @example DATEADD date1, date2, mode, value
*
* https://stackoverflow.com/a/1214753/18511
*/
public dateAdd(date, units, mode) {
let dateCopy = date;
if (!(dateCopy instanceof Date)) {
dateCopy = new Date(dateCopy);
}
var ret = new Date(dateCopy); //don't change original date
var checkRollover = function () { if (ret.getDate() != date.getDate()) ret.setDate(0); };
switch (String(mode).toLowerCase()) {
case 'year': ret.setFullYear(ret.getFullYear() + units); checkRollover(); break;
case 'quarter': ret.setMonth(ret.getMonth() + 3 * units); checkRollover(); break;
case 'month': ret.setMonth(ret.getMonth() + units); checkRollover(); break;
case 'week': ret.setDate(ret.getDate() + 7 * units); break;
case 'day': ret.setDate(ret.getDate() + units); break;
case 'hour': ret.setTime(ret.getTime() + units * 3600000); break;
case 'minute': ret.setTime(ret.getTime() + units * 60000); break;
case 'second': ret.setTime(ret.getTime() + units * 1000); break;
default: ret = undefined; break;
}
return ret;
}
/** /**
* Returns specified list member separated by comma. * Returns specified list member separated by comma.
* *
@ -173,7 +224,7 @@ export class DialogKeywords {
array = array.join(", "); array = array.join(", ");
return array; return array;
} }
/** /**
* Returns the specified time in format hh:dd. * Returns the specified time in format hh:dd.
@ -192,7 +243,7 @@ export class DialogKeywords {
return i; return i;
} }
return addZero(date.getHours()) + ':' + addZero(date.getMinutes()); return addZero(date.getHours()) + ':' + addZero(date.getMinutes());
} }
/** /**
* Returns current time in format hh:dd. * Returns current time in format hh:dd.
@ -214,7 +265,7 @@ export class DialogKeywords {
{ timeZone: process.env.DEFAULT_TIMEZONE })); { timeZone: process.env.DEFAULT_TIMEZONE }));
return now.getHours() + ':' + now.getMinutes(); return now.getHours() + ':' + now.getMinutes();
} }
/** /**
* Sends a file to a given mobile. * Sends a file to a given mobile.
@ -225,7 +276,7 @@ export class DialogKeywords {
public async sendFileTo(step, mobile, filename, caption) { public async sendFileTo(step, mobile, filename, caption) {
GBLog.info(`BASIC: SEND FILE TO '${mobile}', filename '${filename}'.`); GBLog.info(`BASIC: SEND FILE TO '${mobile}', filename '${filename}'.`);
return await this.internalSendFile(null, mobile, filename, caption); return await this.internalSendFile(null, mobile, filename, caption);
} }
/** /**
* Sends a file to the current user. * Sends a file to the current user.
@ -235,7 +286,7 @@ export class DialogKeywords {
*/ */
public async sendFile(step, filename, caption) { public async sendFile(step, filename, caption) {
return await this.internalSendFile(step, null, filename, caption); return await this.internalSendFile(step, null, filename, caption);
} }
/** /**
* Defines the current language of the bot conversation. * Defines the current language of the bot conversation.
@ -251,7 +302,7 @@ export class DialogKeywords {
await this.min.userProfile.set(step.context, user); await this.min.userProfile.set(step.context, user);
this.user = user; this.user = user;
} }
/** /**
* Defines the maximum lines to scan in spreedsheets. * Defines the maximum lines to scan in spreedsheets.
@ -264,7 +315,7 @@ export class DialogKeywords {
user.basicOptions.maxLines = count; user.basicOptions.maxLines = count;
await this.min.userProfile.set(step.context, user); await this.min.userProfile.set(step.context, user);
this.user = user; this.user = user;
} }
/** /**
* Defines translator behaviour. * Defines translator behaviour.
@ -277,21 +328,21 @@ export class DialogKeywords {
user.basicOptions.translatorOn = (on.trim() === "on"); user.basicOptions.translatorOn = (on.trim() === "on");
await this.min.userProfile.set(step.context, user); await this.min.userProfile.set(step.context, user);
this.user = user; this.user = user;
} }
/** /**
* Returns the name of the user acquired by WhatsApp API. * Returns the name of the user acquired by WhatsApp API.
*/ */
public async userName(step) { public async userName(step) {
return step ? step.context.activity.from.name : 'N/A'; return step ? step.context.activity.from.name : 'N/A';
} }
/** /**
* OBSOLETE. * OBSOLETE.
*/ */
public async getFrom(step) { public async getFrom(step) {
return step ? await this.userMobile(step) : 'N/A'; return step ? await this.userMobile(step) : 'N/A';
} }
/** /**
@ -312,7 +363,7 @@ export class DialogKeywords {
} else { } else {
return step.context.activity['mobile']; return step.context.activity['mobile'];
} }
} }
/** /**
* Shows the subject menu to the user * Shows the subject menu to the user
@ -322,7 +373,7 @@ export class DialogKeywords {
*/ */
public async showMenu(step) { public async showMenu(step) {
return await step.beginDialog('/menu'); return await step.beginDialog('/menu');
} }
/** /**
* Performs the transfer of the conversation to a human agent. * Performs the transfer of the conversation to a human agent.
@ -332,7 +383,7 @@ export class DialogKeywords {
*/ */
public async transfer(step) { public async transfer(step) {
return await step.beginDialog('/t'); return await step.beginDialog('/t');
} }
/** /**
* Hears something from user and put it in a variable * Hears something from user and put it in a variable
@ -354,7 +405,7 @@ export class DialogKeywords {
} else { } else {
await step.beginDialog('/hear', opts); await step.beginDialog('/hear', opts);
} }
} }
/** /**
* Talks to the user by using the specified text. * Talks to the user by using the specified text.
@ -362,7 +413,7 @@ export class DialogKeywords {
public async talk(step, text: string) { public async talk(step, text: string) {
await this.min.conversationalService['sendTextWithOptions'](this.min, step, text, await this.min.conversationalService['sendTextWithOptions'](this.min, step, text,
this.user.basicOptions.translatorOn, null); this.user.basicOptions.translatorOn, null);
} }
private static getChannel(step): string { private static getChannel(step): string {
if (!isNaN(step.context.activity['mobile'])) { if (!isNaN(step.context.activity['mobile'])) {
@ -373,7 +424,7 @@ export class DialogKeywords {
} }
return 'webchat'; return 'webchat';
} }
} }
/** /**
@ -402,5 +453,5 @@ export class DialogKeywords {
await this.min.conversationalService.sendFile(this.min, step, mobile, url, caption); await this.min.conversationalService.sendFile(this.min, step, mobile, url, caption);
} }
} }
} }

View file

@ -81,7 +81,7 @@ export class GBVMService extends GBService {
const vbsFile = filename.substr(0, filename.indexOf('docx')) + 'vbs'; const vbsFile = filename.substr(0, filename.indexOf('docx')) + 'vbs';
const fullVbsFile = urlJoin(folder, vbsFile); const fullVbsFile = urlJoin(folder, vbsFile);
const docxStat = fs.statSync(urlJoin(folder, wordFile)); const docxStat = fs.statSync(urlJoin(folder, wordFile));
const interval = 1000; // If compiled is older 30 seconds, then recompile. const interval = 30000; // If compiled is older 30 seconds, then recompile.
let writeVBS = true; let writeVBS = true;
if (fs.existsSync(fullVbsFile)) { if (fs.existsSync(fullVbsFile)) {
const vbsStat = fs.statSync(fullVbsFile); const vbsStat = fs.statSync(fullVbsFile);
@ -96,7 +96,6 @@ export class GBVMService extends GBService {
if (writeVBS) { if (writeVBS) {
let text = await this.getTextFromWord(folder, wordFile); let text = await this.getTextFromWord(folder, wordFile);
const schedule = GBVMService.getSetScheduleKeywordArgs(text); const schedule = GBVMService.getSetScheduleKeywordArgs(text);
const s = new ScheduleServices(); const s = new ScheduleServices();
if (schedule) { if (schedule) {
@ -105,7 +104,6 @@ export class GBVMService extends GBService {
else { else {
await s.deleteScheduleIfAny(min, mainName); await s.deleteScheduleIfAny(min, mainName);
} }
text = text.replace(/SET SCHEDULE (.*)/gi, ''); text = text.replace(/SET SCHEDULE (.*)/gi, '');
fs.writeFileSync(urlJoin(folder, vbsFile), text); fs.writeFileSync(urlJoin(folder, vbsFile), text);
} }
@ -184,8 +182,8 @@ export class GBVMService extends GBService {
from = mobile; from = mobile;
ubound = function(array){return array.length}; ubound = function(array){return array.length};
isarray = function(array){return Array.isArray(array) }; isarray = function(array){return Array.isArray(array) };
weekday = this.getWeekFromDate; weekday = this.getWeekFromDate.bind(this);
hour = this.getHourFromDate; hour = this.getHourFromDate.bind(this);
tolist = this.getToLst; tolist = this.getToLst;
headers = {}; headers = {};

View file

@ -80,8 +80,7 @@ export class SystemKeywords {
} }
public async sortBy(array, memberName) { public async sortBy(array, memberName) {
return array ? array.sort(p => return array ? array.sort(p => { if (p) { return p[memberName]; } }) :
{ if (p) { return p[memberName]; } }) :
null; null;
} }
@ -351,6 +350,7 @@ export class SystemKeywords {
} }
function isValidNumber(number) { function isValidNumber(number) {
if (number === '') { return false }
return !isNaN(number); return !isNaN(number);
} }
@ -456,6 +456,10 @@ export class SystemKeywords {
case 'date': case 'date':
const resultDate = new Date(result); const resultDate = new Date(result);
switch (filter.operator) { switch (filter.operator) {
case '=':
if (resultDate.getTime() == filter.value.getTime())
filterAcceptCount++;
break;
case '<': case '<':
if (resultDate.getTime() < filter.value.getTime()) if (resultDate.getTime() < filter.value.getTime())
filterAcceptCount++; filterAcceptCount++;