Can't send quotation characters in message
virtser opened this issue · comments
Try to send something like (notice the quotation marks in "these awesome"):
{
"GCM":"{\"data\":{\"message\":\"Check out "these awesome" deals!\",\"url\":\"www.amazon.com\"}}"
}
And you will get the following error:
'Invalid parameter: Message Reason: Invalid notification for protocol GCM: Notification payload is malformed',
Hi @virtser,
That JSON doesn't look correctly escaped. I created an Object with the same content that when I call JSON.stringify on prints:
var data = JSON.stringify({GCM:{data:{message:'Check out "these awesome" deals!',url:'www.amazon.com'}}});
// Prints this
"{"GCM":{"data":{"message":"Check out \"these awesome\" deals!","url":"www.amazon.com"}}}"
@virtser let me know if verifying the format helps.
@evanshortiss actually you can see in your readme file under publishToTopic section that you should escape the JSON with ", that's what SNS push infra expects. So the example that you gave won't work..
@virtser so you tried the format I provided and it failed? I didn't write the publishToTopic section since I've not used topics so can't comment much about them unfortuantely. @abiskop might be of more help in that regard.
Perhaps this requires a patch in the conversion layer here, or the internal quotes you've added around these awesome need extra escaping. It calls JSON.stringify for you but we'd need to test to see if that is the case.
My last suggestion would be to try the following, it has manually escaped the quotes you're having trouble with:
"GCM":"{\"data\":{\"message\":\"Check out \"these awesome\" deals!\",\"url\":\"www.amazon.com\"}}"
@evanshortiss thanks Ivan, I tried escaping it myself of course. It didn't work obviously.
Hey folks, I think the problem is that the default key is missing in the dictionary. As stated in the Readme, this key is mandatory.
@virtser, could you please check what happens when you specify something for the default key?
@abiskop it doesn't really make a difference to do it with or without default message, same result.
And it's not related to topics, I use this type of JSON message in sendMessage function.
@virtser, I'm on the road atm, but I will look into it the next days to see what's going on.
@virtser @evanshortiss Okay folks, sorry for the delay. Just moved over to California from Germany which ate up quite a bit of my time...But it's awesome over here ;-)
I looked into the issue and found a solution I think. The issue probably is that you would have to insert a set of escaped backslashes before the (escaped) quotes, so that the backslashes will be preserved through the first layer of JSON deserialization:
> var o = { "GCM":"{\"data\":{\"message\":\"Check out \\\"these awesome\\\" deals!\",\"url\":\"www.amazon.com\"}}" }
undefined
> o
{ GCM: '{"data":{"message":"Check out \\"these awesome\\" deals!","url":"www.amazon.com"}}' }
> JSON.parse(o.GCM)
{ data:
{ message: 'Check out "these awesome" deals!',
url: 'www.amazon.com' } }
>
I didn't have a chance to test it on SNS, but I am pretty confident that this is the culprit (apart from the default
key issue). @virtser Could you please check if this solves the issue?
That did the trick.
Thanks a lot! :)