Skip to content

Forward ntfy.sh Push Messages πŸš€ to Telegram by using telegram bot and Websocket πŸ›Έ

License

Notifications You must be signed in to change notification settings

sanwebinfo/ntfy-sh-listener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NTFY Listener πŸš€

docker-image

ntfy.sh to Telegram forwarder

Forward ntfy.sh Push Messages πŸš€ to Telegram by using telegram bot and websocket πŸ›Έ

using ntfy.sh websocket to Listen the ntfy.sh topic Push Notifications via websocket Connection and Forward it to Telegram via bot.

API

Ntfy.sh websocket API - https://docs.ntfy.sh/subscribe/api/?h=websoc#websockets

Setup

  • Download or Clone the Repo via git
git clone https://github.com/sanwebinfo/ntfy-sh-listener
cd ntfy-sh-listener

## install packages
pip install -r requirements.txt
touch .env
  • Env File .env
  • Replace ntfy.sh/ with your push server URL
NTFY_WS = "ntfy.sh/"
NTFY_TOPIC ="<YOUR TOPIC>"
TELEGRAM_BOT = "https://api.telegram.org/bot<YOUR BOT API TOKEN>/sendMessage"
TELEGRAM_ID = "<CHAT ID>"
  • Test
python3 ntfy.py

Docker 🐬

Keep Running the Python Script in Docker

  • Update the .dockerfile before build - Replace example ENV with yours
FROM python:3.8.10
ENV PYTHONUNBUFFERED 1
RUN pip install --upgrade pip
RUN pip3 install requests python-dotenv websocket-client
ENV NTFY_WS = "ntfy.sh/"
ENV NTFY_TOPIC ="<YOUR TOPIC>"
ENV TELEGRAM_BOT = "https://api.telegram.org/bot<YOUR BOT API TOKEN>/sendMessage"
ENV TELEGRAM_ID = "<CHAT ID>"
COPY ntfy.py /usr/bin
CMD ["python3", "/usr/bin/ntfy.py"]
## Build image
docker build . -t="ntfy-sh-listener"

## List the image
docker image ls

## Create and Test Container
docker run -d --name ntfysh ntfy-sh-listener
docker container ps
docker stop (containerID)

## Run the container forever
docker run -d --restart=always --name ntfysh ntfy-sh-listener

## List Hidden container if error exists
docker ps -a

## other commands
docker logs (containerID)
docker stop (containerID)
docker rm (containerid)
docker docker rmi (imageid)
docker image prune
docker builder prune --all -f
docker system prune --all
docker rm $(docker ps -all -q)
docker rmi $(docker image ls -q)

Inspiration

Pushtify (Gotify to Pushover forwarder) - https://github.com/sebw/pushtify

LICENSE

MIT