views:

745

answers:

4

I had an idea that would require me be able to send and receive messages via the standard messenger protocols such as msn, icq, aim, skype, etc...

I am currently only familiar with PHP and Python and would thus enjoy a library which I can access from said languages. I have found phurple (http://sourceforge.net/projects/phurple/) for php and python-purple (http://developer.pidgin.im/wiki/PythonHowTo) which don't seem to be to up to date. What would you guys suggest to do? My goal will be to write a webapplication in a distant way like meebo.com

The answer should include a tutorial or example implementation and a decent documentations.. the pidgin.im doesn't really have a useful tutorial..

alternativly you can also just tell me different kinds of implementations, so that I would build my own class out of an existing icq, aim, msn etc implementation.

An example of how to connect to an account (login) and then sending one message would be the ultimate help!

Come one guys :)

+2  A: 

A good bet would be to go through the DBus interface: Pidgin (purple) fully supports it and the DBus interface library for Python is quite stable.

jldupont
Do you know of any good tutorial?
Thomaschaaf
@thomaschaaf: unfortunately not. Sorry.
jldupont
+9  A: 

Here is how to connect to the Pidgin DBus server.

#!/usr/bin/env python
import dbus

bus = dbus.SessionBus()

if "im.pidgin.purple.PurpleService" in bus.list_names():
    purple = bus.get_object("im.pidgin.purple.PurpleService",
            "/im/pidgin/purple/PurpleObject",
            "im.pidgin.purple.PurpleInterface")

    print "Connected to the pidgin DBus."
    for conv in purple.PurpleGetIms():
        purple.PurpleConvImSend(purple.PurpleConvIm(conv), "Ignore this message.")

else:
    print "Could not find piding DBus service, make sure Pidgin is running."

Don't know if you have seen this, but here is the official python DBus tutorial: link.

EDIT: Re-adding link to the pidgin dev wiki. It teaches you everything I posted above, just scroll further down the page. http://developer.pidgin.im/wiki/PythonHowTo

DoR
This is one of the worst documentations I have seen in a long time.. why is there no example of how to connect?!
Thomaschaaf
I added a code example showing how to connect.
DoR
Perhaps a few samples of how to send messages might be good too?
Omnifarious
The examples on how to connect to an account and then how to send one message would be the best documentation I could have found but this is a nice step actually seeing code :)
Thomaschaaf
A: 

Hi,

I use WebIcqLite: ICQ messages sender for the ICQ protocol. It works and the class is easy to understand. I don't know about other protocols, though. What's wrong with the Phurple library?

dusoft
+1  A: 

If you decompress the file from phurple you get some example like this:

<?php
  if(!extension_loaded('phurple')) {
  dl('phurple.' . PHP_SHLIB_SUFFIX);
  }

  class CustomPhurpleClient extends PhurpleClient {
    private $someVar;
    protected function initInternal() {
     $this->someVar = "Hello World";
    }

    protected function writeIM($conversation, $buddy, $message, $flags, $time) {
     if(PhurpleClient::MESSAGE_RECV == $flags) {
      printf( "(%s) %s %s: %s\n",
         $conversation->getName() ? $conversation->getName() : $buddy->getName(),
         date("H:i:s", $time),
         is_object($buddy) ? $buddy->getAlias() : $buddy,
         $message
       );
     }
    }

    protected function onSignedOn($connection) {
     print $this->justForFun($this->someVar);
    }

    public function justForFun($param) {
     return "just for fun, the param is: $param";
    }
  } 
  // end Class CustomPhurpleClient

  // Example Code Below:
  try {
    $user_dir = "/tmp/phphurple-test";
    if(!file_exists($user_dir) || !is_dir($user_dir)) {
     mkdir($user_dir);
    }

    PhurpleClient::setUserDir($user_dir);
    PhurpleClient::setDebug(true);
    PhurpleClient::setUiId("TestUI");

    $client = CustomPhurpleClient::getInstance();
    $client->addAccount("msn://[email protected]:[email protected]:1863");
    $client->connect();

    $client->runLoop();
  } catch (Exception $e) {
    echo "[Phurple]: " . $e->getMessage() . "\n";
    die();
  }
?>
fernyb