This article provides a brief overview of how to set up a Mattermost chatbot in Perl 5.
WebService::Mattermost is an alternative Mattermost chatbot library written in Perl. It provides two interfaces to the Mattermost API and WebSocket gateway: from a script, and as a base for Moo and Moose classes. In this article, I will cover how to use it in a basic script, and demonstrate with a bot which greets users.
Installable from CPAN:
For anyone who doesn’t want to read, here is the final product. You will need to
change the authentication values in the constructor for
to your own Mattermost server and bot user.
- First, as with all good Perl scripts, we need to enable strictures and warnings.
- Then, we instantiate the bot class with three required configuration values:
- Next, we add a non-blocking loop which watches for messages from the gateway.
- Received messages include two arguments:
$bot, which contains our instance of
$args, which contains the message from the gateway.
- Finally, we start the bot.
In the bot’s event loops, there are some additional utilites, accessible through