Send and receive messages via (libpurple) messenger protocols

3.6k views Asked by At

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 :)

4

There are 4 answers

3
Isaiah On BEST ANSWER

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

1
jldupont On

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.

0
dusoft On

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?

0
fernyb On

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();
  }
?>