Simple Flask API returning meugnons links (courtesy of Imgur) to setup a Mattermost Slash command.
- Generate an Imgur client ID (you need an account) here: https://api.imgur.com/oauth2/addclient
- (optional) Generate a Mattermost token when registering your Slash command.
- Run using Docker, in standalone mode or with docker-compose if you want to start a local Mattermost instance.
- Build and run API:
$ docker build -t meugnon-api .
$ docker run -e IMGUR_CLIENT_ID=<your-token> -p 8000 meugnon-api
$ curl localhost:8000/healthz
{
"message": "Tutto bene!"
}
- Create a
.envfile with the Mattermost tokens and the Imgur client ID as described in.env.template(if theMATTERMOST_TOKENSis empty or not set, token validation will be skipped) - Install required Python dependencies with a tool such as
virtualenv:
$ virtualenv ./venv -p python3.8
$ source venv/bin/active
$ pip install -r requirements.txt
- Run and test API is up
$ python run.py
$ curl localhost:8000/healthz
{
"message": "Tutto bene!"
}
$ curl localhost:8000
{
"response_type": "in_channel",
"text": "https://i.imgur.com/DPVf0HB.jpg"
}
Based on https://github.com/mattermost/mattermost-bot-sample-golang
- Start containers with
docker-compose up. - Run script to add users with
./add_users.sh. - Go to your local Mattermost instance on http://localhost:8065 and log in with
bill@example.com/Password1.. - Create a test team and authorize untrusted connections to your API by going to
System console > Environment > Developerand addingmeugnon-api_meugnon_1inAllow untrusted internal connections to. - Enable link preview to easily get your meugnonnerie in
System Console > Site Configuration > Posts > Enable website link previews. - Create your Slash command on
Integrations > Slash Commands > Add Slash Commandsand set request method toGET, and request URL tohttp://meugnon-api_meugnon_1:8000(rest is your choice).
- Tests
- Filter out MP4 links (not previewed in Mattermost :( )
- Build "cache" object with links to avoid useless calls to API