hyphen fix
This commit is contained in:
parent
c8f6454512
commit
8e9297be06
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,6 @@
|
|||||||
node_modules
|
node_modules
|
||||||
removed.rm
|
removed.rm
|
||||||
|
|
||||||
|
fromwindows.json
|
||||||
|
fromandroid.json
|
||||||
|
fromnodered.json
|
||||||
52
chats-out.js
52
chats-out.js
@ -14,27 +14,68 @@ module.exports = function(RED) {
|
|||||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
async function webNubmerSeteing(numb){
|
async function webNubmerSeteing(numb){
|
||||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
// Validate and clean the number
|
||||||
// numb = `${numb}@c.us`;
|
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);
|
var numbID = await node.waClient.getNumberId(numb);
|
||||||
if(numbID) {
|
if(numbID) {
|
||||||
return `${numbID.user}@${numbID.server}`;
|
return `${numbID.user}@${numbID.server}`;
|
||||||
} else {
|
} else {
|
||||||
return `${numb}@g.us`
|
return `${numb}@g.us`
|
||||||
}
|
}
|
||||||
// return numb
|
} catch (e) {
|
||||||
|
node.error(`Error getting number ID for ${numb}: ${e.message}`);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function socNubmerSeteing(numb){
|
async function socNubmerSeteing(numb){
|
||||||
if (numb.remoteJid){
|
if (numb && numb.remoteJid){
|
||||||
return numb.remoteJid;
|
return numb.remoteJid;
|
||||||
}
|
}
|
||||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
|
||||||
|
// 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)
|
const [result] = await (await node.waClient).onWhatsApp(numb)
|
||||||
if (result?.exists){
|
if (result?.exists){
|
||||||
return result.jid
|
return result.jid
|
||||||
}
|
}
|
||||||
return numb = `${numb}@g.us`;
|
return numb = `${numb}@g.us`;
|
||||||
|
} catch (e) {
|
||||||
|
node.error(`Error checking WhatsApp for ${numb}: ${e.message}`);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function whatsappMessage(numb , inputMessage){
|
async function whatsappMessage(numb , inputMessage){
|
||||||
@ -43,7 +84,6 @@ module.exports = function(RED) {
|
|||||||
numb = await webNubmerSeteing(numb);
|
numb = await webNubmerSeteing(numb);
|
||||||
if(typeof inputMessage === "object"){
|
if(typeof inputMessage === "object"){
|
||||||
inputMessage = new Buttons(inputMessage.text, inputMessage.buttons, "text" ,inputMessage.footer);
|
inputMessage = new Buttons(inputMessage.text, inputMessage.buttons, "text" ,inputMessage.footer);
|
||||||
node.waClient.sendMessage(numb, inputMessage);
|
|
||||||
}
|
}
|
||||||
node.waClient.sendMessage(numb, inputMessage);
|
node.waClient.sendMessage(numb, inputMessage);
|
||||||
}
|
}
|
||||||
|
|||||||
52
group-out.js
52
group-out.js
@ -15,28 +15,68 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
|
|
||||||
async function webNubmerSeteing(numb){
|
async function webNubmerSeteing(numb){
|
||||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
// Validate and clean the number
|
||||||
// numb = `${numb}@c.us`;
|
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);
|
var numbID = await node.waClient.getNumberId(numb);
|
||||||
if(numbID) {
|
if(numbID) {
|
||||||
return `${numbID.user}@${numbID.server}`;
|
return `${numbID.user}@${numbID.server}`;
|
||||||
} else {
|
} else {
|
||||||
return `${numb}@g.us`
|
return `${numb}@g.us`
|
||||||
}
|
}
|
||||||
// return numb
|
} catch (e) {
|
||||||
|
node.error(`Error getting number ID for ${numb}: ${e.message}`);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function socNubmerSeteing(numb){
|
async function socNubmerSeteing(numb){
|
||||||
if (numb.remoteJid){
|
if (numb && numb.remoteJid){
|
||||||
return numb.remoteJid;
|
return numb.remoteJid;
|
||||||
}
|
}
|
||||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
|
||||||
|
// 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)
|
const [result] = await (await node.waClient).onWhatsApp(numb)
|
||||||
if (result?.exists){
|
if (result?.exists){
|
||||||
console.log(result.exists)
|
|
||||||
return result.jid
|
return result.jid
|
||||||
}
|
}
|
||||||
return numb = `${numb}@g.us`;
|
return numb = `${numb}@g.us`;
|
||||||
|
} catch (e) {
|
||||||
|
node.error(`Error checking WhatsApp for ${numb}: ${e.message}`);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function whatsappMessage(numb , inputMessage){
|
async function whatsappMessage(numb , inputMessage){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user