Wrong character encoding when fetching message
IllesAprod opened this issue · comments
Issue Summary
When fetching a message with twilio-php it gives me wrong encoded characters (on client side with js sdk we get good encoding)
Steps to Reproduce
- Send message to conversations from js sdk containing these characters: ááűűúúőőóóüüööíí
- Fetching message with twilio-php
$messageSid = 'YYY';
$message = $client->conversations->v1->services('XXX')->conversations($sid)->messages($messageSid)->fetch();
- dump $message->body getting characters like: ááűűúúÅ�Å�óóüüööÃÃ
Possible workaround:
With iconv we were able to minimize wrong characters, but "ő" stil not working
ááűűúúőőóóüüööíí --> ááűűúú�?�?óóüüööíí
Example code:
$fixed = iconv("UTF-8", "Windows-1252//TRANSLIT", $message->body);
Technical details:
- twilio-php version: 6.21.0
- php version: 7.4
@IllesAprod I wasn't able to reproduce it. Have you tried curl-ing to see what you get back?
curl -H "Accept-Charset: utf-8" -X GET 'https://conversations.twilio.com/v1/Conversations/CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
Thanks for your reply, I tried with curl (I had to put /Services/ISXXX... in the url but I dont think it makes any difference)
The message what i sent was (Screenshot from twilio js conversations sdk)
ááűűúúőőóóüüööíí
{"body": "\u00c3\u00a1\u00c3\u00a1\u00c5\u00b1\u00c5\u00b1\u00c3\u00ba\u00c3\u00ba\u00c5\u0091\u00c5\u0091\u00c3\u00b3\u00c3\u00b3\u00c3\u00bc\u00c3\u00bc\u00c3\u00b6\u00c3\u00b6\u00c3\u00ad\u00c3\u00ad"
Which is converted (using this converter: https://r12a.github.io/app-conversion/)
ááűűúúÅ�Å�óóüüööÃÃ
And that looks the same what i get when I try
$message = $client->conversations->v1->services('XXX')->conversations($sid)->messages($messageSid)->fetch();
var_dump($message->body);
So as I can see this is a Twilio Backend related error, can u help how to reach them with that?
We went further and we had to use $body = utf8_decode($message->body); to get good encoding (maybe it should be added to the sdk?)
Thanks for your help
Hi @IllesAprod I suggest reaching out to support and discussing this issue with them.