Setting up Twilio

HJvD4 years ago

Hi,

Just updated to 4.2. Perfect job!

Now trying to set up SMS messaging with Twilio. What is meant by that the phone number has to be URL encoded? How do I encode the phone number?

jaimzj4 years ago

https://www.w3schools.com/tags/ref_urlencode.asp refer to this link for URL encoding details

Sharing with you the configuration for twilio that worked for me (for privacy i will mask the values with *) make sure the sms.http.url also you add your account sid.

<entry key='notificator.types'>web,mail,sms</entry>
<entry key='notificator.sms.manager.class'>org.traccar.sms.HttpSmsClient</entry>
<entry key='sms.http.url'>https://api.twilio.com/2010-04-01/Accounts/A**********************/Messages.json</entry>
<entry key='sms.http.user'>A**********************</entry>
<entry key='sms.http.password'>d******************************</entry>
<entry key='sms.http.template'>
    From=%2B12264074230&To={phone}&Body={message}
</entry>
Anton Tananaev4 years ago

For phone number the only thing you need to encode is probably the plus sign. It should be encoded as %2B.

parelius4 years ago

Have tryed allmost all, bu i`m getting this error...

2018-11-11 17:43:44  WARN: SMS send failed - 
javax.ws.rs.client.ResponseProcessingException: javax.ws.rs.BadRequestException: HTTP 400 BAD REQUEST
    at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:1109)
    at org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:99)
    at org.glassfish.jersey.client.JerseyInvocation$4.completed(JerseyInvocation.java:1017)
    at org.glassfish.jersey.client.ClientRuntime.processResponse(ClientRuntime.java:227)
    at org.glassfish.jersey.client.ClientRuntime.access$200(ClientRuntime.java:85)
    at org.glassfish.jersey.client.ClientRuntime$2.lambda$response$0(ClientRuntime.java:178)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:312)
    at org.glassfish.jersey.client.ClientRuntime$2.response(ClientRuntime.java:178)
    at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:292)
    at org.glassfish.jersey.client.ClientRuntime.lambda$null$3(ClientRuntime.java:187)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:312)
    at org.glassfish.jersey.client.ClientRuntime.lambda$createRunnableForAsyncProcessing$4(ClientRuntime.java:163)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: javax.ws.rs.BadRequestException: HTTP 400 BAD REQUEST
    at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:1077)
    ... 26 more
Anton Tananaev4 years ago

I suspect that either "from" or "to" phone numbers are incorrect.

jaimzj4 years ago

Or a possibility is you have not mentioned the SID in sms.http.url value.

parelius4 years ago

I found that i have a "space" to mutch :)
I got it working now, but its sems to be very unstable... Its working every 3`rd time i try, and traccar service locks up now and then.

Get this error all the time:

2018-11-11 23:15:24  WARN: Client did not connect. - Connection refused: no further information: localhost/127.0.0.1:2775 - AnnotatedConnectException (...)
2018-11-11 23:15:24  WARN: Unable to connect to SMPP server:  - Unable to connect to host [localhost] and port [2775]: Connection refused: no further information: localhost/127.0.0.1:2775 - SmppChannelConnectException (... < SmppClient:171 < ReconnectionTask:29 < ...)
Anton Tananaev4 years ago

How is SMPP related to anything and why have you enabled it?

parelius4 years ago

i havent done any SMPP config, this showing up after i set up SMS via BulkSMS.

This is the only sms config i got:

<entry key='notificator.types'>web,mail,sms</entry>
<entry key='notificator.sms.manager.class'>org.traccar.sms.HttpSmsClient</entry>
<entry key='sms.http.url'>https://api.bulksms.com/v1/messages</entry>
<entry key='sms.http.user'>[YOUR TOKEN ID]</entry>
<entry key='sms.http.password'>[YOUR TOKEN SECRET]</entry>
<entry key='sms.http.template'>
    {
        "to": "{phone}",
        "body": "{message}"
    }
</entry>
Anton Tananaev4 years ago

Log message clearly shows that SMPP is enabled.

parelius4 years ago

My mistake. I thought "SMS Enable" had to be enabled to send sms.