Bot::ChatBots::Role::Sender - Bot::ChatBots Role for Senders
package Bot::ChatBots::Whatever::Sender; use Moo; with 'Bot::ChatBots::Role::Sender'; with 'Bot::ChatBots::Role::UserAgent; sub send_message { my ($self, $message) = @_; $self->ua_request( GET => 'http://frobozz.example.com/v1/whatever', {Accept => 'application/json'}, json => $message ); } 1;
This is a sender role for bots.
This is what you should provide and probably override in the general case:
"send_message" is mandatory and it is where you actually send messages.
The following methods have a same-named option that can be passed to the constructor.
my $recipient = $obj->recipient; $obj->recipient($some_id);
Accessor for a possible default recipient of messages sent by this sender.
This module composes role Bot::ChatBots::Role::Processor, inheriting all its methods (specifically, "processor" in Bot::ChatBots::Role::Processor).
It should be safe to override the following methods in your classes composing this role.
$obj->clear_recipient;
Remove any default "recipient" currently set.
say 'yes' if $obj->has_recipient;
Predicate function to assess whethere a "recipient" is set or not.
my $output = $obj->process($input);
If $input is a hash reference, look for a send_message key and if it exists call "send_message" with it, recording the outcome in key sent_message.
$input
send_message
sent_message
In any case, the $input is the returned as $output.
$output
This class defines a Moo::Role, so it's not a standalone thing by itself. The following methods are required to exist in the class that composes this role.
$obj->send_message($message, %args);
Do actual sending of a message. This method can leverage on "ua" or "ua_request" to do the actual network traffic.
Bot::ChatBots, Bot::ChatBots::Role::UserAgent.
Flavio Poletti <polettix@cpan.org>
Copyright (C) 2016 by Flavio Poletti <polettix@cpan.org>
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
To install Bot::ChatBots, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bot::ChatBots
CPAN shell
perl -MCPAN -e shell install Bot::ChatBots
For more information on module installation, please visit the detailed CPAN module installation guide.