new(basic.gblib) New SET SCHEDULE keyword.

This commit is contained in:
Rodrigo Rodriguez 2021-08-09 21:47:36 -03:00
parent e1c023bf52
commit 38d9ceb704
5 changed files with 33 additions and 18 deletions

View file

@ -140,8 +140,7 @@ export class DialogKeywords {
*
*/
public getToLst(array, member) {
if (array[0] && array[0]['gbarray'])
{
if (array[0] && array[0]['gbarray']) {
array = array.slice(1);
}
array = array.filter((v, i, a) => a.findIndex(t => (t[member] === v[member])) === i);
@ -253,14 +252,14 @@ export class DialogKeywords {
* Returns the name of the user acquired by WhatsApp API.
*/
public async userName(step) {
return step.context.activity.from.name;
return step ? step.context.activity.from.name : 'N/A';
}
/**
* OBSOLETE.
*/
public async getFrom(step) {
return await this.userMobile(step);
return step ? await this.userMobile(step) : 'N/A';
}
@ -271,6 +270,9 @@ export class DialogKeywords {
*
*/
public async userMobile(step) {
if (!step) {
return 'N/A';
}
if (isNaN(step.context.activity['mobile'])) {
if (step.context.activity.from && !isNaN(step.context.activity.from.id)) {
return step.context.activity.from.id;

View file

@ -779,7 +779,8 @@ export class GBVMService extends GBService {
// Creates a class DialogKeywords which is the *this* pointer
// in BASIC.
const user = await min.userProfile.get(step.context, {});
const user =step? await min.userProfile.get(step.context, {}): null;
const sandbox: DialogKeywords = new DialogKeywords(min, deployer, step, user);
// Injects the .gbdialog generated code into the VM.

View file

@ -109,7 +109,7 @@ export class ScheduleServices extends GBService {
GBLog.info(`Loading instances from storage...`);
let schedules;
try {
const options = { where: { state: 'active' } };
const options = { where: { instanceId: min.instance.instanceId } };
schedules = await GuaribasSchedule.findAll(options);
if (process.env.ENDPOINT_UPDATE === 'true') {
await CollectionUtil.asyncForEach(schedules, async item => {
@ -124,7 +124,7 @@ export class ScheduleServices extends GBService {
private ScheduleItem(item: GuaribasSchedule, min: GBMinInstance) {
GBLog.info(`Scheduling ${item.name} ${min.botId}...`);
GBLog.info(`Scheduling ${item.name} on ${min.botId}...`);
try {
const options = {
scheduled: true,
@ -133,21 +133,24 @@ export class ScheduleServices extends GBService {
const task = min["scheduleMap"][item.name];
if (task) {
task.destroy();
delete min["scheduleMap"][name];
task.stop();
min["scheduleMap"][item.name] = null;
}
min["scheduleMap"][item.name] = cron.schedule(
item.schedule,
async () => {
let script = item.name;
let min: GBMinInstance = GBServer.globals.minInstances.filter(
p => p.instance.instanceId === item.instanceId
)[0];
await GBVMService.callVM(script, min, null, null);
},
options
function () {
const finalData = async () => {
let script = item.name;
let min: GBMinInstance = GBServer.globals.minInstances.filter(
p => p.instance.instanceId === item.instanceId
)[0];
await GBVMService.callVM(script, min, null, null);
};
(async () => {
await finalData();
})();
}, options
);
GBLog.info(`Running .gbdialog word ${item.name} on:${item.schedule}...`);
} catch (error) { }

View file

@ -216,6 +216,10 @@ export class GBConversationalService {
}
public userMobile(step) {
if (!step)
{
return 'N/A';
}
if (isNaN(step.context.activity['mobile'])) {
if (step.context.activity.from && !isNaN(step.context.activity.from.id)) {
return step.context.activity.from.id;

View file

@ -79,6 +79,7 @@ import { GBDeployer } from './GBDeployer';
import urlJoin = require('url-join');
import fs = require('fs');
import { GoogleChatDirectLine } from '../../google-chat.gblib/services/GoogleChatDirectLine';
import { ScheduleServices } from '../../basic.gblib/services/ScheduleServices';
/**
* Minimal service layer for a bot and encapsulation of BOT Framework calls.
@ -160,6 +161,7 @@ export class GBMinService {
GBLog.error(`Error mounting bot ${instance.botId}: ${error.message}\n${error.stack}`);
}
});
}
@ -215,6 +217,9 @@ export class GBMinService {
await this.deployer.deployPackage(min, packagePath);
}
const service = new ScheduleServices();
await service.loadSchedules(min);
// Calls the loadBot context.activity for all packages.
await this.invokeLoadBot(GBServer.globals.appPackages, GBServer.globals.sysPackages, min);