• Stars
    star
    449
  • Rank 97,328 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿค– A simple bot to translate JSON HTTP requests into Telegram push messages

Telepush

Send Telegram push notifications easily via HTTP


๐Ÿ“„ Description

A simple Telegram Bot to translate POST requests with JSON payload into Telegram push messages. Similar Gotify and ntfy.sh, except without an extra app. Useful for server monitoring, alerting, and anything else.

โŒจ๏ธ How to use?

Step 1: Get a token

Open Telegram, start a chat with the TelepushBot (or your own bot, respectively) and type /start to obtain a recipient token.

Step 2: Send messages

Messages are sent via POST to https://telepush.dev/api/[[inlets/<inlet_name>]|messages]/<recipient>.

RECIPIENT_TONEN=... # The token you received using /start.
curl -XPOST \
     -H 'Content-Type: application/json' \
     -d '{ "text": "*Hello World!* (yes, this is Markdown)" }' \
     "https://telepush.dev/api/messages/${RECIPIENT_TONEN}"

When hosting your own instance, replace the URL respectively.

โœ‰๏ธ Message options

Key Type Description
text* string Actual message in plain text or Markdown format
origin string What will be shown as the sender of your message
type [TEXT, FILE] Message type, i.e. to send text or a file (default: TEXT)
file** base64 Base64-encoded file content
filename** string Name of the file to send
options object Additional options to pass
options.disable_link_previews bool Whether to show previews of links in the chat

* = required for type: TEXT, ** = required for type: FILE

More details to be found here.

๐Ÿƒโ€โ™€๏ธ How to run?

โ˜๏ธ Option 1: telepush.dev

Simply use the official hosted instance. Rate-limited to 240 requests per recipient per day.

๐ŸŒ Option 2: Self-hosted

When hosting your own Telepush instance, you need to create a new bot with @BotFather first. As a result, you will get a token that you then pass to Telepush when starting the server (see below).

๐Ÿณ Option 2.1: With Docker

$ docker volume create telepush_data
$ docker run -d \
    -p 8080:8080 \
    -v telepush_data:/srv/data \
    --name telepush \
    ghcr.io/muety/telepush \
    -mode webhook \
    -token <YOUR_BOTFATHER_TOKEN>

๐Ÿ›  Option 2.2: Compile from source

# Install
$ go install github.com/muety/telepush@latest

# Run (webhook mode)
$ ./telepush -token <YOUR_BOTFATHER_TOKEN> -mode webhook

โ†”๏ธ Webhook vs. long-polling

You can either run the bot in long-polling- or webhook mode (-mode [webhook|poll]). For production use the latter option is recommended for various reasons. However, you'll need a server with a static IP and a TLS certificate.

More details about webhook setup can be found in Marvin's Marvellous Guide to All Things Webhook.

๐Ÿ”“ HTTPS

In webhook mode, Telegram requires your updates endpoint to use HTTPS. To enable such, either run Telepush behind a reverse proxy (like Caddy), that terminates TLS.

Or, let Telepush itself handle TLS. You'll need a certificate for this, so either get one from Let's Encrypt or create a self-signed one, then use -useHttps in combination with -certPath and -keyPath pointed to your certificate and private key files respectively.

For self-signed certificates, you'll need to pass your public key to Telegram's setWebhook method in addition, see these instructions.

๐Ÿ”ง Configuration options

  • -address (string) โ€“ Network address (IPv4) to bind to. Defaults to 127.0.0.1.
  • -address6 (string) โ€“ Network address (IPv6) to bind to. Defaults to ::1.
  • -disableIPv6 (bool) โ€“ Whether to disable listening on both IPv4 and IPv6 interfaces. Defaults to false.
  • -port (int) โ€“ TCP port to listen on. Defaults to 8080.
  • -proxy (string) โ€“ Proxy connection string to be used for long-polling mode. Defaults to none.
  • -urlSecret (string) โ€“ Random suffix to append to your updates route called by Telegram's servers to prevent spam. Defaults to none.
  • -useHttps (bool) โ€“ Whether to use HTTPS. Defaults to false.
  • -certPath (string) โ€“ Path of your SSL certificate when using webhook mode with useHttp. Default to none.
  • -keyPath (string) โ€“ Path of your private SSL key when using webhook mode with useHttp. Default to none.
  • -dataDir (string) โ€“ File system location where to store persistent data. Defaults to ..
  • -blacklist (string) โ€“ Path to a line-separated blacklist file containing user IDs (send /help to get your id). Defaults to blacklist.txt.
  • -whitelist (string) โ€“ Path to a line-separated whitelist file containing user IDs (send /help to get your id). Defaults to whitelist.txt.
  • -rateLimit (int) โ€“ Maximum number of messages to be delivered to each recipient per hour. Defaults to 100.
  • -metrics (bool) โ€“ Whether to expose Prometheus metrics under /metrics. Defaults to false.

When using the Docker image, you can alternatively set most of the above config options via environment variables (passed to docker run using -e), e.g. APP_USE_HTTPS=true, APP_CERT_PATH=/etc/telepush.crt, etc. For details, see entrypoint.sh.

Whitelist vs. Blacklist

(aka. allow-list vs. block-list)

๐Ÿ“ฅ Inlets

Inlets provide a mechanism to pre-process incoming data that comes in a format different from what is normally expected by the bot.

This is especially useful if data is sent by external, third-party applications which you cannot modify.

For instance, you might want to deliver alerts from Prometheus' Alertmanager as Telegram notifications. However, Alertmanager's webhook requests look much different from Telepush's default input format. To still make them fit, you can write an Inlet to massage the data accordingly.

