https://github.com/dofusdude/ankama-discord-hooks
API for subscribing Ankama related feed updates to your Discord
https://github.com/dofusdude/ankama-discord-hooks
almanax discord discord-bot dofus webhooks
Last synced: 6 months ago
JSON representation
API for subscribing Ankama related feed updates to your Discord
- Host: GitHub
- URL: https://github.com/dofusdude/ankama-discord-hooks
- Owner: dofusdude
- License: mit
- Created: 2022-10-24T15:38:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-12T13:21:10.000Z (over 1 year ago)
- Last Synced: 2025-02-12T14:38:10.654Z (over 1 year ago)
- Topics: almanax, discord, discord-bot, dofus, webhooks
- Language: Go
- Homepage: https://discord.dofusdude.com
- Size: 308 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ankama Discord Webhooks
[](https://goreportcard.com/report/github.com/dofusdude/ankama-discord-hooks)
[](https://github.com/dofusdude/ankama-discord-hooks/actions/workflows/ci.yml)
[](https://codecov.io/gh/dofusdude/ankama-discord-hooks)
A polling based listener converting multiple Ankama related feed updates to Discord Webhooks.
There is also an official [Website](https://discord.dofusdude.com) for very easy and fast Webhook creation using this API.
The full API documentation can be found integrated in the [Dofusdude Docs](https://docs.dofusdu.de).
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](https://docs.dofusdu.de) 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](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate)
- PostgreSQL 14
- Docker (optional, only used for database in README)
- Go 1.19 (only for building from source)
### From source
```bash
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`.
```ini
[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.
```bash
systemctl enable webhooks
systemctl start webhooks
```
### Docker
The Docker image is available on [Docker Hub](https://hub.docker.com/r/stelzo/ankama-discord-hooks).
```bash
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](https://choosealicense.com/licenses/mit/)