new(basic.gblib): New AUTO SAVE keyword.
This commit is contained in:
parent
85f6449ca4
commit
1d3a44c7c4
3 changed files with 92 additions and 13 deletions
|
@ -335,6 +335,14 @@ export class KeywordsExpressions {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
keywords[i++] = [
|
||||||
|
/^\s*(.*)\=\s*(AUTO SAVE)(\s*)(.*)/gim,
|
||||||
|
($0, $1, $2, $3, $4) => {
|
||||||
|
const params = this.getParams($4, ['handle']);
|
||||||
|
return `await sys.autoSave ({pid: pid, ${params}})`;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*hear (\w+\$*) as (\w+( \w+)*.xlsx)/gim,
|
/^\s*hear (\w+\$*) as (\w+( \w+)*.xlsx)/gim,
|
||||||
|
|
|
@ -60,6 +60,7 @@ import { GBConversationalService } from '../../core.gbapp/services/GBConversatio
|
||||||
import { WebAutomationServices } from './WebAutomationServices.js';
|
import { WebAutomationServices } from './WebAutomationServices.js';
|
||||||
import { KeywordsExpressions } from './KeywordsExpressions.js';
|
import { KeywordsExpressions } from './KeywordsExpressions.js';
|
||||||
import { ChatServices } from '../../gpt.gblib/services/ChatServices.js';
|
import { ChatServices } from '../../gpt.gblib/services/ChatServices.js';
|
||||||
|
import mime from 'mime-types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview General Bots server core.
|
* @fileoverview General Bots server core.
|
||||||
|
@ -1874,7 +1875,6 @@ export class SystemKeywords {
|
||||||
GBLog.info(`Twitter Automation: ${text}.`);
|
GBLog.info(`Twitter Automation: ${text}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HEAR description
|
* HEAR description
|
||||||
* text = REWRITE description
|
* text = REWRITE description
|
||||||
|
@ -1950,6 +1950,46 @@ export class SystemKeywords {
|
||||||
|
|
||||||
GBLog.info(`GBPay: ${data.MerchantOrderId} OK: ${url}.`);
|
GBLog.info(`GBPay: ${data.MerchantOrderId} OK: ${url}.`);
|
||||||
|
|
||||||
return { localName: localName, url: url, data: buf, text: data.Payment.QrCodeString };
|
return {
|
||||||
|
name: Path.basename(localName),
|
||||||
|
localName: localName,
|
||||||
|
url: url,
|
||||||
|
data: buf,
|
||||||
|
text: data.Payment.QrCodeString
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HEAR logo AS FILE
|
||||||
|
* file = AUTO SAVE logo
|
||||||
|
* TALK "Your " + file.name + " file is saved."
|
||||||
|
*/
|
||||||
|
public async autoSave({ pid, handle }) {
|
||||||
|
const { min } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
this.internalAutoSave({ min, handle });
|
||||||
|
}
|
||||||
|
|
||||||
|
public async internalAutoSave({ min, handle }) {
|
||||||
|
const file = GBServer.globals.files[handle];
|
||||||
|
GBLog.info(`BASIC: Auto saving '${file.filename}' (SAVE file).`);
|
||||||
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
|
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
||||||
|
try {
|
||||||
|
const contentType = mime.lookup(file.url ? file.url : file.name);
|
||||||
|
const kind = await getContentTypeFolder(contentType);
|
||||||
|
await client.api(`${baseUrl}/drive/root:/${path}/${kind}/${file.name}:/content`).put(file.data);
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code === 'itemNotFound') {
|
||||||
|
GBLog.info(`BASIC: BASIC source file not found: ${file}.`);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getContentTypeFolder(contentType: any) {
|
||||||
|
// TODO: DS .jpog ->'image/jpg' -> IMages
|
||||||
|
// #359
|
||||||
|
if (contentType === 'image/jpg') {
|
||||||
|
return 'Images';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,8 +99,8 @@ import { createKoaHttpServer } from '../../basic.gblib/index.js';
|
||||||
import { DebuggerService } from '../../basic.gblib/services/DebuggerService.js';
|
import { DebuggerService } from '../../basic.gblib/services/DebuggerService.js';
|
||||||
import { ImageProcessingServices } from '../../basic.gblib/services/ImageProcessingServices.js';
|
import { ImageProcessingServices } from '../../basic.gblib/services/ImageProcessingServices.js';
|
||||||
import { ScheduleServices } from '../../basic.gblib/services/ScheduleServices.js';
|
import { ScheduleServices } from '../../basic.gblib/services/ScheduleServices.js';
|
||||||
import mime from 'mime';
|
import mime from 'mime-types';
|
||||||
import { ChatServices } from '../../gpt.gblib/services/ChatServices.js';
|
|
||||||
/**
|
/**
|
||||||
* Minimal service layer for a bot and encapsulation of BOT Framework calls.
|
* Minimal service layer for a bot and encapsulation of BOT Framework calls.
|
||||||
*/
|
*/
|
||||||
|
@ -1282,17 +1282,40 @@ export class GBMinService {
|
||||||
|
|
||||||
// Prepare Promises to download each attachment and then execute each Promise.
|
// Prepare Promises to download each attachment and then execute each Promise.
|
||||||
if (step.context.activity.attachments
|
if (step.context.activity.attachments
|
||||||
|
&& step.context.activity.attachments[0]
|
||||||
&& step.context.activity.attachments[0].contentType != 'text/html') {
|
&& step.context.activity.attachments[0].contentType != 'text/html') {
|
||||||
|
|
||||||
const promises = step.context.activity.attachments.map(
|
const promises = step.context.activity.attachments.map(
|
||||||
GBMinService.downloadAttachmentAndWrite.bind({ min, user, params })
|
GBMinService.downloadAttachmentAndWrite.bind({ min, user, params })
|
||||||
);
|
);
|
||||||
const successfulSaves = await Promise.all(promises);
|
const successfulSaves = await Promise.all(promises);
|
||||||
async function replyForReceivedAttachments(localAttachmentData) {
|
async function replyForReceivedAttachments(attachmentData) {
|
||||||
if (localAttachmentData) {
|
if (attachmentData) {
|
||||||
|
|
||||||
// Because the TurnContext was bound to this function,the bot can call
|
// Because the TurnContext was bound to this function,the bot can call
|
||||||
// `TurnContext.sendActivity` via `this.sendActivity`;
|
// `TurnContext.sendActivity` via `this.sendActivity`;
|
||||||
await this.sendActivity(`Upload OK.`);
|
await this.sendActivity(`Upload OK.`);
|
||||||
|
|
||||||
|
// In case of not having HEAR activated before, it is
|
||||||
|
// a upload with no Dialog, so run Auto Save to .gbdrive.
|
||||||
|
|
||||||
|
if (!min.cbMap[userId])
|
||||||
|
{
|
||||||
|
const t = new SystemKeywords();
|
||||||
|
GBLog.info(`BASIC (${min.botId}): Upload done for ${attachmentData.fileName}.`);
|
||||||
|
const handle = WebAutomationServices.cyrb53(min.botId + attachmentData.fileName);
|
||||||
|
let data = Fs.readFileSync(attachmentData.localPath);
|
||||||
|
|
||||||
|
const gbfile = {
|
||||||
|
filename: attachmentData.localPath,
|
||||||
|
data: data,
|
||||||
|
name: Path.basename(attachmentData.fileName)
|
||||||
|
};
|
||||||
|
|
||||||
|
GBServer.globals.files[handle] = gbfile;
|
||||||
|
await t.internalAutoSave({min: min, handle:handle });
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
await this.sendActivity('Error uploading file. Please,start again.');
|
await this.sendActivity('Error uploading file. Please,start again.');
|
||||||
}
|
}
|
||||||
|
@ -1320,6 +1343,14 @@ export class GBMinService {
|
||||||
}
|
}
|
||||||
min.cbMap[userId].promise = results[0];
|
min.cbMap[userId].promise = results[0];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Uploads file to .gbdrive associated folder.
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue