From ab2851fafe714e65bfacd9818dfde8a08ca528aa Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Mon, 22 Nov 2021 19:48:53 -0300 Subject: [PATCH] new(core.gblib): Teams support for SeeingAI. --- .../basic.gblib/services/SystemKeywords.ts | 29 +++++++++++++------ packages/core.gbapp/services/GBDeployer.ts | 4 +++ packages/core.gbapp/services/GBMinService.ts | 24 +++++++++++++++ 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/packages/basic.gblib/services/SystemKeywords.ts b/packages/basic.gblib/services/SystemKeywords.ts index c8895eaa..59f71c0e 100644 --- a/packages/basic.gblib/services/SystemKeywords.ts +++ b/packages/basic.gblib/services/SystemKeywords.ts @@ -263,7 +263,12 @@ export class SystemKeywords { return documents[0]; } - + /** + * Saves the content of variable into the file in .gbdata default folder. + * + * @exaple SAVE variable as "my.txt" + * + */ public async saveFile(file: string, data: any): Promise { GBLog.info(`BASIC: Saving '${file}' (SAVE file).`); let [baseUrl, client] = await GBDeployer.internalGetDriveClient(this.min); @@ -948,21 +953,27 @@ export class SystemKeywords { * */ public async getByHttp(url: string, headers: any, username: string, ps: string, qs: any) { - const options = { - auth: { - user: username, - pass: ps - }, + let options = { + encoding: "binary", url: url, - headers: headers, - qs: qs, + headers: headers + }; + if (username) { + options['auth'] = { + user: username, + pass: ps + } + } + if (qs) { + options['qs'] = qs; + } const isAO = (val) => { return val instanceof Array || val instanceof Object ? true : false; } let result = await request.get(options); - + if (isAO(result)) { GBLog.info(`[GET]: ${url} : ${result}`); diff --git a/packages/core.gbapp/services/GBDeployer.ts b/packages/core.gbapp/services/GBDeployer.ts index 72345bdf..24895667 100644 --- a/packages/core.gbapp/services/GBDeployer.ts +++ b/packages/core.gbapp/services/GBDeployer.ts @@ -842,6 +842,10 @@ export class GBDeployer implements IGBDeployer { GBServer.globals.server.use(`/kb/${gbaiName}/${packageName}/videos`, express.static(urlJoin('work', gbaiName, filename, 'videos'))); + GBServer.globals.server.use(`/${botId}/cache`, + express.static(urlJoin('work', gbaiName, 'cache'))); + + GBLog.info(`KB (.gbkb) assets accessible at: /kb/${botId}.gbai/${packageName}.`); } diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index a857ef10..61a8fddc 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -37,11 +37,13 @@ 'use strict'; const { DialogSet, TextPrompt } = require('botbuilder-dialogs'); const express = require('express'); +const Fs = require('fs'); const request = require('request-promise-native'); const removeRoute = require('express-remove-route'); const AuthenticationContext = require('adal-node').AuthenticationContext; const wash = require('washyourmouthoutwithsoap'); const { FacebookAdapter } = require('botbuilder-adapter-facebook'); +const path = require('path'); import { AutoSaveStateMiddleware, BotFrameworkAdapter, @@ -80,6 +82,7 @@ import urlJoin = require('url-join'); import fs = require('fs'); import { GoogleChatDirectLine } from '../../google-chat.gblib/services/GoogleChatDirectLine'; import { ScheduleServices } from '../../basic.gblib/services/ScheduleServices'; +import { SystemKeywords } from '../../basic.gblib/services/SystemKeywords'; /** * Minimal service layer for a bot and encapsulation of BOT Framework calls. @@ -872,6 +875,27 @@ export class GBMinService { // Required for MSTEAMS handling of persisted conversations. if (step.context.activity.channelId === 'msteams') { + + if (step.context.activity.attachments && step.context.activity.attachments.length > 1) { + + const file = context.activity.attachments[0]; + const credentials = new MicrosoftAppCredentials(min.instance.marketplaceId, min.instance.marketplacePassword); + const botToken = await credentials.getToken(); + const headers = { Authorization: `Bearer ${botToken}` }; + const t = new SystemKeywords(null, null, null); + const data = await t.getByHttp(file.contentUrl, headers, null, null, null); + const folder = `work/${min.instance.botId}.gbai/cache`; + const filename =`${GBAdminService.generateUuid()}.png`; + + if (!Fs.existsSync(folder)) + { + Fs.mkdirSync(folder); + } + + Fs.writeFileSync(path.join(folder, filename), data); + step.context.activity.text = urlJoin(GBServer.globals.publicAddress, `${min.instance.botId}`, 'cache', filename); + } + const conversationReference = JSON.stringify( TurnContext.getConversationReference(context.activity) );