hyphen fix
This commit is contained in:
parent
c8f6454512
commit
8e9297be06
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,2 +1,6 @@
|
||||
node_modules
|
||||
removed.rm
|
||||
removed.rm
|
||||
|
||||
fromwindows.json
|
||||
fromandroid.json
|
||||
fromnodered.json
|
||||
70
chats-out.js
70
chats-out.js
@ -14,27 +14,68 @@ module.exports = function(RED) {
|
||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
async function webNubmerSeteing(numb){
|
||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
||||
// numb = `${numb}@c.us`;
|
||||
var numbID = await node.waClient.getNumberId(numb);
|
||||
if(numbID) {
|
||||
return `${numbID.user}@${numbID.server}`;
|
||||
} else {
|
||||
return `${numb}@g.us`
|
||||
// Validate and clean the number
|
||||
if (!numb) {
|
||||
throw new Error('Number is required');
|
||||
}
|
||||
|
||||
// Convert to string if number
|
||||
numb = typeof numb === 'number' ? numb.toString() : numb;
|
||||
|
||||
// For group IDs, preserve the hyphen (format: NUMBER-TIMESTAMP@g.us)
|
||||
// Only strip non-digits and non-hyphens for cleaning
|
||||
numb = numb.replace(/[^\d-]/g, '');
|
||||
|
||||
// Check if number is valid after cleaning
|
||||
if (!numb || numb.length === 0) {
|
||||
throw new Error('Invalid number format');
|
||||
}
|
||||
|
||||
try {
|
||||
var numbID = await node.waClient.getNumberId(numb);
|
||||
if(numbID) {
|
||||
return `${numbID.user}@${numbID.server}`;
|
||||
} else {
|
||||
return `${numb}@g.us`
|
||||
}
|
||||
} catch (e) {
|
||||
node.error(`Error getting number ID for ${numb}: ${e.message}`);
|
||||
throw e;
|
||||
}
|
||||
// return numb
|
||||
}
|
||||
|
||||
async function socNubmerSeteing(numb){
|
||||
if (numb.remoteJid){
|
||||
if (numb && numb.remoteJid){
|
||||
return numb.remoteJid;
|
||||
}
|
||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
||||
const [result] = await (await node.waClient).onWhatsApp(numb)
|
||||
if (result?.exists){
|
||||
return result.jid
|
||||
|
||||
// Validate and clean the number
|
||||
if (!numb) {
|
||||
throw new Error('Number is required');
|
||||
}
|
||||
|
||||
// Convert to string if number
|
||||
numb = typeof numb === 'number' ? numb.toString() : numb;
|
||||
|
||||
// For group IDs, preserve the hyphen (format: NUMBER-TIMESTAMP@g.us)
|
||||
// Only strip non-digits and non-hyphens for cleaning
|
||||
numb = numb.replace(/[^\d-]/g, '');
|
||||
|
||||
// Check if number is valid after cleaning
|
||||
if (!numb || numb.length === 0) {
|
||||
throw new Error('Invalid number format');
|
||||
}
|
||||
|
||||
try {
|
||||
const [result] = await (await node.waClient).onWhatsApp(numb)
|
||||
if (result?.exists){
|
||||
return result.jid
|
||||
}
|
||||
return numb = `${numb}@g.us`;
|
||||
} catch (e) {
|
||||
node.error(`Error checking WhatsApp for ${numb}: ${e.message}`);
|
||||
throw e;
|
||||
}
|
||||
return numb = `${numb}@g.us`;
|
||||
}
|
||||
|
||||
async function whatsappMessage(numb , inputMessage){
|
||||
@ -43,7 +84,6 @@ module.exports = function(RED) {
|
||||
numb = await webNubmerSeteing(numb);
|
||||
if(typeof inputMessage === "object"){
|
||||
inputMessage = new Buttons(inputMessage.text, inputMessage.buttons, "text" ,inputMessage.footer);
|
||||
node.waClient.sendMessage(numb, inputMessage);
|
||||
}
|
||||
node.waClient.sendMessage(numb, inputMessage);
|
||||
}
|
||||
|
||||
70
group-out.js
70
group-out.js
@ -15,28 +15,68 @@ module.exports = function(RED) {
|
||||
|
||||
|
||||
async function webNubmerSeteing(numb){
|
||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
||||
// numb = `${numb}@c.us`;
|
||||
var numbID = await node.waClient.getNumberId(numb);
|
||||
if(numbID) {
|
||||
return `${numbID.user}@${numbID.server}`;
|
||||
} else {
|
||||
return `${numb}@g.us`
|
||||
// Validate and clean the number
|
||||
if (!numb) {
|
||||
throw new Error('Number is required');
|
||||
}
|
||||
|
||||
// Convert to string if number
|
||||
numb = typeof numb === 'number' ? numb.toString() : numb;
|
||||
|
||||
// For group IDs, preserve the hyphen (format: NUMBER-TIMESTAMP@g.us)
|
||||
// Only strip non-digits and non-hyphens for cleaning
|
||||
numb = numb.replace(/[^\d-]/g, '');
|
||||
|
||||
// Check if number is valid after cleaning
|
||||
if (!numb || numb.length === 0) {
|
||||
throw new Error('Invalid number format');
|
||||
}
|
||||
|
||||
try {
|
||||
var numbID = await node.waClient.getNumberId(numb);
|
||||
if(numbID) {
|
||||
return `${numbID.user}@${numbID.server}`;
|
||||
} else {
|
||||
return `${numb}@g.us`
|
||||
}
|
||||
} catch (e) {
|
||||
node.error(`Error getting number ID for ${numb}: ${e.message}`);
|
||||
throw e;
|
||||
}
|
||||
// return numb
|
||||
}
|
||||
|
||||
async function socNubmerSeteing(numb){
|
||||
if (numb.remoteJid){
|
||||
if (numb && numb.remoteJid){
|
||||
return numb.remoteJid;
|
||||
}
|
||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
||||
const [result] = await (await node.waClient).onWhatsApp(numb)
|
||||
if (result?.exists){
|
||||
console.log(result.exists)
|
||||
return result.jid
|
||||
|
||||
// Validate and clean the number
|
||||
if (!numb) {
|
||||
throw new Error('Number is required');
|
||||
}
|
||||
|
||||
// Convert to string if number
|
||||
numb = typeof numb === 'number' ? numb.toString() : numb;
|
||||
|
||||
// For group IDs, preserve the hyphen (format: NUMBER-TIMESTAMP@g.us)
|
||||
// Only strip non-digits and non-hyphens for cleaning
|
||||
numb = numb.replace(/[^\d-]/g, '');
|
||||
|
||||
// Check if number is valid after cleaning
|
||||
if (!numb || numb.length === 0) {
|
||||
throw new Error('Invalid number format');
|
||||
}
|
||||
|
||||
try {
|
||||
const [result] = await (await node.waClient).onWhatsApp(numb)
|
||||
if (result?.exists){
|
||||
return result.jid
|
||||
}
|
||||
return numb = `${numb}@g.us`;
|
||||
} catch (e) {
|
||||
node.error(`Error checking WhatsApp for ${numb}: ${e.message}`);
|
||||
throw e;
|
||||
}
|
||||
return numb = `${numb}@g.us`;
|
||||
}
|
||||
|
||||
async function whatsappMessage(numb , inputMessage){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user