Fix number format issues
This commit is contained in:
parent
deedec1283
commit
3207c84296
24
chats-out.js
24
chats-out.js
@ -22,6 +22,11 @@ module.exports = function(RED) {
|
||||
// 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, '');
|
||||
@ -31,6 +36,13 @@ module.exports = function(RED) {
|
||||
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) {
|
||||
@ -57,6 +69,11 @@ module.exports = function(RED) {
|
||||
// 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, '');
|
||||
@ -66,6 +83,13 @@ module.exports = function(RED) {
|
||||
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){
|
||||
|
||||
24
group-out.js
24
group-out.js
@ -23,6 +23,11 @@ module.exports = function(RED) {
|
||||
// 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, '');
|
||||
@ -32,6 +37,13 @@ module.exports = function(RED) {
|
||||
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) {
|
||||
@ -58,6 +70,11 @@ module.exports = function(RED) {
|
||||
// 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, '');
|
||||
@ -67,6 +84,13 @@ module.exports = function(RED) {
|
||||
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){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user