GithubHelp home page GithubHelp logo

grinnz / webservice-mattermost Goto Github PK

View Code? Open in Web Editor NEW

This project forked from n7st/webservice-mattermost

0.0 1.0 0.0 467 KB

Perl client library for Mattermost

License: MIT License

Perl 100.00%

webservice-mattermost's Introduction

WebService::Mattermost test status

WebService::Mattermost is a suite for interacting with Mattermost chat servers. It includes an API client and a WebSocket gateway.

See individual POD files for details.

Installation

From CPAN

% cpanm WebService::Mattermost

Manual

% git clone [email protected]:n7st/WebService-Mattermost.git
% cd WebService-Mattermost
% dzil listdeps | cpanm
% dzil authordeps | cpanm
% dzil install

API usage

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;

WebSocket gateway usage

Emitted events

Event Purpose
gw_message_no_event A message with no event type was received (ping or unknown event)
gw_ws_started The WebSocket client started
gw_ws_finished The WebSocket client's connection was closed
gw_ws_error An error occurred
gw_message A chat message was received

Extending with Moo or Moose

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. See here for a full list.

Running the test suite

% prove -lv t/**/*.t

License

MIT. See LICENSE.txt.

webservice-mattermost's People

Contributors

n7st avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.