Bot::ChatBots::Trello::WebHook - Trello updates receiver, web hook


   use Log::Any qw< $log >;
   use Log::Any::Adapter;
   use Mojolicious::Lite;
   plugin 'Bot::ChatBots::Trello' => instances => [
         processor  => \&processor,
         register   => 1,
         token      => $ENV{TOKEN},
         unregister => 0,
         url        => '',
      # more can follow here...
   sub processor { # tube-compliant
      my $record = shift; # ... $record is normalized, by default

      # ... your business logic goes here...
      my $message = 'Howdy!';

      # In a WebHook you're actually processing a HTTP Request from
      # Trello, so you can set a response via Mojolicious
      if (automatic_via_https_response()) { # WebHook only
         $record->{response} = $message;
      elsif (do_it_yourself_via_https_response()) { # WebHook only
         $record->{source}{refs}{controller}->render(text => $message);
         $record->{source}{flags}{rendered} = 1; # if Bot::ChatBot <= 0.006
      elsif (automatic_via_sender()) { # same as LongPoll
         $record->{send_response} = $message;
      elsif (do_it_yourself_via_sender()) { # same as LongPoll
         my $sender = $record->{source}{refs}{sender};
         $sender->send_response($message, record => $record);
      # else nothing is sent back, just a HTTP 204 by default

      return $record; # follow on..


This is an updates receiver and dispatcher for the Trello infrastructure. It connects to Trello's API for webhooks style (i.e. waiting for push messages to arrive), so you need a routable address/port to get the ball rolling.

Strictly speaking, you MUST only provide a "processor" and "url". The latter is used to set a POST route, while the former is what is called whenever a new message arrives through that route.

Initial releases do not provide access back to Trello via the API, so the registration must be carried over in some other way.


This class consumes the following roles, inheriting their accessors:


This class consumes the following roles, inheriting their methods:

The following sections describe the addiitonal ones.


This method is called upon object construction. It takes care to call "install_route" from Bot::ChatBots::Role::WebHook so that you don't have to. It takes care to install both POST and GET routes, to make Trello happy.


   my $obj = Bot::ChatBots::Trello::WebHook->new(%args);

   # mostly used in Mojolicious applications
   plugin 'Bot::ChatBots::Trello' => instances => [ [ 'WebHook', %args ] ];

Create a new instance. Mostly used behind the scenes by Bot::ChatBots::MojoPlugin as in the second example above.

The arguments hash %hash supports the following keys:


all keys from Bot::ChatBots::Role::WebHook


   my $record = $self->normlize_record($input_record);

Perform some normalization on the record to give it a more "general" shape. Which is still in a state of flux, so a look to the code might be helpful.

So far you should find the following keys in the returned record:


a hash reference with the following keys inside:


whatever type the incoming action (notification from Trello) has


whatever is contained in action.display.translationKey


the item type is derived (if possible) from the type, based on whether it ends with Card, List or Board. In this case, the relevant sub-hash from is extracted.


set to point to the same value as update


set to the string unknown until we figure out something better


set to the string trello


   my @updates = $obj->parse_request($req);

Parse the request and extract updates from it. The current Trello WebHook API sends one single update per message. Returns the update.


   my $outcome = $obj->process($record);

Process a record. The main workhorse is inherited from Bot::ChatBots::Role::WebHook, although this wraps around it to add automatic sending of a 200 OK response.

When a response is rendered, $record->{source}{flags}{rendered} is set to 1 (or another integer true value) to signal that rendering already happened (this should prevent the calling function from doing the rendering again).


Bot::ChatBots, Bot::ChatBots::Role::WebHook.


Flavio Poletti <>


Copyright (C) 2016, 2018 by Flavio Poletti <>

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.