diff --git a/package.json b/package.json index cea441d2..83aa9926 100644 --- a/package.json +++ b/package.json @@ -180,7 +180,7 @@ "vm2-process": "2.1.1", "walk-promise": "0.2.0", "washyourmouthoutwithsoap": "1.0.2", - "whatsapp-web.js": "1.20.0", + "whatsapp-web.js": "1.22.1", "winston": "3.8.2", "winston-logs-display": "1.0.0", "ws": "8.12.1", diff --git a/packages/basic.gblib/services/DialogKeywords.ts b/packages/basic.gblib/services/DialogKeywords.ts index e9704e46..bd31dd7e 100644 --- a/packages/basic.gblib/services/DialogKeywords.ts +++ b/packages/basic.gblib/services/DialogKeywords.ts @@ -1223,13 +1223,21 @@ export class DialogKeywords { const reply = { type: ActivityTypes.Message, text: caption }; const imageData = await (await fetch(url)).arrayBuffer(); - const base64Image = Buffer.from(imageData).toString('base64'); const contentType = mime.lookup(url); reply['attachments'] = []; + + // Prepare a cache to be referenced by Bot Framework. + + let buf: any = Buffer.from(imageData); + const gbaiName = DialogKeywords.getGBAIPath(min.botId); + const localName = Path.join('work', gbaiName, 'cache', `tmp${GBAdminService.getRndReadableIdentifier()}.docx`); + Fs.writeFileSync(localName, buf, { encoding: null }); + url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName)); + reply['attachments'].push({ name: nameOnly, contentType: contentType, - contentUrl: `data:${contentType};base64,${base64Image}` + contentUrl: url }); if (channel === 'omnichannel') { diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 3420a769..3a882f37 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -1268,7 +1268,7 @@ export class GBMinService { : min.core.getParam(min.instance, 'Start Dialog', null); if ( - startDialog && + startDialog && startDialog!=="" && !min['conversationWelcomed'][step.context.activity.conversation.id] && !step.context.activity['group'] ) { @@ -1348,6 +1348,10 @@ export class GBMinService { } min.cbMap[userId].promise = results[0]; } + else{ + + return; + } } } diff --git a/packages/kb.gbapp/dialogs/AskDialog.ts b/packages/kb.gbapp/dialogs/AskDialog.ts index 8332f128..13407e03 100644 --- a/packages/kb.gbapp/dialogs/AskDialog.ts +++ b/packages/kb.gbapp/dialogs/AskDialog.ts @@ -108,7 +108,9 @@ export class AskDialog extends IGBDialog { text = Messages[locale].ask_first_time; } else if (step.options && step.options.isReturning && !step.context.activity.group) { - text = Messages[locale].anything_else; + const askForMore = min.core.getParam(min.instance, 'Ask For More', null); + + text = askForMore?Messages[locale].anything_else: ''; } else if (step.context.activity.group || (step.options && step.options.emptyPrompt)) { text = ''; diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index b0c39447..a791686c 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -30,6 +30,7 @@ | | \*****************************************************************************/ +import mime from 'mime-types'; import urlJoin from 'url-join'; import SwaggerClient from 'swagger-client'; import Path from 'path'; @@ -49,6 +50,7 @@ import { GBSSR } from '../../core.gbapp/services/GBSSR.js'; import pkg from 'whatsapp-web.js'; import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js'; import { ChatServices } from '../../gpt.gblib/services/ChatServices.js'; +import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js'; const { List, Buttons, Client, MessageMedia } = pkg; /** @@ -315,11 +317,19 @@ export class WhatsappDirectLine extends GBService { if (message.hasMedia) { const base64Image = await message.downloadMedia(); + + let buf: any = Buffer.from(base64Image.data, "base64"); + const gbaiName = DialogKeywords.getGBAIPath(this.min.botId); + const localName = Path.join('work', gbaiName, 'cache', `tmp${GBAdminService.getRndReadableIdentifier()}.docx`); + Fs.writeFileSync(localName, buf, { encoding: null }); + const url = urlJoin(GBServer.globals.publicAddress, this.min.botId, 'cache', Path.basename(localName)); + attachments = []; attachments.push({ - name: 'uploaded.png', + name: `${new Date().toISOString().replace(/\:/g, '')}.${mime.extension(base64Image.mimetype)}`, + noName: true, contentType: base64Image.mimetype, - contentUrl: `data:${base64Image.mimetype};base64,${base64Image.data}` + contentUrl: url }); } diff --git a/src/app.ts b/src/app.ts index c178f699..60f69a31 100644 --- a/src/app.ts +++ b/src/app.ts @@ -102,8 +102,9 @@ export class GBServer { GBServer.globals.indexSemaphore = new Mutex(); server.use(bodyParser.json()); - server.use(bodyParser.urlencoded({ extended: true })); - + server.use(bodyParser.json({limit: '100mb'})); + server.use(bodyParser.urlencoded({limit: '100mb', extended: true})); + // Setups global error handlers. process.on('unhandledRejection', (err, p) => {