NAME

Telegram::Bot::Brain - A base class to make your very own Telegram bot

VERSION

version 0.003

SYNOPSIS

package MyApp::Coolbot;

use Mojo::Base 'Telegram::Bot::Brain';

has token       => 'token-you-got-from-@botfather';

sub init {
    my $self = shift;
    $self->add_repeating_task(600, \&timed_task);
    $self->add_listener(\&criteria, \&response);
}

Elsewhere....

my $bot = MyApp::Coolbot->new();
$bot->think;  # this will block unless there is already an event
              # loop running

DESCRIPTION

This base class makes it easy to create your own Bot classes that interface with the Telegram Bot API.

Internally it uses the Mojo::IOLoop event loop to provide non-blocking access to the Bot API, allowing your bot to listen for events via the longpoll getUpdates API method and also trigger timed events that can run without blocking.

METHODS

add_repeating_task

This method will add a sub to run every $seconds seconds.

add_listener

Respond to messages we receive. It takes two arguments

  • a CODEREF to be executed to evaluate if we should respond to this message

  • a CODEREF to be executed if the previous criteria was true

Each CODEREF is passed two arguments, this Telegram::Bot::Brain object, and the Telegram::Bot::Message object, the message that was sent to us.

send_message_to_chat_id

Send a text message to a chat_id (group or individual).

SEE ALSO

AUTHOR

Justin Hawkins <justin@eatmorecode.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Justin Hawkins.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 191:

'=end' without a target?