fix(all): Fixes in bot creation.

This commit is contained in:
Rodrigo Rodriguez 2023-12-20 18:07:09 -03:00
parent 811a6e320b
commit c42843c190
5 changed files with 40 additions and 29 deletions

View file

@ -39,14 +39,14 @@
import crypto from 'crypto'; import crypto from 'crypto';
import urlJoin from 'url-join'; import urlJoin from 'url-join';
import { WaterfallDialog } from 'botbuilder-dialogs'; import { WaterfallDialog } from 'botbuilder-dialogs';
import { GBLog, GBMinInstance, IGBDialog } from 'botlib'; import { GBMinInstance, IGBDialog } from 'botlib';
import { GBDeployer } from '../../core.gbapp/services/GBDeployer.js'; import { GBDeployer } from '../../core.gbapp/services/GBDeployer.js';
import { GBImporter } from '../../core.gbapp/services/GBImporterService.js'; import { GBImporter } from '../../core.gbapp/services/GBImporterService.js';
import { Messages } from '../strings.js'; import { Messages } from '../strings.js';
import { GBAdminService } from '../services/GBAdminService.js'; import { GBAdminService } from '../services/GBAdminService.js';
import { CollectionUtil } from 'pragmatismo-io-framework'; import { CollectionUtil } from 'pragmatismo-io-framework';
import { SecService } from '../../security.gbapp/services/SecService.js'; import { SecService } from '../../security.gbapp/services/SecService.js';
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js'; import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js';
/** /**
* Dialogs for administration tasks. * Dialogs for administration tasks.
@ -444,7 +444,8 @@ export class AdminDialog extends IGBDialog {
const scope = tokenName ? '' : 'https://graph.microsoft.com/.default'; const scope = tokenName ? '' : 'https://graph.microsoft.com/.default';
const host = tokenName ? step.activeDialog.state.host : 'https://login.microsoftonline.com' const host = tokenName ? step.activeDialog.state.host : 'https://login.microsoftonline.com'
const tenant = tokenName ? step.activeDialog.state.tenant : min.instance.authenticatorTenant; const tenant = tokenName ? step.activeDialog.state.tenant : min.instance.authenticatorTenant;
const clientId = tokenName ? step.activeDialog.state.clientId : min.instance.marketplaceId; const clientId = tokenName ? step.activeDialog.state.clientId : (min.instance.marketplaceId ?
min.instance.marketplaceId : GBConfigService.get('MARKETPLACE_ID'));
const oauth2 = tokenName ? 'oauth' : 'oauth2'; const oauth2 = tokenName ? 'oauth' : 'oauth2';
const url = `${host}/${tenant}/${oauth2}/authorize?client_id=${clientId}&response_type=code&redirect_uri=${redirectUri}&scope=${scope}&state=${state}&response_mode=query`; const url = `${host}/${tenant}/${oauth2}/authorize?client_id=${clientId}&response_type=code&redirect_uri=${redirectUri}&scope=${scope}&state=${state}&response_mode=query`;

View file

@ -100,10 +100,26 @@ export class GBAdminService implements IGBAdminService {
} }
public static getRndPassword(): string { public static getRndPassword(): string {
let password = caseSensitive_Numbs_SpecialCharacters_PW(15); let password = caseSensitive_Numbs_SpecialCharacters_PW(15);
password = password.replace(/[\@\[\=\:\;\?\"\'\#]/gi, '*'); password = password.replace(/[\@\[\=\:\;\?\"\'\#]/gi, '*');
return password; const removeRepeatedChars = (s, r) => {
let res = '', last = null, counter = 0;
s.split('').forEach(char => {
if (char == last)
counter++;
else {
counter = 0;
last = char;
}
if (counter < r)
res += char;
});
return res;
}
return removeRepeatedChars(password, 1);
} }
public static getRndReadableIdentifier(): string { public static getRndReadableIdentifier(): string {

View file

@ -421,11 +421,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
instance.cloudLocation instance.cloudLocation
); );
await this.createStorage(name, storageServer, storageName, instance.cloudLocation); await this.createStorage(name, storageServer, storageName, instance.cloudLocation);
instance.storageUsername = administratorLogin;
instance.storagePassword = administratorPassword;
instance.storageName = storageName;
instance.storageDialect = 'mssql';
instance.storageServer = `${storageServer}.database.windows.net`;
GBLog.info(`Deploying Search...`); GBLog.info(`Deploying Search...`);
const searchName = `${name}-search`.toLowerCase(); const searchName = `${name}-search`.toLowerCase();

View file

@ -97,7 +97,7 @@ export class GBDeployer implements IGBDeployer {
* use to database like the Indexer (Azure Search). * use to database like the Indexer (Azure Search).
*/ */
public static getConnectionStringFromInstance(instance: IGBInstance) { public static getConnectionStringFromInstance(instance: IGBInstance) {
return `Server=tcp:${instance.storageServer},1433;Database=${instance.storageName};User ID=${instance.storageUsername};Password=${instance.storagePassword};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;`; return `Server=tcp:${GBConfigService.get("STORAGE_SERVER")},1433;Database=${GBConfigService.get("STORAGE_NAME")};User ID=${GBConfigService.get("STORAGE_USERNAME")};Password=${GBConfigService.get("STORAGE_PASSWORD")};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;`;
} }
/** /**
@ -819,13 +819,7 @@ export class GBDeployer implements IGBDeployer {
} }
await search.createIndex(searchSchema, dsName); await search.createIndex(searchSchema, dsName);
// release();
GBLogEx.info(instance.instanceId, `Released rebuildIndex mutex.`); GBLogEx.info(instance.instanceId, `Released rebuildIndex mutex.`);
//} catch {
// if (release) {
// release();
// }
//}
} }
/** /**

View file

@ -516,7 +516,7 @@ export class GBMinService {
const options = { const options = {
method: 'POST', method: 'POST',
headers: { headers: {
Accept: '1.0', Accept: '1.0',
Authorization: `Basic ${base64}`, Authorization: `Basic ${base64}`,
'Content-Type': 'application/x-www-form-urlencoded' 'Content-Type': 'application/x-www-form-urlencoded'
@ -537,15 +537,15 @@ export class GBMinService {
// Saves token to the database. // Saves token to the database.
await this.adminService.setValue(instance.instanceId, await this.adminService.setValue(instance.instanceId,
`${tokenName}accessToken`, token['accessToken']?token['accessToken']:token['access_token']); `${tokenName}accessToken`, token['accessToken'] ? token['accessToken'] : token['access_token']);
await this.adminService.setValue(instance.instanceId, await this.adminService.setValue(instance.instanceId,
`${tokenName}refreshToken`, token['refreshToken']?token['refreshToken']:token['refresh_token']); `${tokenName}refreshToken`, token['refreshToken'] ? token['refreshToken'] : token['refresh_token']);
await this.adminService.setValue(instance.instanceId, await this.adminService.setValue(instance.instanceId,
`${tokenName}expiresOn`, token['expiresOn'] ? `${tokenName}expiresOn`, token['expiresOn'] ?
token['expiresOn'].toString(): token['expiresOn'].toString() :
new Date (Date.now() + token['expires_in']).toString()); new Date(Date.now() + token['expires_in']).toString());
await this.adminService.setValue(instance.instanceId, `${tokenName}AntiCSRFAttackState`, null); await this.adminService.setValue(instance.instanceId, `${tokenName}AntiCSRFAttackState`, null);
@ -721,8 +721,10 @@ export class GBMinService {
// MSFT stuff. // MSFT stuff.
const adapter = new BotFrameworkAdapter({ const adapter = new BotFrameworkAdapter({
appId: instance.marketplaceId, appId: instance.marketplaceId ? instance.marketplaceId : GBConfigService.get('MARKETPLACE_ID'),
appPassword: instance.marketplacePassword appPassword: instance.marketplacePassword
? instance.marketplacePassword
: GBConfigService.get('MARKETPLACE_SECRET')
}); });
const storage = new MemoryStorage(); const storage = new MemoryStorage();
const conversationState = new ConversationState(storage); const conversationState = new ConversationState(storage);
@ -759,6 +761,9 @@ export class GBMinService {
if (!GBServer.globals.minBoot.botId) { if (!GBServer.globals.minBoot.botId) {
GBServer.globals.minBoot = min; GBServer.globals.minBoot = min;
GBServer.globals.minBoot.instance.marketplaceId = GBConfigService.get('MARKETPLACE_ID');
GBServer.globals.minBoot.instance.marketplacePassword = GBConfigService.get('MARKETPLACE_SECRET');
} }
if (min.instance.facebookWorkplaceVerifyToken) { if (min.instance.facebookWorkplaceVerifyToken) {
@ -1212,7 +1217,7 @@ export class GBMinService {
} }
private async handleUploads(min, step, user, params, autoSave) { private async handleUploads(min, step, user, params, autoSave) {
// Prepare Promises to download each attachment and then execute each Promise. // Prepare Promises to download each attachment and then execute each Promise.
if ( if (
@ -1243,7 +1248,7 @@ export class GBMinService {
GBServer.globals.files[handle] = gbfile; GBServer.globals.files[handle] = gbfile;
if (!min.cbMap[user.userId] && autoSave) { if (!min.cbMap[user.userId] && autoSave) {
const result = await t['internalAutoSave']({ min: min, handle: handle }); const result = await t['internalAutoSave']({ min: min, handle: handle });
await min.conversationalService.sendText( await min.conversationalService.sendText(
min, min,
@ -1253,8 +1258,7 @@ export class GBMinService {
return; return;
} }
else else {
{
return gbfile; return gbfile;
} }