new(basic.gblib) New SET SCHEDULE keyword.
This commit is contained in:
parent
e1c023bf52
commit
38d9ceb704
5 changed files with 33 additions and 18 deletions
|
@ -140,8 +140,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public getToLst(array, member) {
|
public getToLst(array, member) {
|
||||||
if (array[0] && array[0]['gbarray'])
|
if (array[0] && array[0]['gbarray']) {
|
||||||
{
|
|
||||||
array = array.slice(1);
|
array = array.slice(1);
|
||||||
}
|
}
|
||||||
array = array.filter((v, i, a) => a.findIndex(t => (t[member] === v[member])) === i);
|
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.
|
* Returns the name of the user acquired by WhatsApp API.
|
||||||
*/
|
*/
|
||||||
public async userName(step) {
|
public async userName(step) {
|
||||||
return step.context.activity.from.name;
|
return step ? step.context.activity.from.name : 'N/A';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OBSOLETE.
|
* OBSOLETE.
|
||||||
*/
|
*/
|
||||||
public async getFrom(step) {
|
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) {
|
public async userMobile(step) {
|
||||||
|
if (!step) {
|
||||||
|
return 'N/A';
|
||||||
|
}
|
||||||
if (isNaN(step.context.activity['mobile'])) {
|
if (isNaN(step.context.activity['mobile'])) {
|
||||||
if (step.context.activity.from && !isNaN(step.context.activity.from.id)) {
|
if (step.context.activity.from && !isNaN(step.context.activity.from.id)) {
|
||||||
return step.context.activity.from.id;
|
return step.context.activity.from.id;
|
||||||
|
|
|
@ -779,7 +779,8 @@ export class GBVMService extends GBService {
|
||||||
|
|
||||||
// Creates a class DialogKeywords which is the *this* pointer
|
// Creates a class DialogKeywords which is the *this* pointer
|
||||||
// in BASIC.
|
// 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);
|
const sandbox: DialogKeywords = new DialogKeywords(min, deployer, step, user);
|
||||||
|
|
||||||
// Injects the .gbdialog generated code into the VM.
|
// Injects the .gbdialog generated code into the VM.
|
||||||
|
|
|
@ -109,7 +109,7 @@ export class ScheduleServices extends GBService {
|
||||||
GBLog.info(`Loading instances from storage...`);
|
GBLog.info(`Loading instances from storage...`);
|
||||||
let schedules;
|
let schedules;
|
||||||
try {
|
try {
|
||||||
const options = { where: { state: 'active' } };
|
const options = { where: { instanceId: min.instance.instanceId } };
|
||||||
schedules = await GuaribasSchedule.findAll(options);
|
schedules = await GuaribasSchedule.findAll(options);
|
||||||
if (process.env.ENDPOINT_UPDATE === 'true') {
|
if (process.env.ENDPOINT_UPDATE === 'true') {
|
||||||
await CollectionUtil.asyncForEach(schedules, async item => {
|
await CollectionUtil.asyncForEach(schedules, async item => {
|
||||||
|
@ -124,7 +124,7 @@ export class ScheduleServices extends GBService {
|
||||||
|
|
||||||
|
|
||||||
private ScheduleItem(item: GuaribasSchedule, min: GBMinInstance) {
|
private ScheduleItem(item: GuaribasSchedule, min: GBMinInstance) {
|
||||||
GBLog.info(`Scheduling ${item.name} ${min.botId}...`);
|
GBLog.info(`Scheduling ${item.name} on ${min.botId}...`);
|
||||||
try {
|
try {
|
||||||
const options = {
|
const options = {
|
||||||
scheduled: true,
|
scheduled: true,
|
||||||
|
@ -133,21 +133,24 @@ export class ScheduleServices extends GBService {
|
||||||
|
|
||||||
const task = min["scheduleMap"][item.name];
|
const task = min["scheduleMap"][item.name];
|
||||||
if (task) {
|
if (task) {
|
||||||
task.destroy();
|
task.stop();
|
||||||
delete min["scheduleMap"][name];
|
min["scheduleMap"][item.name] = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
min["scheduleMap"][item.name] = cron.schedule(
|
min["scheduleMap"][item.name] = cron.schedule(
|
||||||
item.schedule,
|
item.schedule,
|
||||||
async () => {
|
function () {
|
||||||
let script = item.name;
|
const finalData = async () => {
|
||||||
let min: GBMinInstance = GBServer.globals.minInstances.filter(
|
let script = item.name;
|
||||||
p => p.instance.instanceId === item.instanceId
|
let min: GBMinInstance = GBServer.globals.minInstances.filter(
|
||||||
)[0];
|
p => p.instance.instanceId === item.instanceId
|
||||||
await GBVMService.callVM(script, min, null, null);
|
)[0];
|
||||||
},
|
await GBVMService.callVM(script, min, null, null);
|
||||||
options
|
};
|
||||||
|
(async () => {
|
||||||
|
await finalData();
|
||||||
|
})();
|
||||||
|
}, options
|
||||||
);
|
);
|
||||||
GBLog.info(`Running .gbdialog word ${item.name} on:${item.schedule}...`);
|
GBLog.info(`Running .gbdialog word ${item.name} on:${item.schedule}...`);
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
|
|
|
@ -216,6 +216,10 @@ export class GBConversationalService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public userMobile(step) {
|
public userMobile(step) {
|
||||||
|
if (!step)
|
||||||
|
{
|
||||||
|
return 'N/A';
|
||||||
|
}
|
||||||
if (isNaN(step.context.activity['mobile'])) {
|
if (isNaN(step.context.activity['mobile'])) {
|
||||||
if (step.context.activity.from && !isNaN(step.context.activity.from.id)) {
|
if (step.context.activity.from && !isNaN(step.context.activity.from.id)) {
|
||||||
return step.context.activity.from.id;
|
return step.context.activity.from.id;
|
||||||
|
|
|
@ -79,6 +79,7 @@ import { GBDeployer } from './GBDeployer';
|
||||||
import urlJoin = require('url-join');
|
import urlJoin = require('url-join');
|
||||||
import fs = require('fs');
|
import fs = require('fs');
|
||||||
import { GoogleChatDirectLine } from '../../google-chat.gblib/services/GoogleChatDirectLine';
|
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.
|
* 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}`);
|
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);
|
await this.deployer.deployPackage(min, packagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const service = new ScheduleServices();
|
||||||
|
await service.loadSchedules(min);
|
||||||
|
|
||||||
// Calls the loadBot context.activity for all packages.
|
// Calls the loadBot context.activity for all packages.
|
||||||
|
|
||||||
await this.invokeLoadBot(GBServer.globals.appPackages, GBServer.globals.sysPackages, min);
|
await this.invokeLoadBot(GBServer.globals.appPackages, GBServer.globals.sysPackages, min);
|
||||||
|
|
Loading…
Add table
Reference in a new issue