This script listens to Gotify messages via WebSocket and forwards them to a Discord webhook.
- Python 3.6 or higher installed on your system
websockets
library installed (install withpip install websockets
)
Clone the repository to your local machine:
git clone https://github.com/yourusername/your-repository.git
cd your-repository
-
Gotify Application Token:
- Replace
your_gotify_token_here
with your Gotify application token inforward_gotify_to_discord.py
. - Example:
GOTIFY_TOKEN = 'your_gotify_token_here'
- Replace
-
Gotify Server URL:
- Replace
your_gotify_server_ip
with the IP address or hostname of your Gotify server. - Example:
GOTIFY_URL = f'ws://your_gotify_server_ip:3000/stream?token={GOTIFY_TOKEN}'
- Replace
- Discord Webhook URL:
- Replace
your_discord_webhook_here
with your Discord webhook URL inforward_gotify_to_discord.py
. - Example:
DISCORD_WEBHOOK_URL = 'https://discord.com/api/webhooks/your_discord_webhook_here'
- Replace
Install the required Python dependencies using pip:
pip install websockets && pip install requests
Run the script to start forwarding Gotify messages to Discord:
python3 forward_gotify_to_discord.py
The script will establish a WebSocket connection to your Gotify server and listen for incoming messages. When a message is received, it will be forwarded to the specified Discord webhook.
- Ensure that your Gotify server is accessible from the machine where you are running the script.
- Monitor the script output for any errors or messages indicating successful forwarding of messages.
If you encounter any issues while setting up or running the script, consider the following steps:
- Check Dependencies: Ensure that Python and the
websockets
library are correctly installed. - Verify Configuration: Double-check the Gotify token, server URL, and Discord webhook URL in
forward_gotify_to_discord.py
. - Review Logs: Check the script output or logs for any error messages or indications of connection issues.
This guide explains how to set up and run your Python script (forward_gotify_to_discord.py
) as a systemd service on Ubuntu. This includes creating a new user, placing the script in /opt/discordforwarder/
, and setting correct permissions.
Create a new system user (forwarduser
) to run the service:
sudo adduser --system --group --disabled-login --home /home/forwarduser forwarduser
This command creates a system user named forwarduser
with a home directory set to /home/forwarduser
.
Create the directory /opt/discordforwarder/
and move your Python script (forward_gotify_to_discord.py
) into it:
sudo mkdir /opt/discordforwarder
sudo mv forward_gotify_to_discord.py /opt/discordforwarder/
Set ownership and permissions for the script and its directory:
sudo chown -R forwarduser:forwarduser /opt/discordforwarder
sudo chmod +x /opt/discordforwarder/forward_gotify_to_discord.py
chown -R forwarduser:forwarduser /opt/discordforwarder
: Recursively change ownership of all files and directories under/opt/discordforwarder
toforwarduser
.chmod +x /opt/discordforwarder/forward_gotify_to_discord.py
: Make the script executable.
Create a systemd service file (forward-gotify-to-discord.service
) in /etc/systemd/system/
:
sudo nano /etc/systemd/system/forward-gotify-to-discord.service
Add the following content to forward-gotify-to-discord.service
:
[Unit]
Description=Gotify to Discord Forwarder
After=network.target
[Service]
User=forwarduser
Group=forwarduser
WorkingDirectory=/opt/discordforwarder
ExecStart=/usr/bin/python3 /opt/discordforwarder/forward_gotify_to_discord.py
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=forward-gotify-to-discord
[Install]
WantedBy=multi-user.target
Save the file (Ctrl + O
in nano, then Enter
) and exit (Ctrl + X
).
Once the service file is created, enable and start the service:
sudo systemctl daemon-reload # Reload systemd to read the new service file
sudo systemctl enable forward-gotify-to-discord # Enable the service to start on boot
sudo systemctl start forward-gotify-to-discord # Start the service now
Check the status of your service to ensure it's running without errors:
sudo systemctl status forward-gotify-to-discord
Look for Active: active (running)
in the output, which indicates that the service is running successfully.
To view logs related to your service:
sudo journalctl -u forward-gotify-to-discord
This command displays logs specific to the forward-gotify-to-discord
service.
- Replace
forward_gotify_to_discord.py
with the actual name of your Python script. - Adjust paths (
WorkingDirectory
andExecStart
) in the.service
file to match your script's location and environment. - Ensure your Python script is executable (
chmod +x
if needed). - This setup ensures that your Python script runs as a service, automatically starting on system boot and managed by
systemd
, providing reliability and ease of management. Adjust configurations as necessary based on specific requirements or system setup.