August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)

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)),
             TextDisplayer()
             ).run()