JsonObject obj = paramJson(req.body());
if (obj.has("From") && obj.has("Body")) {
String body = URLDecoder.decode(obj.getAsJsonPrimitive("Body").getAsString(), "UTF-8");
String from = URLDecoder.decode(obj.getAsJsonPrimitive("From").getAsString(), "UTF-8").replace("whatsapp:", "");
if (!from.isEmpty() && !body.isEmpty())
textChannel.sendMessage("<WHATSAPP=" + from + ">" + body);
}
if (obj.has("MessageSid")) {
System.out.println("!!-!!");
ResourceSet<Media> mediaList = Media.reader(obj.getAsJsonPrimitive("MessageSid").getAsString()).read();
for (Media media : mediaList) {
textChannel.sendMessage("<WHATSAPP=>https://api.twilio.com" + media.getUri());
}
}
Exception/Log
13:19:18.893 [qtp1468410391-45] ERROR spark.http.matching.GeneralError -
com.twilio.exception.ApiException: The requested resource /2010-04-01/Accounts/AC75d9becf673eab453e2879cc1a70b34a/Messages/SMe153cd878958802011ccd560060006d6/Media.json was not found
at com.twilio.rest.api.v2010.account.message.MediaReader.pageForRequest(MediaReader.java:197)
at com.twilio.rest.api.v2010.account.message.MediaReader.firstPage(MediaReader.java:113)
at com.twilio.rest.api.v2010.account.message.MediaReader.read(MediaReader.java:92)
at com.twilio.base.Reader.read(Reader.java:25)
at com.teamwizardry.wizardrybot.TwilioWebListener.lambda$null$1(TwilioWebListener.java:75)
at java.util.Optional.ifPresent(Optional.java:159)
at com.teamwizardry.wizardrybot.TwilioWebListener.lambda$new$2(TwilioWebListener.java:62)
at spark.RouteImpl$1.handle(RouteImpl.java:72)
at spark.http.matching.Routes.execute(Routes.java:61)
at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:130)
at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1568)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:530)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:347)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:256)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:382)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:708)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:626)
at java.lang.Thread.run(Thread.java:748)
Steps to Reproduce
So basically, my app works well. I can interface with whatsapp just fine. I can get the body and the number sending the message just fine and do everything else properly. The messageSID is not null, it returns the actual sid given from the request body properly.
But when I send any file or image in whatsapp, That exception is thrown.
Observe the image sent from my WhatsApp to Twilio
So, what you can see in the image is:
1- The media file representing my current mood with the issue + a message attached. This resulted in an empty BODY as well. Not only was the media null and returned the exception above, but the body was also null for some reason despite adding "hey albus" attached to it"
2- Confirmation that regular raw text message are being processed correctly, therefore my SIDs are correct and everything else is functioning properly
3- A media file alone also returns no response (body is empty anyways) and also throws that exception
So I don't know if I'm doing something wrong or if this is a bug. I would like to note that the number I'm using hasn't been approved yet and that this is a sandbox number.
Version: 7.23.1
Code Snippet
Exception/Log
Steps to Reproduce
So basically, my app works well. I can interface with whatsapp just fine. I can get the body and the number sending the message just fine and do everything else properly. The messageSID is not null, it returns the actual sid given from the request body properly.
But when I send any file or image in whatsapp, That exception is thrown. Observe the image sent from my WhatsApp to Twilio![Image](https://user-images.githubusercontent.com/7407478/44204295-b4f6c580-a15a-11e8-93f4-06e875c4b2e1.png)
So, what you can see in the image is: 1- The media file representing my current mood with the issue + a message attached. This resulted in an empty BODY as well. Not only was the media null and returned the exception above, but the body was also null for some reason despite adding "hey albus" attached to it" 2- Confirmation that regular raw text message are being processed correctly, therefore my SIDs are correct and everything else is functioning properly 3- A media file alone also returns no response (body is empty anyways) and also throws that exception
So I don't know if I'm doing something wrong or if this is a bug. I would like to note that the number I'm using hasn't been approved yet and that this is a sandbox number.