NAME

Bot::ChatBots::Role::Sender - Bot::ChatBots Role for Senders

SYNOPSIS

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;

DESCRIPTION

This is a sender role for bots.

What Should You Provide/Override

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.

ACCESSORS

The following methods have a same-named option that can be passed to the constructor.

recipient

my $recipient = $obj->recipient;
$obj->recipient($some_id);

Accessor for a possible default recipient of messages sent by this sender.

METHODS

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.

clear_recipient

$obj->clear_recipient;

Remove any default "recipient" currently set.

has_recipient

say 'yes' if $obj->has_recipient;

Predicate function to assess whethere a "recipient" is set or not.

process

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.

In any case, the $input is the returned as $output.

REQUIRED METHODS

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.

send_message

$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.

SEE ALSO

Bot::ChatBots, Bot::ChatBots::Role::UserAgent.

AUTHOR

Flavio Poletti <polettix@cpan.org>

COPYRIGHT AND LICENSE

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.