twilio / twilio-php

A PHP library for communicating with the Twilio REST API and generating TwiML.

Home Page:https://www.twilio.com/docs/libraries/php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

  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();
  1. 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

@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?

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

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