NAME
Net::Mattermost::Bot - A base class for Mattermost bots.
VERSION
0.04
SYNOPSIS
Extend Net::Mattermost::Bot
in a Moo
or Moose
package.
my $bot = Local::MyBot->new({
username => 'username here',
password => 'password here',
team_name => 'team name here',
base_url => 'Mattermost server\'s base URL here',
debug => 1, # For extra WebSocket connection information
});
$bot->connect();
package Local::MyBot;
use Moo;
extends 'Net::Mattermost::Bot';
# A message was posted to the channel
sub event_posted {
my $self = shift;
my $args = shift;
# $args contains data from Mattermost
return $self->_post_to_channel({
channel_id => 1234,
message => 'This will be output to channel with ID "1234"',
});
}
1;
API calls can also be made directly to Mattermost using their v4 API (using Furl):
sub event_posted {
my $self = shift;
# Get a list of your team's custom emoticons
my $res = $self->furl->get($self->api_url.'/emoji', $self->headers);
# ...
}
DESCRIPTION
Provides a websocket connection and basic API controls for creating a simple Mattermost bot.
METHODS
This package provides several methods which may be overridden in your own bot.
Each method takes two arguments ($self
and $event
), except event_connected
which only passes $self
.
event_connected()
-
The bot connected to the server.
event_typing()
-
Someone started typing.
event_channel_viewed()
-
Someone viewed the channel.
event_posted()
-
Someone posted to the channel.
event_generic()
-
Generic catch-all for extra events.
SEE ALSO
- https://mojolicious.org/perldoc/Mojo/IOLoop
-
The websocket loop is provided by Mojo::IOLoop.
AUTHOR
Mike Jones email:mike@netsplit.org.uk
COPYRIGHT AND LICENSE
Copyright (c) 2018 Mike Jones
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.