Suite for interacting with Mattermost chat servers. Includes API and WebSocket gateways.
See individual POD files for details.
This library supercedes Net::Mattermost::Bot and replaces all functionality.
% cpanm WebService::Mattermost
% git clone ssh://[email protected]:7170/mike/WebService-Mattermost.git
% cd WebService-Mattermost
% dzil listdeps | cpanm
% dzil authordeps | cpanm
% dzil install
Currently, only API version 4 (latest) is supported.
use WebService::Mattermost;
my $mattermost = WebService::Mattermost->new({
authenticate => 1, # Log into Mattermost
debug => 1, # Output some debug-level information via Mojo::Log
username => '[email protected]',
password => 'hunter2',
base_url => 'https://my.mattermost.server.com/api/v4/',
});
# API methods available under:
my $api = $mattermost->api;
Several events are emitted:
gw_ws_started
when the bot opens its WebSocket connection.gw_ws_finished
when the connection closes.gw_ws_error
if an error occurs.gw_message
on a "message" event.- Unless it has no event type attached to it, where
gw_message_no_event
is emitted (this is usually a "ping" response).
The WebSocket gateway can be extended in a Moo or Moose class:
package SomePackage;
use Moo;
extends 'WebService::Mattermost::V4::Client';
# WebService::Mattermost::WS::v4 emits events which can be caught with these
# methods. None of them are required and they all pass two arguments ($self,
# HashRef $args).
sub gw_ws_started {}
sub gw_ws_finished {}
sub gw_message {
my $self = shift;
my $args = shift;
# The message's data is in $args
}
sub gw_ws_error {}
sub gw_message_no_event {}
1;
Or used in a script:
use WebService::Mattermost::V4::Client;
my $bot = WebService::Mattermost::V4::Client->new({
username => 'usernamehere',
password => 'password',
base_url => 'https://mattermost.server.com/api/v4/',
# Optional arguments
debug => 1, # Show extra connection information
ignore_self => 0, # May cause recursion!
reauthentication_interval => 600, # Shorten the reauthentication loop delay
});
$bot->on(gw_message => sub {
my ($bot, $args) = @_;
# $args contains the decoded message content
});
$bot->start(); # Add me last
The available events are the same:
gw_message_no_event
gw_message
gw_ws_error
gw_ws_finished
gw_ws_started
% prove -lv t/**/*.t
MIT. See LICENSE.txt.