REST API PHP and Cyrillic characters



PhantomBot v2.3.8 | Ubuntu 16.04.2 | Java 1.8.0_131

Hello again devs! Recently was looking into REST API and found this feature to be extremely useful when creating unique interactions on stream. And been using PHP script found on these forums ever since.

There is a problem though. REST API always shows Cyrillic characters in wrong encoding. When you send them in UTF-8, cyrillic characters appear in ISO-8859-1.

My test message is: Фантом - гордость СССР. (Phantom is a pride of USSR)
UTF8 -> Фантом - гордость СССР(ISO-8859-1)
Windows1251 - Ôàíòîì - ãîðäîñòü ÑÑÑÐ

I’ve tried many solutions including setting headers, encoding strings, etc, etc… But unfortunately nothing seems to work, latin characters always render fine in chat, but cyrillic don’t.

Script from @JustAlixe

$url = "";
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, $url);
// set headers
$headers = [
'webauth: my webauth key',
'user: bot user on twitch',
'message: Фантомбот - Гордость советского союза'
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
echo $output;


Or is it possible to get the source for the web server side of phantombot that receives these commands? I’ve got an experienced programmer friend who is willing to help. Thanks devs!


I think you need to encode the message in order for it to send properly?

Read more here:


Fixed, will be in the next Nightly and Stable Build

% curl -X PUT -H "webauth: asdfasdf" -H "user: illusionarybot" -H "message:  Фантом - гордость" http://localhost:27000

[09-17-2017 @ 12:36:51.851 MDT] Фантом - гордость
[09-17-2017 @ 12:36:51.852 MDT] [CHAT] Фантом - гордость

The PUT API now expects ISO_8859_1 as input and translates that to UTF-8 to support that character set. If it turns out that some character sets have issues, will need to look at a different encoding option.


You guys are the best, will check it out soon. Thanks!


You bet, I tested that on macOS, I am hopeful it works under other OSs, I just didn’t have my Windows laptop at the time to check with and didn’t make it over to my Linux development server to double check it.


Just tested it out! Now cyrillic characters render fine, thanks!


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.