To directly address an inlet, request https://telepush.dev/api/inlets/<inlet_name>. Note that /api/inlets/default is equivalent to /api/messages.

Following inlets are currently available:

Name Description Status
default Simply passes the request through without any changes โœ…
alertmanager Consumes Alertmanager webhook requests โœ…
grafana Consumes Grafana webhook requests โœ…
webmentionio Accepts Webmention.io webhook requests to notify about a new Webmention of one of your articles โœ…
bitbucket Accepts Bitbucket webhook requests to notify about a pipeline status change โณ

Further documentation about the individual inlets is available here.

๐Ÿ“Š Metrics

Fundamental Prometheus metrics are exposed under /metrics, if the -metrics flag gets passed. They include:

  • telepush_messages_total{origin="string", type="string"}
  • telepush_requests_total{success="string"}

๐Ÿž Troubleshooting

Error: panic: template: pattern matches no files: *.tpl.html

When running Telepush as a single executable, you must not use dev mode unless Telepush's source code is located inside the same directory. Make sure to not pass -env dev in this case.

๐Ÿ““ License

MIT @ Ferdinand Mรผtsch

More Repositories

1

wakapi

๐Ÿ“Š A minimalist, self-hosted WakaTime-compatible backend for coding statistics
Go
2,534
star
2

mailwhale

๐Ÿณ A bring-your-own-SMTP-server mail relay with REST API and web UI
Go
245
star
3

mininote

๐Ÿ“” A simple, self-hosted, encrypted Markdown note-taking editor
Vue
225
star
4

anchr

โš“๏ธ Anchr provides you with a toolbox for tiny tasks on the internet, especially bookmark collections
JavaScript
181
star
5

website-watcher

๐Ÿ•ต๏ธโ€โ™€๏ธ Naively watch websites for changes on regular intervals.
Python
54
star
6

telegram-expense-bot

A bot that helps you manage and track your daily expenses.
JavaScript
48
star
7

anchr-android

๐Ÿ“ฑ Android client for Anchr.io link collections, built with Flutter
Dart
43
star
8

telegram-payment-bot

How to create a basic Telegram bot with Payments
JavaScript
42
star
9

telegram-bot-tutorial

How to create a basic Telegram bot
JavaScript
38
star
10

http-server-benchmarks

Some simple benchmarks of different HTTP servers in different languages
Java
27
star
11

http2-serverpush-proxy

A simple standalone reverse proxy that automatically enables server-push for assets related to a HTTP response.
JavaScript
26
star
12

gitcount

A command-line tool to estimate the time spent on a git project, based on a very simple heuristic
Go
25
star
13

safe-browse-url-lookup

A simplified NodeJS wrapper for Google's Safe Browsing API v4 to check whether a URL is malicious or not. See https://developers.google.com/safe-browsing/v4/ for more information.
JavaScript
19
star
14

kitsquid

๐Ÿ™ Alternative course catalog for Karlsruhe Institute of Technology
Go
15
star
15

linkeddata-trivia

Auto-generated trivia questions based on DBPedia data.
JavaScript
15
star
16

hashcode-2018

Solution for Google Hash Code 2018 Qualification Round
Python
14
star
17

tello

Keyboard interface to control a DJI Tello drone with your PC
Go
13
star
18

talkycars-thesis

A Distributed Platform Approach to Cooperative Perception based on Celluar-V2X Communication
Python
10
star
19

telegram-paypalme-bot

A bot that help you easily request money from friends.
JavaScript
9
star
20

go-graphql-sse-example

Basic example application using Go + GraphQL Subscriptions + Server-Sent Events + MongoDB + VueJS
Go
8
star
21

caddy-remote-host

Caddy v2 plugin to match a request's client IP against a host name (similar to remote_ip)
Go
7
star
22

tg-chat-classification

Naive-Bayes based classification of Telegram chat messages.
Python
6
star
23

caddy-pirsch-plugin

A Caddy v2 plugin to track requests in Pirsch analytics
Go
5
star
24

popular-movies-android

Project 1 from Udacity Android Developer Nanodegree
Java
5
star
25

halite-bot-java

My rule-based solution for the Halite AI competition
Java
4
star
26

quiznerd-android

๐Ÿค“ A multiplayer coding quiz game for developers. Challenge your friends, compete in matches and test your skills in various programming languages.
Java
4
star
27

winscp2filezilla

A tool that migrates your saved servers from WinSCP to FileZilla.
Go
4
star
28

kit-lod16-knowledge-panel

Linked Open Data-based knowledge panel built during a seminar at Karlsruhe Institute of Technology
Java
4
star
29

broilerplate

A template project for new Go web backend applications
Go
3
star
30

readme-guestbook

A GitHub action to create a guestbook in your README from repository issues
JavaScript
3
star
31

express-request-limit

Express middleware to limit the request rate to specific routes, based on client IP address.
JavaScript
2
star
32

xyz-reader-android

Project 5 from Udacity Android Developer Nanodegree
Java
2
star
33

muetsch.io

My personal website and blog
Stylus
2
star
34

muety.github.io

HTML
1
star
35

baking-time-android

Project 3 from Udacity Android Developer Nanodegree
Java
1
star
36

hashcode-2021

Google HashCode 2021 Solutions
Java
1
star
37

telegram-bot-sdk

A JavaScript SDK to interact with the Telegram Bot API (https://core.telegram.org/bots/api) from your Node.js application.
JavaScript
1
star
38

operation-go

My solutions to the Operation Go hacking game by gocode.io
Go
1
star
39

srvctl

A mini tool to quickly perform certain actions on a server
PHP
1
star