new(basic.gblib): SEND FILE pdf as temporary images.

This commit is contained in:
me@rodrigorodriguez.com 2024-10-04 00:55:10 -03:00
parent 975d4961a4
commit 25245a010e
5 changed files with 111 additions and 60 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1114,8 +1114,7 @@ export class GBMinService {
step.context.activity['pid'] = pid; step.context.activity['pid'] = pid;
const notes = min.core.getParam(min.instance, 'Notes', null); const notes = min.core.getParam(min.instance, 'Notes', null);
if (await this.handleUploads(min, step, user, params, notes != null)) if (await this.handleUploads(min, step, user, params, notes != null)) {
{
return; return;
} }
@ -1363,7 +1362,6 @@ 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.
let ret = false;
if ( if (
step.context.activity.attachments && step.context.activity.attachments &&
step.context.activity.attachments[0] && step.context.activity.attachments[0] &&
@ -1412,7 +1410,6 @@ export class GBMinService {
const replyPromises = successfulSaves.map(replyForReceivedAttachments.bind(step.context)); const replyPromises = successfulSaves.map(replyForReceivedAttachments.bind(step.context));
await Promise.all(replyPromises); await Promise.all(replyPromises);
if (successfulSaves.length > 0) { if (successfulSaves.length > 0) {
ret = true;
class GBFile { class GBFile {
data: Buffer; data: Buffer;
filename: string; filename: string;
@ -1436,13 +1433,11 @@ export class GBMinService {
throw new Error('It is only possible to upload one file per message, right now.'); throw new Error('It is only possible to upload one file per message, right now.');
} }
min.cbMap[user.userId].promise = results[0]; min.cbMap[user.userId].promise = results[0];
return;
} else {
return;
} }
} }
return successfulSaves.length > 0;
} }
return ret; return false;
} }
/** /**

View file

@ -693,7 +693,7 @@ export class WhatsappDirectLine extends GBService {
break; break;
case 'image/png': case 'image/png':
await this.sendFileToDevice(to, attachment.contentUrl, attachment.name, attachment.name, 0, 0); await this.sendFileToDevice(to, attachment.contentUrl, attachment.name, attachment.name, 0, false);
return; return;
@ -710,7 +710,7 @@ export class WhatsappDirectLine extends GBService {
return `${attachment.content.title} - ${attachment.content.text}`; return `${attachment.content.title} - ${attachment.content.text}`;
} }
public async sendFileToDevice(to, url, filename, caption, chatId, viewOnce) { public async sendFileToDevice(to, url, filename, caption, chatId, isViewOnce = false) {
let options; let options;
switch (this.provider) { switch (this.provider) {
case 'meta': case 'meta':
@ -724,7 +724,7 @@ export class WhatsappDirectLine extends GBService {
whatsappServiceNumber = GBServer.globals.minBoot.instance.whatsappServiceNumber; whatsappServiceNumber = GBServer.globals.minBoot.instance.whatsappServiceNumber;
whatsappServiceKey = GBServer.globals.minBoot.instance.whatsappServiceKey; whatsappServiceKey = GBServer.globals.minBoot.instance.whatsappServiceKey;
} }
if (viewOnce) { if (isViewOnce) {
await this.sendImageViewOnce(to, url, caption); await this.sendImageViewOnce(to, url, caption);
} }
else { else {
@ -744,7 +744,7 @@ export class WhatsappDirectLine extends GBService {
} }
} }
await this.customClient.sendMessage(to, attachment, { caption: caption , viewOnce}); await this.customClient.sendMessage(to, attachment, { caption: caption, isViewOnce });
break; break;
} }
@ -923,7 +923,7 @@ export class WhatsappDirectLine extends GBService {
} }
public async sendToDevice(to: any, msg: string, conversationId, viewOnce= false) { public async sendToDevice(to: any, msg: string, conversationId, isViewOnce = false) {
try { try {
const cmd = '/audio '; const cmd = '/audio ';
let url; let url;
@ -984,7 +984,7 @@ export class WhatsappDirectLine extends GBService {
} }
} }
if ((await this.customClient.getState()) === WAState.CONNECTED) { if ((await this.customClient.getState()) === WAState.CONNECTED) {
await this.customClient.sendMessage(to, msg, { isViewOnce: isViewOnce }); await this.customClient.sendMessage(to, msg, { isViewOnce });
} else { } else {
GBLogEx.info(this.min, `WhatsApp OFFLINE ${to}: ${msg}`); GBLogEx.info(this.min, `WhatsApp OFFLINE ${to}: ${msg}`);
} }

View file

@ -1,7 +1,11 @@
TALK "Please, take a photo of the QR Code and send to me." TALK "Please, take a photo of the QR Code and send to me."
HEAR doc as QRCODE HEAR doc as QRCODE
text = null
IF doc THEN
TALK "Reading document " + doc + "..." TALK "Reading document " + doc + "..."
text = GET doc text = GET doc
END IF
IF text THEN IF text THEN
@ -9,7 +13,7 @@ IF text THEN
SET CONTEXT text SET CONTEXT text
SET ANSWER MODE "document" SET ANSWER MODE "document"
TALK "Document ${doc} loaded. You can ask me anything about it." TALK "Document ${doc} loaded. You can ask me anything about it."
TALK "I will also send it to you..." TALK "Please, wait while I convert pages to images..."
SEND FILE doc SEND FILE doc
ELSE ELSE