new(whatsapp.gblib): New WhatsApp provider: Meta.

This commit is contained in:
Rodrigo Rodriguez 2024-04-30 15:05:31 -03:00
parent db80d556c1
commit 3ec96d7bdd

View file

@ -157,7 +157,7 @@ export class DialogKeywords {
* Returns the OCR of image file.
*
*/
public async getOCR({pid, localFile }) {
public async getOCR({ pid, localFile }) {
const { min, user } = await DialogKeywords.getProcessInfo(pid);
GBLogEx.info(min, `BASIC: OCR processing on ${localFile}.`);
@ -529,6 +529,7 @@ export class DialogKeywords {
*/
public async sendEmail({ pid, to, subject, body }) {
const { min, user } = await DialogKeywords.getProcessInfo(pid);
if (!body) {
body = "";
};
@ -545,6 +546,8 @@ export class DialogKeywords {
body = result.value;
}
if (emailToken) {
return new Promise<any>((resolve, reject) => {
sgMail.setApiKey(emailToken);
const msg = {
@ -563,6 +566,39 @@ export class DialogKeywords {
});
});
}
else {
let { client } = await GBDeployer.internalGetDriveClient(min);
const data = {
"message": {
"subject": subject,
"body": {
"contentType": "Text",
"content": body
},
"toRecipients": [
{
"emailAddress": {
"address": to
}
}
],
"from": {
"emailAddress": {
"address": process.env.EMAIL_FROM
}
}
}
};
await client.api('/me/sendMail')
.post(data);
GBLogEx.info(min, `E-mail para ${to} (${subject}) enviado.`);
}
}
/**
* Sends a file to a given mobile.
@ -1292,7 +1328,7 @@ export class DialogKeywords {
activities = activities.filter(m => m.from.id === min.botId && m.type === 'message');
if (activities.length) {
activities.forEach(activity => {
messages.push( activity.text );
messages.push(activity.text);
GBLogEx.info(min, `MESSAGE BOT answer from bot: ${activity.text}`);
});
}