Skip to content

Commit

Permalink
fix(all): Minor changes in PROD.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jul 9, 2023
1 parent a969abb commit a60581b
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 62 deletions.
Empty file modified gbot.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion packages/basic.gblib/services/DialogKeywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
125 changes: 66 additions & 59 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -1081,6 +1066,7 @@ export class GBMinService {
};

try {

await adapter['processActivity'](req, res, handler);
} catch (error) {
if (error.code === 401) {
Expand Down Expand Up @@ -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
};
}


/**
*
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.');
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core.gbapp/services/GBSSR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/kb.gbapp/dialogs/AskDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a60581b

Please sign in to comment.