REST API PHP and Cyrillic characters

cyrillic
encoding
phantombot

#1

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

<?php
$url = "http://myserver.de:25000/";
// 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
curl_close($ch);
echo $output;
?>

#2

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!


#3

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

Read more here:


#4

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] Фантом - гордость

https://github.com/PhantomBot/PhantomBot/pull/1673

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.


#5

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


#6

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.


#7

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


#8

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