Skip to content

Commit

Permalink
fix: Fixed send message to groups (close #1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jan 12, 2023
1 parent 7b1d83a commit f8bc6e4
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/util/functions.js
Expand Up @@ -28,19 +28,15 @@ export function contactToArray(number, isGroup) {
let localArr = [];
if (Array.isArray(number)) {
for (let contact of number) {
while (!/^[a-zA-Z0-9]+$/.test(contact)) {
contact = contact?.split('@')[0]?.split(':')[0]?.replace(/\D/g, '');
}
isGroup ? (contact = contact.split('@')[0]) : (contact = contact.split('@')[0]?.replace(/[^\w ]/g, ''));
if (contact !== '')
if (isGroup) localArr.push(`${contact}@g.us`);
else localArr.push(`${contact}@c.us`);
}
} else {
let arrContacts = number.split(/\s*[,;]\s*/g);
for (let contact of arrContacts) {
while (!/^[a-zA-Z0-9]+$/.test(contact)) {
contact = contact?.split('@')[0]?.split(':')[0]?.replace(/\D/g, '');
}
isGroup ? (contact = contact.split('@')[0]) : (contact = contact.split('@')[0]?.replace(/[^\w ]/g, ''));
if (contact !== '')
if (isGroup) localArr.push(`${contact}@g.us`);
else localArr.push(`${contact}@c.us`);
Expand All @@ -54,17 +50,13 @@ export function groupToArray(group) {
let localArr = [];
if (Array.isArray(group)) {
for (let contact of group) {
while (!/^[a-zA-Z0-9]+$/.test(contact)) {
contact = contact?.split('@')[0]?.split(':')[0]?.replace(/\D/g, '');
}
contact = contact.split('@')[0];
if (contact !== '') localArr.push(`${contact}@g.us`);
}
} else {
let arrContacts = group.split(/\s*[,;]\s*/g);
for (let contact of arrContacts) {
while (!/^[a-zA-Z0-9]+$/.test(contact)) {
contact = contact?.split('@')[0]?.split(':')[0]?.replace(/\D/g, '');
}
contact = contact.split('@')[0];
if (contact !== '') localArr.push(`${contact}@g.us`);
}
}
Expand Down

0 comments on commit f8bc6e4

Please sign in to comment.