new(whatsapp.gblib): New WhatsApp provider: Meta.
This commit is contained in:
parent
db80d556c1
commit
3ec96d7bdd
1 changed files with 56 additions and 20 deletions
|
@ -157,7 +157,7 @@ export class DialogKeywords {
|
||||||
* Returns the OCR of image file.
|
* Returns the OCR of image file.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async getOCR({pid, localFile }) {
|
public async getOCR({ pid, localFile }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: OCR processing on ${localFile}.`);
|
GBLogEx.info(min, `BASIC: OCR processing on ${localFile}.`);
|
||||||
|
|
||||||
|
@ -529,6 +529,7 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async sendEmail({ pid, to, subject, body }) {
|
public async sendEmail({ pid, to, subject, body }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
if (!body) {
|
if (!body) {
|
||||||
body = "";
|
body = "";
|
||||||
};
|
};
|
||||||
|
@ -545,23 +546,58 @@ export class DialogKeywords {
|
||||||
body = result.value;
|
body = result.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise<any>((resolve, reject) => {
|
|
||||||
sgMail.setApiKey(emailToken);
|
if (emailToken) {
|
||||||
const msg = {
|
return new Promise<any>((resolve, reject) => {
|
||||||
to: to,
|
sgMail.setApiKey(emailToken);
|
||||||
from: process.env.EMAIL_FROM,
|
const msg = {
|
||||||
subject: subject,
|
to: to,
|
||||||
text: body,
|
from: process.env.EMAIL_FROM,
|
||||||
html: body
|
subject: subject,
|
||||||
};
|
text: body,
|
||||||
sgMail.send(msg, false, (err, res) => {
|
html: body
|
||||||
if (err) {
|
};
|
||||||
reject(err);
|
sgMail.send(msg, false, (err, res) => {
|
||||||
} else {
|
if (err) {
|
||||||
resolve(res);
|
reject(err);
|
||||||
}
|
} else {
|
||||||
|
resolve(res);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
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.`);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1292,7 +1328,7 @@ export class DialogKeywords {
|
||||||
activities = activities.filter(m => m.from.id === min.botId && m.type === 'message');
|
activities = activities.filter(m => m.from.id === min.botId && m.type === 'message');
|
||||||
if (activities.length) {
|
if (activities.length) {
|
||||||
activities.forEach(activity => {
|
activities.forEach(activity => {
|
||||||
messages.push( activity.text );
|
messages.push(activity.text);
|
||||||
GBLogEx.info(min, `MESSAGE BOT answer from bot: ${activity.text}`);
|
GBLogEx.info(min, `MESSAGE BOT answer from bot: ${activity.text}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue