NURUL FERDOUS

Posts Tagged ‘imified

Recently I made a news bot named news@bot.im AKA newsbot24@yahoo.com with the help of a wrapper class wrote by Hasin Hayder. This cool API has been provided by imified recently to make your application IM enable easily . You may test my bot by sending any instant message to newsbot24@yahoo.com or sending a message from your GTalk. It will grab one of the latest 25 top news from http://www.news.google.com or http://www.bdnews24.com RSS feed. I have set caching time as 1200 so that it can be easily work with very less bandwidth. I used lastRSS class to grab the RSS feed as I am having some freight to use Google feed parser with JSON 😦

You can make one just for FREE from http://www.bot.im All you need is to DOWNLOAD the wrapper class to do it quick. Alternatively you may read the quick and dirty documentation from HERE.

Now lemme reveal the source code I used for my news bot :p

<?php
// include lastRSS
include "lastRSS.php";
include "class.imified.php";
// Set cache dir and cache time limit (1200 seconds)
// (don't forget to chmod cahce dir to 777 to allow writing)
$rss->cache_dir = './temp';
$rss->cache_time = 1200;
$rss->cp = 'UTF-8';
$rss->date_format = 'l';
//initiating bot...
//@param pass your imified user credentials
$im = new ImifiedHelper("YOUR-API-KEY-GIVEN-FROM-IMIFIED","DEVELOPERS-NAME","PASSWORD");
if(!isset($_REQUEST['msg']))
{
    echo "This is a newsbot. You may add it as news@bot.im or newsbot24@yahoo.com";
    die();
}

//callback
$im->setCallback("callback");
function callback($message, $step, $network, $userKey)
{
    global $im;
    $message = strtolower($message);
    if("inews" == $message){
        // Create lastRSS object
        $rss = new lastRSS;
        // Try to load and parse RSS file of Slashdot.org
        $rssurl = 'http://news.google.com/?output=rss';
        $rs = $rss->get($rssurl);
        if ($rs) {
            $i = rand(0,25);
            echo $title = strip_tags(htmlspecialchars_decode($rs['items'][$i]['title']."

"))."
";
            echo $description = strip_tags(htmlspecialchars_decode($rs['items'][$i]['description']))."
";
        }
        else {
            echo "Error: It's not possible to get $rssurl...";
        }
        $im->resetStep();
    }
    elseif("bdnews" == $message){
        // Create lastRSS object
        $rss = new lastRSS;
        $rssurl = 'http://rss.bdnews24.com/rss/english/home/rss.xml';
        $rs = $rss->get($rssurl);
        if ($rs) {
            $i = rand(0,25);
            echo $title = strip_tags(htmlspecialchars_decode($rs['items'][$i]['title']))."
";
            echo $description = strip_tags(htmlspecialchars_decode($rs['items'][$i]['description']))."
";
        }
        else {
            echo "Oops! Looks like Server is Busy! to get ".$rssurl." Give it a try with inews";
        }
    }
    else{
        echo "Please type help to see available commands";
        $im->resetStep();
    }
}
?>

Thanks to hasin bro for your cool wrapper class 🙂

Tags: , ,

I am Nurul Ferdous a Zend Certified Engineer (ZCE), serving at Bangladesh Internet Press Limited (BIPL) as programmer. I am a FOSS advocate and love RnD.

Categories

Me @ LinkedIn

View Nurul Ferdous's profile on LinkedIn

My Photos @ Flickr

00bcd191b03b72a98ce7f120f066f81afa3ebdd7ecec46a6095d55500c10fb8e

MOTEEL HOME PAGE







More Photos

Blog Stats

  • 42,083 [ Vistors ]

My Twitter Updates