IM::Engine - The HTTP::Engine of instant messaging


IM-Engine documentation Contained in the IM-Engine distribution.

Index


Code Index:

NAME

Top

IM::Engine - The HTTP::Engine of instant messaging

SYNOPSIS

Top

    IM::Engine->new(
        interface => {
            protocol => 'AIM',
            credentials => {
                screenname => '...',
                password   => '...',
            },
            incoming_callback => sub {
                my $incoming = shift;

                my $message = $incoming->plaintext;
                $message =~ tr[a-zA-Z][n-za-mN-ZA-M];

                return $incoming->reply($message);
            },
        },
    )->run;

DESCRIPTION

Top

IM::Engine abstracts away the details of talking through different IM services. A Jabber bot will be essentially the same as an AIM bot, so IM::Engine facilitates switching between these different services.

It is currently alpha quality with serious features missing and is rife with horrible bugs. I'm releasing it under the "release early, release often" doctrine. Backwards compatibility may be broken in subsequent releases.

In particular, I am likely to move IM::Engine::Interface::AIM, IM::Engine::Interface::Jabber, and IM::Engine::Interface::IRC into their own distributions, since they have their own dependencies.

PROTOCOLS

Top

IM::Engine currently understands the following protocols:

AIM (IM::Engine::Interface::AIM)

Talks AIM using Net::OSCAR:

    IM::Engine->new(
        interface => {
            protocol => 'AIM',
            credentials => {
                screenname => 'foo',
                password   => '...',
            },
        },
        # ...
    );

Jabber (IM::Engine::Interface::Jabber)

Talks XMPP using AnyEvent::XMPP:

    IM::Engine->new(
        interface => {
            protocol => 'Jabber',
            credentials => {
                jid      => 'foo@gchat.com',
                password => '...',
            },
        },
        # ...
    );

IRC (IM::Engine::Interface::IRC)

Talks IRC using AnyEvent::IRC:

    IM::Engine->new(
        interface => {
            protocol => 'IRC',
            credentials => {
                server   => "irc.perl.org",
                port     => 6667,
                channels => ["#moose", "#im-engine"],
                nick     => "Boot",
            },
        },
        # ...
    );

There has been some concern about whether IRC is actually an IM protocol. I certainly consider private messages to be IM-ish. For some bots, joining regular human-infested channels would also make sense. Bots that just respond to chatters (which is most, if not all, of what purl does) make sense outside of the context of IRC, so that is the use case I am targetting.

REPL (IM::Engine::Interface::REPL)

Opens up a shell where every line of input is an IM. Responses will be printed to standard output. Handy for testing.

    IM::Engine->new(
        interface => {
            protocol => 'REPL',
        },
        # ...
    );

CLI (IM::Engine::Interface::CLI)

Pass your IM as command-line arguments. Your response will be printed to standard output. Handy for testing but could also be distributed as a useful script (I want this for Hiveminder's IM interface :))

    IM::Engine->new(
        interface => {
            protocol => 'CLI',
        },
        # ...
    );

AUTHOR

Top

Shawn M Moore, sartak@gmail.com

SEE ALSO

Top

HTTP::Engine

The inspiration for the initial design

IM::Engine::Plugin::Dispatcher

Uses Path::Dispatcher to provide sugary IM dispatch

IM::Engine::Plugin::State

Provides state management methods on IM::Engine::Users

IM::Engine::Plugin::MultiCommand

Allows multiple commands to be run in one IM (builds on IM::Engine::Plugin::Dispatcher)

COPYRIGHT AND LICENSE

Top


IM-Engine documentation Contained in the IM-Engine distribution.

package IM::Engine;
use 5.008001;
use Moose;
use MooseX::StrictConstructor;

use IM::Engine::Interface;

our $VERSION = '0.06';

with 'IM::Engine::HasPlugins';

has interface_args => (
    is       => 'ro',
    isa      => 'HashRef',
    init_arg => 'interface',
    required => 1,
);

has interface => (
    is       => 'ro',
    isa      => 'IM::Engine::Interface',
    handles  => ['run', 'send_message'],
    init_arg => undef,
    builder  => '_build_interface',
    lazy     => 1,
);

sub _build_interface {
    my $self = shift;

    my $interface = $self->interface_args
        or confess "You must provide 'interface' to " . blessed($self) . "->new";

    my $protocol = delete $interface->{protocol}
        or confess "Your IM::Engine::Interface definition must include the 'protocol' key";

    if ($protocol !~ s{^\+}{}) {
        $protocol = join '::', 'IM', 'Engine', 'Interface', $protocol;
    }

    Class::MOP::load_class($protocol);

    return $protocol->new(
        %$interface,
        engine => $self,
    );
}

sub engine { shift }

__PACKAGE__->meta->make_immutable;
no Moose;

1;

__END__