Commit 8b47d9b4 authored by Luc Didry's avatar Luc Didry

First commit. Working

Pipeline #6761 skipped
![English:]( **Framasoft uses GitLab** for the development of its free softwares. Our Github repositories are only mirrors.
If you want to work with us, **fork us on [](**. (no registration needed, you can sign in with your Github account)
![Français :]( **Framasoft utilise GitLab** pour le développement de ses logiciels libres. Nos dépôts Github ne sont que des miroirs.
Si vous souhaitez travailler avec nous, **forkez-nous sur [](**. (l'inscription n'est pas nécessaire, vous pouvez vous connecter avec votre compte Github)
* * *
# Giphy Mat Hooker
The `Mat` stand for [Mattermost](
This service allows you to create [slash commands]( on Mattermost to search gifs on <>.
## License
Giphy Mat Hooker is licensed under the terms of the AGPLv3. See the LICENSE file.
# Installation
## Dependencies
* Carton : Perl dependencies manager, it will get what you need, so don't bother for dependencies (but you can read the file `cpanfile` if you want).
sudo cpan Carton
## The real installation
After installing Carton :
git clone
cd giphymathooker
carton install
cp giphy_mat_hooker.conf.template giphy_mat_hooker.conf
vi giphy_mat_hooker.conf
The configuration file is self-documented.
## Usage
### Launch manually
This is good for test, not for production.
carton exec hypnotoad script/giphy_mat_hooker
# stop it
carton exec hypnotoad -s script/giphy_mat_hooker
Yup, that's all, it will listen at "".
For more options (interfaces, user, etc.), change the configuration in `giphy_mat_hooker.conf` (have a look at for the available options).
### Systemd
sudo su
cp utilities/giphymathooker.service /etc/systemd/system/
vi /etc/systemd/system/giphymathooker.service
systemctl daemon-reload
systemctl enable giphymathooker.service
systemctl start giphymathooker.service
## Nginx
You may want to put GHM behind a reverse proxy. Have a look at `utilities/giphymathooker.nginx` for an example.
# How to use in Mattermost?
First, have a look at the [Mattermost documentation about slash commands](
Then, create your slash command, using the URL of your installation (say, choose `GET` or `POST` method, it doesn't matter, GMH will answer to both.
Finally, put the token provided by Mattermost in your GMH configuration file. Or not, if you want anybody to be able to use it if he provides the mattermost parameters.
requires "Mojolicious";
requires "Mojolicious::Plugin::DebugDumperHelper";
# carton snapshot format: version 1.0
pathname: D/DA/DAGOLDEN/CPAN-Meta-2.150005.tar.gz
CPAN::Meta 2.150005
CPAN::Meta::Converter 2.150005
CPAN::Meta::Feature 2.150005
CPAN::Meta::History 2.150005
CPAN::Meta::Merge 2.150005
CPAN::Meta::Prereqs 2.150005
CPAN::Meta::Spec 2.150005
CPAN::Meta::Validator 2.150005
CPAN::Meta::Requirements 2.121
CPAN::Meta::YAML 0.008
Carp 0
ExtUtils::MakeMaker 6.17
JSON::PP 2.27200
Parse::CPAN::Meta 1.4414
Scalar::Util 0
perl 5.008
strict 0
version 0.88
warnings 0
pathname: P/PE/PEVANS/IO-Socket-IP-0.37.tar.gz
IO::Socket::IP 0.37
IO::Socket 0
Socket 1.97
Test::More 0.88
pathname: L/LE/LEONT/Module-Build-0.4218.tar.gz
Module::Build 0.4218
Module::Build::Base 0.4218
Module::Build::Compat 0.4218
Module::Build::Config 0.4218
Module::Build::Cookbook 0.4218
Module::Build::Dumper 0.4218
Module::Build::Notes 0.4218
Module::Build::PPMMaker 0.4218
Module::Build::Platform::Default 0.4218
Module::Build::Platform::MacOS 0.4218
Module::Build::Platform::Unix 0.4218
Module::Build::Platform::VMS 0.4218
Module::Build::Platform::VOS 0.4218
Module::Build::Platform::Windows 0.4218
Module::Build::Platform::aix 0.4218
Module::Build::Platform::cygwin 0.4218
Module::Build::Platform::darwin 0.4218
Module::Build::Platform::os2 0.4218
Module::Build::PodParser 0.4218
CPAN::Meta 2.142060
CPAN::Meta::YAML 0.003
Cwd 0
Data::Dumper 0
ExtUtils::CBuilder 0.27
ExtUtils::Install 0
ExtUtils::Manifest 0
ExtUtils::Mkbootstrap 0
ExtUtils::ParseXS 2.21
File::Basename 0
File::Compare 0
File::Copy 0
File::Find 0
File::Path 0
File::Spec 0.82
File::Temp 0.15
Getopt::Long 0
Module::Metadata 1.000002
Parse::CPAN::Meta 1.4401
Perl::OSType 1
Pod::Man 2.17
TAP::Harness 3.29
Test::More 0.49
Text::Abbrev 0
Text::ParseWords 0
perl 5.006001
version 0.87
pathname: S/SR/SRI/Mojolicious-6.62.tar.gz
Mojo undef
Mojo::Asset undef
Mojo::Asset::File undef
Mojo::Asset::Memory undef
Mojo::Base undef
Mojo::ByteStream undef
Mojo::Cache undef
Mojo::Collection undef
Mojo::Content undef
Mojo::Content::MultiPart undef
Mojo::Content::Single undef
Mojo::Cookie undef
Mojo::Cookie::Request undef
Mojo::Cookie::Response undef
Mojo::DOM undef
Mojo::DOM::CSS undef
Mojo::DOM::HTML undef
Mojo::Date undef
Mojo::EventEmitter undef
Mojo::Exception undef
Mojo::Headers undef
Mojo::HelloWorld undef
Mojo::Home undef
Mojo::IOLoop undef
Mojo::IOLoop::Client undef
Mojo::IOLoop::Delay undef
Mojo::IOLoop::Server undef
Mojo::IOLoop::Stream undef
Mojo::JSON undef
Mojo::JSON::Pointer undef
Mojo::Loader undef
Mojo::Log undef
Mojo::Message undef
Mojo::Message::Request undef
Mojo::Message::Response undef
Mojo::Parameters undef
Mojo::Path undef
Mojo::Reactor undef
Mojo::Reactor::EV undef
Mojo::Reactor::Poll undef
Mojo::Server undef
Mojo::Server::CGI undef
Mojo::Server::Daemon undef
Mojo::Server::Hypnotoad undef
Mojo::Server::Morbo undef
Mojo::Server::PSGI undef
Mojo::Server::PSGI::_IO undef
Mojo::Server::Prefork undef
Mojo::Template undef
Mojo::Transaction undef
Mojo::Transaction::HTTP undef
Mojo::Transaction::WebSocket undef
Mojo::URL undef
Mojo::Upload undef
Mojo::UserAgent undef
Mojo::UserAgent::CookieJar undef
Mojo::UserAgent::Proxy undef
Mojo::UserAgent::Server undef
Mojo::UserAgent::Transactor undef
Mojo::Util undef
Mojo::WebSocket undef
Mojolicious 6.62
Mojolicious::Command undef
Mojolicious::Command::cgi undef
Mojolicious::Command::cpanify undef
Mojolicious::Command::daemon undef
Mojolicious::Command::eval undef
Mojolicious::Command::generate undef
Mojolicious::Command::generate::app undef
Mojolicious::Command::generate::lite_app undef
Mojolicious::Command::generate::makefile undef
Mojolicious::Command::generate::plugin undef
Mojolicious::Command::get undef
Mojolicious::Command::inflate undef
Mojolicious::Command::prefork undef
Mojolicious::Command::psgi undef
Mojolicious::Command::routes undef
Mojolicious::Command::test undef
Mojolicious::Command::version undef
Mojolicious::Commands undef
Mojolicious::Controller undef
Mojolicious::Lite undef
Mojolicious::Plugin undef
Mojolicious::Plugin::Charset undef
Mojolicious::Plugin::Config undef
Mojolicious::Plugin::Config::Sandbox undef
Mojolicious::Plugin::DefaultHelpers undef
Mojolicious::Plugin::EPLRenderer undef
Mojolicious::Plugin::EPRenderer undef
Mojolicious::Plugin::HeaderCondition undef
Mojolicious::Plugin::JSONConfig undef
Mojolicious::Plugin::Mount undef
Mojolicious::Plugin::PODRenderer undef
Mojolicious::Plugin::TagHelpers undef
Mojolicious::Plugins undef
Mojolicious::Renderer undef
Mojolicious::Routes undef
Mojolicious::Routes::Match undef
Mojolicious::Routes::Pattern undef
Mojolicious::Routes::Route undef
Mojolicious::Sessions undef
Mojolicious::Static undef
Mojolicious::Types undef
Mojolicious::Validator undef
Mojolicious::Validator::Validation undef
Test::Mojo undef
ojo undef
ExtUtils::MakeMaker 0
IO::Socket::IP 0.37
JSON::PP 2.27103
Pod::Simple 3.09
Time::Local 1.2
pathname: L/LD/LDIDRY/Mojolicious-Plugin-DebugDumperHelper-0.02.tar.gz
Mojolicious::Plugin::DebugDumperHelper 0.02
ExtUtils::MakeMaker 0
Mojolicious 6.11
# vim:set sw=4 ts=4 sts=4 ft=perl expandtab:
# Hypnotoad settings
# see for a full list of settings
hypnotoad => {
# array of IP addresses and ports you want to listen to
listen => [''],
# Application settings
# Giphy API key.
# The default is the dev key from Giphy, which is rate-limited.
# See to know how to get
# a production API key
#apikey => 'dc6zaTOxFJmzC',
# Mattermost token
# When you create a slash command in mattermost, you get a token.
# Put it here if you want that service to be available to your team
# only.
# If you do not provide a token, it will check for parameters that
# Mattermost usually send with a slash command.
#token => 'something'
package GiphyMatHooker;
use Mojo::Base 'Mojolicious';
use Mojo::Upload;
sub startup {
my $self = shift;
$self->plugin('Config', {
default => {
apikey => 'dc6zaTOxFJmzC',
# Router
my $r = $self->routes;
# Normal route to controller
$r->any('/' => sub {
my $c = shift;
# This is only to check that the request comes (apparently) from mattermost
# I know that I should test the token, but it would prevent other users from
# framateam to use this service
# To enable token authent, just set a token in the configuration file
if ((!defined($c->config('token')) &&
defined($c->param('token')) &&
defined($c->param('channel_id')) &&
defined($c->param('channel_name')) &&
defined($c->param('command')) &&
defined($c->param('team_domain')) &&
defined($c->param('team_id')) &&
defined($c->param('user_id')) &&
defined($c->param('user_name')) &&
|| (defined $c->config('token') && $c->param('token') eq $c->config('token'))
) {
my $text = $c->param('text');
my $url = Mojo::URL->new('');
q => $text,
api_key => $c->config('apikey'),
limit => 25
$c->ua->get($url => sub {
my ($ua, $tx) = @_;
if (my $res = $tx->success) {
json => {
"response_type" => "in_channel",
"text" => $res->json->{data}->[rand(25)]->{images}->{original}->{url}
} else {
<!DOCTYPE html>
<title>Welcome to the Mojolicious real-time web framework!</title>
<h2>Welcome to the Mojolicious real-time web framework!</h2>
This is the static document "public/index.html",
<a href="/">click here</a> to get back to the start.
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/../lib" }
use Mojolicious::Commands;
# Start command line interface for application
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('GiphyMatHooker');
% layout 'default';
% title 'Welcome';
<h2><%= $msg %></h2>
This page was generated from the template "templates/example/welcome.html.ep"
and the layout "templates/layouts/default.html.ep",
<%= link_to 'click here' => url_for %> to reload the page or
<%= link_to 'here' => '/index.html' %> to move forward to a static page. To
learn more, you can also browse through the documentation
<%= link_to 'here' => '/perldoc' %>.
<!DOCTYPE html>
<head><title><%= title %></title></head>
<body><%= content %></body>
upstream giphymathooker {
server {
listen 80;
listen [::]:80;
access_log /var/log/nginx/giphymathooker.access.log;
error_log /var/log/nginx/giphymathooker.error.log;
location / {
proxy_set_header Host $host;
proxy_pass http://giphymathooker;
proxy_redirect http://giphymathooker;
Description=Mattermost giphy search service
ExecStart=/usr/local/bin/carton exec hypnotoad script/giphy_mat_hooker
ExecStop=/usr/local/bin/carton exec hypnotoad -s script/giphy_mat_hooker
ExecReload=/usr/local/bin/carton exec hypnotoad script/giphy_mat_hooker
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment