new(basic.gblib): SEND FILE pdf as temporary images.
This commit is contained in:
parent
975d4961a4
commit
25245a010e
5 changed files with 111 additions and 60 deletions
File diff suppressed because one or more lines are too long
52
.wwebjs_cache/2.3000.1017054665.html
Normal file
52
.wwebjs_cache/2.3000.1017054665.html
Normal file
File diff suppressed because one or more lines are too long
|
@ -1114,8 +1114,7 @@ export class GBMinService {
|
|||
step.context.activity['pid'] = pid;
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
@ -1334,11 +1333,11 @@ export class GBMinService {
|
|||
const base64Data = url.split(';base64,')[1];
|
||||
buffer = Buffer.from(base64Data, 'base64');
|
||||
} else {
|
||||
const options = {
|
||||
method: 'GET',
|
||||
encoding: 'binary'
|
||||
};
|
||||
const res = await fetch(url, options);
|
||||
const options = {
|
||||
method: 'GET',
|
||||
encoding: 'binary'
|
||||
};
|
||||
const res = await fetch(url, options);
|
||||
buffer = arrayBufferToBuffer(await res.arrayBuffer());
|
||||
}
|
||||
|
||||
|
@ -1363,14 +1362,13 @@ export class GBMinService {
|
|||
|
||||
private async handleUploads(min, step, user, params, autoSave) {
|
||||
// Prepare Promises to download each attachment and then execute each Promise.
|
||||
let ret = false;
|
||||
if (
|
||||
step.context.activity.attachments &&
|
||||
step.context.activity.attachments[0] &&
|
||||
step.context.activity.attachments[0].contentType != 'text/html'
|
||||
) {
|
||||
const promises = step.context.activity.attachments.map(
|
||||
GBMinService.downloadAttachmentAndWrite.bind({ min, user, params })
|
||||
GBMinService.downloadAttachmentAndWrite.bind({ min, user, params })
|
||||
);
|
||||
const successfulSaves = await Promise.all(promises);
|
||||
async function replyForReceivedAttachments(attachmentData) {
|
||||
|
@ -1412,7 +1410,6 @@ export class GBMinService {
|
|||
const replyPromises = successfulSaves.map(replyForReceivedAttachments.bind(step.context));
|
||||
await Promise.all(replyPromises);
|
||||
if (successfulSaves.length > 0) {
|
||||
ret = true;
|
||||
class GBFile {
|
||||
data: Buffer;
|
||||
filename: string;
|
||||
|
@ -1436,13 +1433,11 @@ export class GBMinService {
|
|||
throw new Error('It is only possible to upload one file per message, right now.');
|
||||
}
|
||||
min.cbMap[user.userId].promise = results[0];
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return successfulSaves.length > 0;
|
||||
}
|
||||
return ret;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -693,7 +693,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
break;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -710,7 +710,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
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;
|
||||
switch (this.provider) {
|
||||
case 'meta':
|
||||
|
@ -724,7 +724,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
whatsappServiceNumber = GBServer.globals.minBoot.instance.whatsappServiceNumber;
|
||||
whatsappServiceKey = GBServer.globals.minBoot.instance.whatsappServiceKey;
|
||||
}
|
||||
if (viewOnce) {
|
||||
if (isViewOnce) {
|
||||
await this.sendImageViewOnce(to, url, caption);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
const cmd = '/audio ';
|
||||
let url;
|
||||
|
@ -984,7 +984,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
}
|
||||
}
|
||||
if ((await this.customClient.getState()) === WAState.CONNECTED) {
|
||||
await this.customClient.sendMessage(to, msg, { isViewOnce: isViewOnce });
|
||||
await this.customClient.sendMessage(to, msg, { isViewOnce });
|
||||
} else {
|
||||
GBLogEx.info(this.min, `WhatsApp OFFLINE ${to}: ${msg}`);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
TALK "Please, take a photo of the QR Code and send to me."
|
||||
HEAR doc as QRCODE
|
||||
TALK "Reading document " + doc + "..."
|
||||
text = GET doc
|
||||
text = null
|
||||
|
||||
IF doc THEN
|
||||
TALK "Reading document " + doc + "..."
|
||||
text = GET doc
|
||||
END IF
|
||||
|
||||
IF text THEN
|
||||
|
||||
|
@ -9,7 +13,7 @@ IF text THEN
|
|||
SET CONTEXT text
|
||||
SET ANSWER MODE "document"
|
||||
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
|
||||
|
||||
ELSE
|
||||
|
|
Loading…
Add table
Reference in a new issue