new(whatsapp.gblib): Native provider works in groups now.
This commit is contained in:
parent
9e84298ab0
commit
64d77b4b43
2 changed files with 29 additions and 16 deletions
|
@ -991,7 +991,10 @@ export class GBConversationalService {
|
||||||
analytics.createMessage(min.instance.instanceId, user.conversation, null, text);
|
analytics.createMessage(min.instance.instanceId, user.conversation, null, text);
|
||||||
|
|
||||||
if (!isNaN(member.id) && !member.id.startsWith('1000')) {
|
if (!isNaN(member.id) && !member.id.startsWith('1000')) {
|
||||||
await min.whatsAppDirectLine.sendToDevice(member.id, text, step.context.activity.conversation.id);
|
|
||||||
|
const to = step.context.activity.group? step.context.activity.group : member.id;
|
||||||
|
|
||||||
|
await min.whatsAppDirectLine.sendToDevice(to, text, step.context.activity.conversation.id);
|
||||||
} else {
|
} else {
|
||||||
await step.context.sendActivity(text);
|
await step.context.sendActivity(text);
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,7 +344,8 @@ export class WhatsappDirectLine extends GBService {
|
||||||
case 'GeneralBots':
|
case 'GeneralBots':
|
||||||
message = req;
|
message = req;
|
||||||
text = message.body;
|
text = message.body;
|
||||||
from = message.from.split('@')[0];
|
from = message.from.endsWith('@g.us') ?
|
||||||
|
message.author.split('@')[0] : message.from.split('@')[0];
|
||||||
fromName = message._data.notifyName;
|
fromName = message._data.notifyName;
|
||||||
|
|
||||||
if (message.hasMedia) {
|
if (message.hasMedia) {
|
||||||
|
@ -727,7 +728,16 @@ export class WhatsappDirectLine extends GBService {
|
||||||
switch (this.provider) {
|
switch (this.provider) {
|
||||||
case 'GeneralBots':
|
case 'GeneralBots':
|
||||||
const attachment = await MessageMedia.fromUrl(url);
|
const attachment = await MessageMedia.fromUrl(url);
|
||||||
await this.customClient.sendMessage(to + '@c.us', attachment, { caption: caption });
|
if (to.indexOf('@') == -1) {
|
||||||
|
if (to.length == 18) {
|
||||||
|
to = to + '@g.us';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
to = to + '@c.us';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.customClient.sendMessage(to, attachment, { caption: caption });
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'chatapi':
|
case 'chatapi':
|
||||||
|
@ -859,15 +869,15 @@ export class WhatsappDirectLine extends GBService {
|
||||||
switch (this.provider) {
|
switch (this.provider) {
|
||||||
case 'GeneralBots':
|
case 'GeneralBots':
|
||||||
|
|
||||||
if (to.length == 18)
|
if (to.indexOf('@') == -1) {
|
||||||
{
|
if (to.length == 18) {
|
||||||
to = to + '@g.us';
|
to = to + '@g.us';
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
to = to + '@c.us';
|
to = to + '@c.us';
|
||||||
}
|
}
|
||||||
this.customClient.sendMessage(to, msg);
|
}
|
||||||
|
await this.customClient.sendMessage(to, msg);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1008,7 +1018,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
|
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
|
|
||||||
let user = await sec.ensureUser(this.min.instance.instanceId, id,senderName,'', 'whatsApp', senderName, null);
|
let user = await sec.ensureUser(this.min.instance.instanceId, id, senderName, '', 'whatsApp', senderName, null);
|
||||||
GBLog.info(`A WhatsApp mobile requested instance for: ${botId}.`);
|
GBLog.info(`A WhatsApp mobile requested instance for: ${botId}.`);
|
||||||
|
|
||||||
let urlMin: any = GBServer.globals.minInstances.filter
|
let urlMin: any = GBServer.globals.minInstances.filter
|
||||||
|
@ -1045,7 +1055,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
function getKeyByValue(object, value) {
|
function getKeyByValue(object, value) {
|
||||||
return Object.keys(object).find(key => object[key] === value);
|
return Object.keys(object).find(key => object[key] === value);
|
||||||
}
|
}
|
||||||
const botId = getKeyByValue(WhatsappDirectLine.botGroups, group) ;
|
const botId = getKeyByValue(WhatsappDirectLine.botGroups, group);
|
||||||
if (botId && user.instanceId !== this.min.instance.instanceId) {
|
if (botId && user.instanceId !== this.min.instance.instanceId) {
|
||||||
await sec.updateUserInstance(id, this.min.instance.instanceId);
|
await sec.updateUserInstance(id, this.min.instance.instanceId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue