twilio / twilio-php

A PHP library for communicating with the Twilio REST API and generating TwiML.
MIT License
1.57k stars 562 forks source link

Wrong character encoding when fetching message #686

Closed IllesAprod closed 3 years ago

IllesAprod commented 3 years ago

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

  1. Send message to conversations from js sdk containing these characters: ááűűúúőőóóüüööíí
  2. Fetching message with twilio-php
    $messageSid = 'YYY';
    $message = $client->conversations->v1->services('XXX')->conversations($sid)->messages($messageSid)->fetch();
  3. 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:

shwetha-manvinkurke commented 3 years ago

@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
IllesAprod commented 3 years ago

@shwetha-manvinkurke

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) Screenshot 2021-05-18 at 7 42 31

ááűűúúőőóóüüööíí

With curl i get: Screenshot 2021-05-18 at 7 44 20

{"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?

IllesAprod commented 3 years ago

Hi @shwetha-manvinkurke

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

shwetha-manvinkurke commented 3 years ago

Hi @IllesAprod I suggest reaching out to support and discussing this issue with them.