Skip to content

dofusdude/ankama-discord-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ankama Discord Webhooks

Report card integration codecov

A polling based listener converting multiple Ankama related feed updates to Discord Webhooks.

There is also an official Website for very easy and fast Webhook creation using this API.

The full API documentation can be found integrated in the Dofusdude Docs.

With the integration into the Dofusdude API, there are also SDKs ready to use, so you don't need to write the API function mappings and types yourself. You can find them at the docs.

How it works

The server polls the Twitter API and RSS feeds and checks whether new content is available. If so, it sends a POST request to the configured URLs.

The Almanax listeners wait until a subscribed Webhook time is set to fire. Then it uses the Dofusdude API to get the Almanax data and sends a custom request defined by personal settings to the registered URLs.

Public CRUD safety

The URLs include keys to a channel with write access. This API is meant to be public but leaking the URLs would be a security issue. To replace them, there are random IDs that should be kept secret or only shown to the user. With the IDs, the user can update or delete the Webhook but can't retrieve the URL.

Adding feeds

For the official instance I don't want to spam every imaginable Twitter account or RSS feed. So I only added the ones I think are interesting for everyone. If you want to add a feed, just open an issue or a PR.

I won't allow adding feeds programmatically to the public API. If you read the database code, you'll see the official flag. This could be a way to add feeds via the API in the future, but it definitely will be with authentication and authorization.

Preventing abuse

The official instance has an IP based rate limit of 1 request/second with a burst of 5.

It only allows Discord Webhooks to be used as target. Otherwise, it would basically become a DDoS service. In the future, I want to add custom targets but (again) only with authentication and authorization. Because of this (and I don't want Discord to be the default), the json field format must be set to 'discord' on creation. This way, the schema stays flexible for the future.

Self-hosting

You can easily self-host this service, but you should be mindful of the URLs. Always see them as plain-text passwords saved in a database. So never serve unprotected endpoints to the public.

Tools

  • golang-migrate
  • PostgreSQL 14
  • Docker (optional, only used for database in README)
  • Go 1.19 (only for building from source)

From source

cd $GOPATH/src
mkdir -p github.com/dofusdude && cd github.com/dofusdude
git clone git@github.com:dofusdude/ankama-discord-hooks.git && cd ankama-discord-hooks

# create a .env file
cp .env.example .env

# export .env to shell
set -o allexport
source .env
set +o allexport

# setup database
docker run --rm --name webhooks-postgres --env-file .env -p 5432:5432 -d postgres:14-alpine
make migrate-up

go test -cover
go run .

# cleanup database
docker stop webhooks-postgres

Binary

Check the Releases tab and download the latest version of the binary for your platform.

Create a PostgreSQL database and run the migrations (like above).

Set the environment variables as described in the .env.example file or override ENV_DIR to a directory with an .env file (no trailing slash) and run the binary.

For running the binary in the background as a service, you can use systemd:

Create a service file, for example /etc/systemd/system/webhooks.service.

[Unit]
Description=Webhooks Server

[Service]
ExecStart=/bin/ankama-discord-hooks
User=dofusdude

Environment=ENV_DIR=/home/dofusdude/ankama-discord-hooks

[Install]
WantedBy=multi-user.target

Then enable and start the service.

systemctl enable webhooks
systemctl start webhooks

Docker

The Docker image is available on Docker Hub.

docker-compose up -d db

# wait a few seconds for the database to run migrations and get ready.

docker-compose up -d webhooks

License

MIT