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 ..
my $sock_file = $ARGV || "./im_socket_file";
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\@example.com MSN This is sent to Chitrangoda via MSN server.".chr(0x1A);
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.