From a60581bd320bdfa7abac5a7d8c27bc84cfa87cf5 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Sun, 9 Jul 2023 06:51:10 -0300 Subject: [PATCH] fix(all): Minor changes in PROD. --- gbot.sh | 0 .../basic.gblib/services/DialogKeywords.ts | 2 +- packages/core.gbapp/services/GBMinService.ts | 125 +++++++++--------- packages/core.gbapp/services/GBSSR.ts | 2 +- packages/kb.gbapp/dialogs/AskDialog.ts | 2 +- 5 files changed, 69 insertions(+), 62 deletions(-) mode change 100644 => 100755 gbot.sh diff --git a/gbot.sh b/gbot.sh old mode 100644 new mode 100755 diff --git a/packages/basic.gblib/services/DialogKeywords.ts b/packages/basic.gblib/services/DialogKeywords.ts index a5bc41af..082ff404 100644 --- a/packages/basic.gblib/services/DialogKeywords.ts +++ b/packages/basic.gblib/services/DialogKeywords.ts @@ -717,7 +717,7 @@ export class DialogKeywords { * */ public async hear({ pid, kind, args }) { - let { min, user, params } = await DialogKeywords.getProcessInfo(pid); + let { min, user, params } = await DialogKeywords.getProcessInfo(pid); // Handles first arg as an array of args. diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 2d98ea4d..9f0321b8 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -201,10 +201,10 @@ export class GBMinService { pingSendTimeout: null, keepAliveTimeout: null, listeners: { - unsubscribed(subscriptions: number): void {}, - subscribed(subscriptions: number): void {}, - disconnected(remoteId: string, connections: number): void {}, - connected(remoteId: string, connections: number): void {}, + unsubscribed(subscriptions: number): void { }, + subscribed(subscriptions: number): void { }, + disconnected(remoteId: string, connections: number): void { }, + connected(remoteId: string, connections: number): void { }, messageIn(...params): void { GBLogEx.info(0, '[IN] ' + params); }, @@ -239,7 +239,7 @@ export class GBMinService { GBLogEx.info(0, 'API RPC HTTP Server started.'); // Loads schedules. - + GBLog.info(`Preparing SET SCHEDULE dialog calls...`); const service = new ScheduleServices(); await service.scheduleAll(); @@ -285,7 +285,7 @@ export class GBMinService { /** * Unmounts the bot web site (default.gbui) secure domain, if any. */ - public async unloadDomain(instance: IGBInstance) {} + public async unloadDomain(instance: IGBInstance) { } /** * Mount the instance by creating an BOT Framework bot object, @@ -562,9 +562,8 @@ export class GBMinService { min.instance.authenticatorTenant, '/oauth2/authorize' ); - authorizationUrl = `${authorizationUrl}?response_type=code&client_id=${ - min.instance.marketplaceId - }&redirect_uri=${urlJoin(min.instance.botEndpoint, min.instance.botId, 'token')}`; + authorizationUrl = `${authorizationUrl}?response_type=code&client_id=${min.instance.marketplaceId + }&redirect_uri=${urlJoin(min.instance.botEndpoint, min.instance.botId, 'token')}`; GBLog.info(`HandleOAuthRequests: ${authorizationUrl}.`); res.redirect(authorizationUrl); }); @@ -1040,20 +1039,7 @@ export class GBMinService { } else { GBLog.info(`Person added to conversation: ${member.name}`); - if (GBMinService.userMobile(step)) { - if ( - startDialog && - !min['conversationWelcomed'][step.context.activity.conversation.id] && - !step.context.activity['group'] - ) { - await sec.setParam(userId, 'welcomed', 'true'); - min['conversationWelcomed'][step.context.activity.conversation.id] = true; - GBLog.info( - `Auto start (whatsapp) dialog is now being called: ${startDialog} for ${min.instance.instanceId}...` - ); - await GBVMService.callVM(startDialog.toLowerCase(), min, step, user, this.deployer, false); - } - } + return; } } else if (context.activity.type === 'message') { // Processes messages activities. @@ -1065,9 +1051,8 @@ export class GBMinService { await this.processEventActivity(min, user, context, step); } } catch (error) { - const msg = `ERROR: ${error.message} ${error.stack} ${error.error ? error.error.body : ''} ${ - error.error ? (error.error.stack ? error.error.stack : '') : '' - }`; + const msg = `ERROR: ${error.message} ${error.stack} ${error.error ? error.error.body : ''} ${error.error ? (error.error.stack ? error.error.stack : '') : '' + }`; GBLog.error(msg); await min.conversationalService.sendText( @@ -1081,6 +1066,7 @@ export class GBMinService { }; try { + await adapter['processActivity'](req, res, handler); } catch (error) { if (error.code === 401) { @@ -1133,40 +1119,40 @@ export class GBMinService { /** * Private handler which receives the Attachment and persists to disk. * during a HEAR attachment AS FILE upload. - */ - // ... - + */ + // ... + private static async downloadAttachmentAndWrite(attachment) { - const url = attachment.contentUrl; - const localFolder = Path.join('work'); - const path = DialogKeywords.getGBAIPath(this['min'].botId); - const localFileName = Path.join(localFolder, path, 'uploads', - attachment.name - ); - - let buffer; - if (url.startsWith('data:')) { - const base64Data = url.split(';base64,')[1]; - buffer = Buffer.from(base64Data, 'base64'); - } else { - const options = { - method: 'GET', - encoding: 'binary' - }; - const res = await fetch(url, options); - buffer = arrayBufferToBuffer(await res.arrayBuffer()); - } - - Fs.writeFileSync(localFileName, buffer); - - return { - fileName: - attachment.name - , - localPath: localFileName + const url = attachment.contentUrl; + const localFolder = Path.join('work'); + const path = DialogKeywords.getGBAIPath(this['min'].botId); + const localFileName = Path.join(localFolder, path, 'uploads', + attachment.name + ); + + let buffer; + if (url.startsWith('data:')) { + const base64Data = url.split(';base64,')[1]; + buffer = Buffer.from(base64Data, 'base64'); + } else { + const options = { + method: 'GET', + encoding: 'binary' }; + const res = await fetch(url, options); + buffer = arrayBufferToBuffer(await res.arrayBuffer()); } - + + Fs.writeFileSync(localFileName, buffer); + + return { + fileName: + attachment.name + , + localPath: localFileName + }; + } + /** * @@ -1233,6 +1219,27 @@ export class GBMinService { } } + if (GBMinService.userMobile(step)) { + const startDialog = user.hearOnDialog + ? user.hearOnDialog + : min.core.getParam(min.instance, 'Start Dialog', null); + + if ( + startDialog && + !min['conversationWelcomed'][step.context.activity.conversation.id] && + !step.context.activity['group'] + ) { + await sec.setParam(userId, 'welcomed', 'true'); + min['conversationWelcomed'][step.context.activity.conversation.id] = true; + GBLog.info( + `Auto start (whatsapp) dialog is now being called: ${startDialog} for ${min.instance.instanceId}...` + ); + await GBVMService.callVM(startDialog.toLowerCase(), min, step, user, this.deployer, false); + + return; + } + } + // Prepare Promises to download each attachment and then execute each Promise. if (step.context.activity.attachments) { const promises = step.context.activity.attachments.map( @@ -1264,7 +1271,7 @@ export class GBMinService { accum.push(result); return accum; }, []) as GBFile[]; - + if (min.cbMap[userId] && min.cbMap[userId].promise == '!GBHEAR') { if (results.length > 1) { throw new Error('It is only possible to upload one file per message, right now.'); @@ -1465,7 +1472,7 @@ export class GBMinService { ); } } else { - if (min.cbMap[userId] && min.cbMap[userId].promise == '!GBHEAR') { + if (min.cbMap[userId] && min.cbMap[userId].promise === '!GBHEAR') { min.cbMap[userId].promise = text; } diff --git a/packages/core.gbapp/services/GBSSR.ts b/packages/core.gbapp/services/GBSSR.ts index 4de8051a..1c658b94 100644 --- a/packages/core.gbapp/services/GBSSR.ts +++ b/packages/core.gbapp/services/GBSSR.ts @@ -333,7 +333,7 @@ export class GBSSR { url === '/' || url === '' ? `index.html` : url ); if (GBServer.globals.wwwroot && url === '/'){ - path = GBServer.globals.wwwroot + "\\index.html"; + path = GBServer.globals.wwwroot + "/index.html"; // TODO. } if (Fs.existsSync(path)) { if (min) { diff --git a/packages/kb.gbapp/dialogs/AskDialog.ts b/packages/kb.gbapp/dialogs/AskDialog.ts index 319d51ad..640588f5 100644 --- a/packages/kb.gbapp/dialogs/AskDialog.ts +++ b/packages/kb.gbapp/dialogs/AskDialog.ts @@ -189,7 +189,7 @@ export class AskDialog extends IGBDialog { // When no text is typed, the start dialog is invoked again // when people type just the @botName in MSTEAMS for example. - if (!text) { + if (!text && step.context.activity.channelId === 'msteams') { const startDialog = min.core.getParam(min.instance, 'Start Dialog', null); if (startDialog) { await GBVMService.callVM(startDialog.toLowerCase().trim(), min, step, user, this.deployer, false);