Closed SECVESHA closed 1 year ago
Is there an existing issue for this?
- [x] I have searched the existing issues
Describe the bug
When I try this code client.sendMessage('NUMBER@c.us', 'hi'), the bot does send the message indeed, but it doesn't send it to the specified number! How do I know this? Because the number I'm trying to send the message to is my own! If it's within message.to or message.from, it sends normally, but when specifying the number directly, it kind of creates a chat with a number that's exactly identical to mine, both in the country code and area code, and sends the message to it! But the message doesn't reach me on my correct number. Why is this happening?
Expected behavior
client.sendMessage('NUMBER@c.us', 'hi')
Steps to Reproduce the Bug or Issue
1 - Try to use client.sendMessage(message.from, 'test') You need to make sure that message.to or message.from is the same number to which we will try to send a message later on.'
2 - If you did that, you probably sent the message correctly! Now, add a console.log(message.from || message.to) and copy the ID.
3 - try to use client.sendMessage('ID-COPIED', 'test')
Don't rely on LOGS because they will indicate that the message was sent... However, when you enter the WhatsApp to which you sent the message, you will see that something went wrong! It sent to a clone number without a profile picture and not to the correct number.
Relevant Code
client.on('message_create', async message => { if (message.fromMe) { if (message.body === 'š') { const chat = await message.getChat(); await chat.sendStateTyping(); await new Promise((resolve) => setTimeout(resolve, 3000)); await client.sendMessage(message.to, entrega); // Sucess console.log(message.to) client.sendMessage('NUMBER1@c.us', entrega) // ProblemW
Browser Type
Google Chrome
WhatsApp Account Type
Standard
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
Windows 10
Additional context
No response
Best is to describe what you want to achieve as it lacks information to give any solution ? as best way to tackle this is to reply using
message.reply('message');
In any case to send a message to a custom number you need to add country code to the number without + like this
let number = "1234567890";
let country_code = "91" // +91 is country code for India but here its without +
let final = country_code+number+"@c.us";
client.sendMessage(final, 'message sent!');
Try this and reply !
For me, the bug was in calling the processAttachments
method. Changed the order of the parameters.
Credits to https://github.com/vilsonei, that fix the bug.
Working here:
var mc = new Store.MediaCollection(chat);
mc.processAttachments([{ file: mediaBlob }, 1], 1, chat).then(() => {
var media = mc._models[0]
media.sendToChat(chat, { caption: caption });
});
client.getNumberId(phoneNumber) .then((result) => { if (result) { console.log('Number ID:', result); } else { console.log('NO EXIST.'); } }) .catch((error) => { console.error('Error to get Number ID:', error); });
i The problem is actually because I was having errors when sending numbers that contained the number " 9 " as an additional, so a good practice is to always check the numberID and get the serialized returned, after doing this I was able to normally send the messages properly.
I think it's not only because of that. I'm getting the contact the same way (when the number is provided and the chat doesn't exist) and sometimes still failing like you mentioned ("sent" but not really sent). Plus, there's some people reporting the exact same issue for the first time on the discord (some of them mention that this happened to them with captioned document messages but are not sure about this).
Is there an existing issue for this?
Describe the bug
When I try this code client.sendMessage('NUMBER@c.us', 'hi'), the bot does send the message indeed, but it doesn't send it to the specified number! How do I know this? Because the number I'm trying to send the message to is my own! If it's within message.to or message.from, it sends normally, but when specifying the number directly, it kind of creates a chat with a number that's exactly identical to mine, both in the country code and area code, and sends the message to it! But the message doesn't reach me on my correct number. Why is this happening?
Expected behavior
client.sendMessage('NUMBER@c.us', 'hi')
Steps to Reproduce the Bug or Issue
1 - Try to use client.sendMessage(message.from, 'test') You need to make sure that message.to or message.from is the same number to which we will try to send a message later on.'
2 - If you did that, you probably sent the message correctly! Now, add a console.log(message.from || message.to) and copy the ID.
3 - try to use client.sendMessage('ID-COPIED', 'test')
Don't rely on LOGS because they will indicate that the message was sent... However, when you enter the WhatsApp to which you sent the message, you will see that something went wrong! It sent to a clone number without a profile picture and not to the correct number.
Relevant Code
client.on('message_create', async message => { if (message.fromMe) { if (message.body === 'š') { const chat = await message.getChat(); await chat.sendStateTyping(); await new Promise((resolve) => setTimeout(resolve, 3000)); await client.sendMessage(message.to, entrega); // Sucess console.log(message.to) client.sendMessage('NUMBER1@c.us', entrega) // ProblemW
Browser Type
Google Chrome
WhatsApp Account Type
Standard
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
Windows 10
Additional context
No response