SetScroller
From xatwiki
Contents |
[edit] Set a chat scroller message using API
This feature is aimed at advanced users who want to set the chat scroller automatically from their server. e.g. showing tweets, displaying now/next on their radio station.
You can now set a chat scroller message using an API call to xat.
An example use is for a radio station to set the scroller to display information about the current track that is playing.
You can use the API manually via a web page here: http://xat.com/web_gear/chat/SetScroller.php
To set the scroller from another computer do something like this:
http://xat.com/web_gear/chat/SetScroller.php?Message=Welcome%20to%20my%20chat&GroupName=help&GroupPass=fred
or
http://xat.com/web_gear/chat/SetScroller.php?Message=Hello%20all!&id=12345&pw=1234567890
(preferred method)
to get id and pw click on "edit your chat", "extra features" and use the 2 numbers from the URL.
Notes:
you are limited to 1 update every minute.
The above uses the GET HTTP method, POST will also work.
If you reset your chat you will need to update your software to go to the new ID and PW. If you change your group password you'll need to update to use the new pass.
[edit] Example of how to access the API in php
$url = 'http://xat.com/web_gear/chat/SetScroller.php';
$url .= "?Message=".urlencode("Hi there");
$url .= "&id=12345";
$url .= "&pw=1234567890";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
$content = curl_exec ($ch);
print "$content\n";
curl_close ($ch);
[edit] Example to show latest Twitter tweets on xat scroller in php
The script should be run in the background. It connects to the Twitter streaming API and will set the xat scroller to the text of any tweets on the twitter account you specify. A production version would need error handling, e.g. reconnecting if connection lost, handling once per minute limitation
<?php
$username = 'anytwitterusername';
$password = 'anytwitterpassword';
$twitter = 'twitteridtofollow';
$id = 'chatid';
$pw = 'chatpw';
$fp = fopen("http://$username:$password@stream.twitter.com/1/statuses/filter.json?follow=$twitter", 'r');
while($data = fgets($fp))
{
if(strlen($data)>2)
{
$res = json_decode($data, true);
$tweet = $res['text'];
print "twitter: $tweet\n";
$url = 'http://xat.com/web_gear/chat/SetScroller.php';
$url .= "?Message=".urlencode($tweet);
$url .= "&id=$id";
$url .= "&pw=$pw";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
$content = curl_exec ($ch);
print "$content\n";
curl_close ($ch);
}
else
{
print "...\n";
}
}
fclose($fp);
?>
[edit] Links / more information
http://blog.xatworld.com/new-features/xat-setscroller/ another take on SetScroller
