Wednesday, August 6, 2008

Pidgin as instant messaging gateway

Pidgin is the most powerful IM client I have ever seen . This is because of the big community support and also because I am big fan of Mark Spencer :-P .. The libpurple (Pidgin/Finch core) library can be used as IM gateway . I implemented such gateway for event notification . Something like a bot .

It keeps libpurple connected to the IM servers of different protocol and takes message request from UNIX socket . For example the following code will send a message to Chitrangoda ..

#!/usr/bin/perl -w

use strict;
use Socket;

my $sock_file = $ARGV[1] || "./im_socket_file";
my $msg;
die "provide a socket file address" unless $sock_file;

socket(SOCK, PF_UNIX, SOCK_STREAM, 0) || die "socket: $!";
print "connecting ..\n";
connect(SOCK, sockaddr_un($sock_file)) || die "connect: $!";

print "writing ..\n";
$msg = "chitrangoda\ MSN This is sent to Chitrangoda via MSN server.".chr(0x1A);
print "done\n";
close SOCK;

And here is the code with examples pidgin_send_im (please let me know if the link is broken).It works with Pidgin version 2.4.2 and upper (I am not sure about the lower version) ..

Again, there are more than one way to do it. You can use the perl/php bindings or plugins .. I expect you show those howtos in the comments.

No comments: