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

This commit is contained in:
Rodrigo Rodriguez 2024-05-03 14:18:16 -03:00
parent bb6c202a1b
commit 645af9acd4
2 changed files with 13 additions and 9 deletions

View file

@ -525,8 +525,6 @@ export class GBVMService extends GBService {
const channel = this.channel; const channel = this.channel;
const ENTER = this.ENTER; const ENTER = this.ENTER;
const headers = this.headers; const headers = this.headers;
let data = this.data;
let list = this.list;
let httpUsername = this.httpUsername; let httpUsername = this.httpUsername;
let httpPs = this.httpPs; let httpPs = this.httpPs;
let today = this.today; let today = this.today;
@ -1107,8 +1105,6 @@ export class GBVMService extends GBService {
sandbox['from'] = await dk.userMobile({ pid }); sandbox['from'] = await dk.userMobile({ pid });
sandbox['ENTER'] = String.fromCharCode(13); sandbox['ENTER'] = String.fromCharCode(13);
sandbox['headers'] = {}; sandbox['headers'] = {};
sandbox['data'] = {};
sandbox['list'] = [];
sandbox['httpUsername'] = ''; sandbox['httpUsername'] = '';
sandbox['httpPs'] = ''; sandbox['httpPs'] = '';
sandbox['pid'] = pid; sandbox['pid'] = pid;

View file

@ -648,9 +648,15 @@ export class GBConversationalService {
}); });
} }
public async fillAndBroadcastTemplate(min: GBMinInstance, step: GBDialogStep, mobile: string, text) { public async fillAndBroadcastTemplate(min: GBMinInstance, mobile: string, text) {
let isMedia = text.toLowerCase().endsWith('.jpg') || text.toLowerCase().endsWith('.jpeg')
|| text.toLowerCase().endsWith('.png');
let image = isMedia ?
/(.*)\n/gmi.exec(text)[0].trim():
text;
let image = /(.*)\n/gmi.exec(text)[0].trim();
const gbaiName = DialogKeywords.getGBAIPath(min.botId); const gbaiName = DialogKeywords.getGBAIPath(min.botId);
const fileUrl = urlJoin(process.env.BOT_URL,'kb', gbaiName, `${min.botId}.gbkb`, 'images', image); const fileUrl = urlJoin(process.env.BOT_URL,'kb', gbaiName, `${min.botId}.gbkb`, 'images', image);
@ -658,11 +664,13 @@ export class GBConversationalService {
? image ? image
: fileUrl; : fileUrl;
if (!isMedia){
text = text.substring(image.length).trim(); text = text.substring(image.length).trim();
text = text.replace(/\n/g, "\\n"); text = text.replace(/\n/g, "\\n");
}
let data = { let data = {
name: 'broadcast', components: [ name: isMedia?'broadcast_notext':'broadcast', components: [
{ {
type: "header", type: "header",
parameters: [ parameters: [