April 2024 - This site, and Kamaelia are being updated. There is significant work needed, and PRs are welcome.

Cookbook: AIMHarness

Sending and receiving messages over AIM is easy. AIMHarness only deals with four kinds of messages: outgoing IMs, incoming IMs, buddy online notifications, and error notifications. The first kind it receives in its inbox, and the other three are sent out through its outbox.

      NOTIFICATION                                         EVENT
                ("buddy online", {buddy information})                A buddy comes online
                ("message", sender, message text)                    An instant message arrives for you
                ("error", error message)                             An error occurs during the first stage of login

A simple, one-buddy AIM client using Pygame

def sendTo(recipient, text):
    return ("message", recipient, text)

def outformat(data, buddyname):
    if data[0] == "buddy online" and data[1]["name"] ==  buddyname:
        return "%s is online" % buddyname
    elif data[0] == "message" and data[1] == buddyname:
        return "%s: %s" % (buddyname, data[2])
    elif data[0] == "error":
        ": ".join(data)

def SimpleAIMClient(screenname, password, buddyname):
    Pipeline(Textbox(position=(0, 400)),
             PureTransformer(lambda text: sendTo(buddyname, text)),
             AIMHarness(screenname, password),
             PureTransformer(lambda tup: outformat(tup, buddyname)),