Compare commits

...

3 Commits

Author SHA1 Message Date
3207c84296 Fix number format issues 2025-11-17 09:58:53 +01:00
deedec1283 git url? 2025-11-17 09:50:07 +01:00
8e9297be06 hyphen fix 2025-11-17 09:41:01 +01:00
4 changed files with 167 additions and 35 deletions

6
.gitignore vendored
View File

@ -1,2 +1,6 @@
node_modules
removed.rm
removed.rm
fromwindows.json
fromandroid.json
fromnodered.json

View File

@ -14,27 +14,92 @@ 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;
// Check if it's already a formatted ID (contains @)
if (numb.includes('@')) {
return 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');
}
// Check if it looks like a group ID (contains hyphen)
if (numb.includes('-')) {
// It's a group ID, format it directly without validation
return `${numb}@g.us`;
}
// It's a regular phone number, validate with getNumberId
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;
// Check if it's already a formatted ID (contains @)
if (numb.includes('@')) {
return 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');
}
// Check if it looks like a group ID (contains hyphen)
if (numb.includes('-')) {
// It's a group ID, format it directly
return `${numb}@g.us`;
}
// It's a regular phone number, validate with onWhatsApp
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 +108,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);
}

View File

@ -15,28 +15,92 @@ 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;
// Check if it's already a formatted ID (contains @)
if (numb.includes('@')) {
return 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');
}
// Check if it looks like a group ID (contains hyphen)
if (numb.includes('-')) {
// It's a group ID, format it directly without validation
return `${numb}@g.us`;
}
// It's a regular phone number, validate with getNumberId
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;
// Check if it's already a formatted ID (contains @)
if (numb.includes('@')) {
return 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');
}
// Check if it looks like a group ID (contains hyphen)
if (numb.includes('-')) {
// It's a group ID, format it directly
return `${numb}@g.us`;
}
// It's a regular phone number, validate with onWhatsApp
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){

View File

@ -1,13 +1,13 @@
{
"name": "node-red-contrib-whatsapp-link",
"version": "0.1.39C",
"version": "1.0.40-local.1",
"description": "Node to send and receive whatsapp messages in groups and chats. | No third party APIs",
"repository": {
"type": "git",
"url": "git+https://github.com/raweee/node-red-contrib-whatsapp-link.git"
"url": "git+https://gitea.delphas.dk/daniels/node-red-contrib-whatsapp-link.git"
},
"bugs": {
"url": "https://github.com/raweee/node-red-contrib-whatsapp-link/issues"
"url": "git+https://gitea.delphas.dk/daniels/node-red-contrib-whatsapp-link/issues"
},
"keywords": [
"node-red",
@ -16,7 +16,7 @@
"whatsapp Group",
"whatsapp Chat"
],
"author": "Ravi Mishra",
"author": "Daniel Gradman-Svendsen",
"license": "ISC",
"node-red": {
"version": ">=2.0",