Help with notifications for WhatsApp

smsoousa2 years ago

Hello everybody! I set up a server with whatsapp-web to send messages, I'm using the traccar SMS method for this service. I can send messages normally through the link
http://my-ip:4000/send?numeroDestinatario=55xxxxxxxxxx&texto=Hello, but when I try to use it in traccar 5.5 I always get an error, I've tried several ways. I wanted to know if anyone can help me with any tips. Thanks

my xml:

    <entry key='notificator.sms.manager.class'>org.traccar.sms.HttpSmsClient</entry>
    <entry key='sms.http.url'>http://my-ip:4000/send?</entry>
    <entry key='sms.http.template'>{"destino": "{phone}","mensagem": "{message}"}</entry>

error:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>Cannot POST /send</pre> </body> </html> - MessageException (HttpSmsClient:96 < NotificatorSms:50 < NotificationResource:96 < ...)
Cristian2 years ago

But in versions prior to 5.5 it worked? You can test the whatsapp api in this link to see if it works. https://reqbin.com

Anton Tananaev2 years ago

Your config doesn't match your sample link, so I'm not sure how you expect it to work.

Cristian2 years ago
smsoousa2 years ago

I'm sorry for this! I ended up sending one of the messages I had sent earlier. Here is the current configuration:

<entry key='sms.enable'>true</entry>
<entry key='notificator.sms.manager.class'>org.traccar.sms.HttpSmsClient</entry>
<entry key='sms.http.url'>http://my-ip:3000/send?</entry>     
<entry key='sms.http.template'>{"numeroDestinatario": "{phone}","texto": "{message}"}</entry>

When I click on test channels this is the error:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>Cannot POST /send</pre> </body> </html> - MessageException (HttpSmsClient:96 < NotificatorSms:50 < NotificationResource:96 < ...)

This is the url I use to send a message through the browser and it works perfectly:

http://my-ip:3000/send?numeroDestinatario=55[number]&texto=test
smsoousa2 years ago

@cristian I didn't get to test it in previous versions, but I'll provide a test and return with the answer.

smsoousa2 years ago

this is the result of ReqBin

Description text

Anton Tananaev2 years ago

I still don't understand why you have one format when you test it, but then you use completely different format when you put it in Traccar configuration file. Does your service expect query parameters or JSON payload?

smsoousa2 years ago

I'm sorry for my ignorance, could you show me what's wrong? Suddenly in how I am assembling the XML. I'm using the pattern I saw in the documentation.

Anton Tananaev2 years ago

I already explained exactly what's wrong. Are you planning to answer my question?

smsoousa2 years ago

Yes, the server I built expects query parameters in the URL. In the example I provided earlier, the parameters are passed in the URL itself as part of the query string.

Anton Tananaev2 years ago

Traccar does not support query parameters. We only support data in the payload.

smsoousa2 years ago

Perfect, now it makes sense. Thank you for your help. I will reprogram the whatsapp server to work with the POST method

smsoousa2 years ago

Hello everyone! I adjusted the server to send via POST, this working perfectly, I did the tests on the postman, however, has a small detail, the data is sent by the body. When I do the notification test in the tracar, it says that the data is invalid, that is, it is not sending the data. Would there be any additional configuration?

{
    "status": false,
    "message": {
        "number": "Invalid value",
        "message": "Invalid value"
    }
}

my XML:

<entry key='sms.enable'>true</entry>
<entry key='notificator.sms.manager.class'>org.traccar.sms.HttpSmsClient</entry>
<entry key='sms.http.url'>http://xxxxxxxxxxx:9000/send-message</entry>
<entry key='sms.http.template'>
    {
        "number": "{phone}",
        "message": "{message}"
    }
</entry>
{"status":false,"message":{"number":"Invalid value","message":"Invalid value"}} - MessageException (HttpSmsClient:96 < NotificatorSms:50 < NotificationResource:96 < ...)

Description text

Anton Tananaev2 years ago

Once again you're sending one thing in Postman and completely different thing in Traccar. Why are you not testing the same thing? It seems like your server is expecting a form, but you're configuring Traccar to send a JSON.