Skip to content

Commit

Permalink
Add Telegram Topic support (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
iranzo authored Feb 13, 2023
1 parent 9557998 commit 99ed163
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 39 deletions.
45 changes: 21 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ when it's done. You can receive messages on your computer or phone.

Noti can send notifications on a number of services.

```
| macOS | Linux | Windows
--------------------------------------
Banner | ✔ | ✔ | ✔
Speech | ✔ | ✔ | ✔
BearyChat | ✔ | ✔ | ✔
Keybase | ✔ | ✔ | ✔
Mattermost | ✔ | ✔ | ✔
Pushbullet | ✔ | ✔ | ✔
Pushover | ✔ | ✔ | ✔
Pushsafer | ✔ | ✔ | ✔
Simplepush | ✔ | ✔ | ✔
Slack | ✔ | ✔ | ✔
Telegram | ✔ | ✔ | ✔
Zulip | ✔ | ✔ | ✔
Twilio | ✔ | ✔ | ✔
GChat | ✔ | ✔ | ✔
```
| Service | macOS | Linux | Windows |
| ---------- | :---: | :---: | :-----: |
| Banner ||||
| Speech ||||
| BearyChat ||||
| Keybase ||||
| Mattermost ||||
| Pushbullet ||||
| Pushover ||||
| Pushsafer ||||
| Simplepush ||||
| Slack ||||
| Telegram ||||
| Zulip ||||
| Twilio ||||
| GChat ||||

Checkout the [screenshots] directory to see what the notifications look like on
different platforms.
Expand Down Expand Up @@ -70,20 +68,20 @@ details, checkout the [docs].

Display a notification when `tar` finishes compressing files.

```
```sh
noti tar -cjf music.tar.bz2 Music/
```

Add `noti` after a command, in case you forgot at the beginning.

```
```sh
clang foo.c -Wall -lm -L/usr/X11R6/lib -lX11 -o bizz; noti
```

If you already started a command, but forgot to use `noti`, then you can do
this to get notified when that process' PID disappears.

```
```sh
noti --pwatch 1234
```

Expand All @@ -103,12 +101,11 @@ $ fg; noti

Additionally, `noti` can send a message piped from stdin with `-`.

```
```sh
$ make test 2>&1 | tail --lines 5 | noti -t "Test Results" -m -
```


[macOS Banner Notification]: https://raw.githubusercontent.com/variadico/noti/main/docs/screenshots/macos_banner.png
[macos banner notification]: https://raw.githubusercontent.com/variadico/noti/main/docs/screenshots/macos_banner.png
[screenshots]: https://github.com/variadico/noti/tree/main/docs/screenshots
[latest release]: https://github.com/variadico/noti/releases/latest
[docs]: https://github.com/variadico/noti/blob/main/docs/noti.md
35 changes: 20 additions & 15 deletions docs/noti.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@ when it's done. You can receive messages on your computer or phone.

Noti can send notifications on a number of services.

```
| macOS | Linux | Windows
--------------------------------------
Banner | ✔ | ✔ | ✔
Speech | ✔ | ✔ | ✔
BearyChat | ✔ | ✔ | ✔
Keybase | ✔ | ✔ | ✔
Pushbullet | ✔ | ✔ | ✔
Pushover | ✔ | ✔ | ✔
Pushsafer | ✔ | ✔ | ✔
Simplepush | ✔ | ✔ | ✔
Slack | ✔ | ✔ | ✔
Twilio | ✔ | ✔ | ✔
GChat | ✔ | ✔ | ✔
```

| Service | macOS | Linux | Windows |
| ---------- | :---: | :---: | :-----: |
| Banner ||||
| Speech ||||
| BearyChat ||||
| Keybase ||||
| Mattermost ||||
| Pushbullet ||||
| Pushover ||||
| Pushsafer ||||
| Simplepush ||||
| Slack ||||
| Telegram ||||
| Zulip ||||
| Twilio ||||
| GChat ||||


## Installation

Expand Down Expand Up @@ -163,6 +166,7 @@ curl -L $(curl -s https://api.github.com/repos/variadico/noti/releases/latest |
* `NOTI_TWILIO_AUTHTOKEN`
* `NOTI_TELEGRAM_CHATID`
* `NOTI_TELEGRAM_TOKEN`
* `NOTI_TELEGRAM_TOPIC`
* `NOTI_GCHAT_APPURL`
* `NOTI_GCHAT_TEMPLATE`

Expand Down Expand Up @@ -374,6 +378,7 @@ slack:
telegram:
token: 1234567890abcdefg
chatId: '@notifier'
topic: 12345
twilio:
numberto: +972542877978
numberfrom: +18111119711
Expand Down
1 change: 1 addition & 0 deletions internal/command/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func getTelegram(title, message string, v *viper.Viper) notification {
return &telegram.Notification{
ChatID: v.GetString("telegram.chatId"),
Token: v.GetString("telegram.token"),
Topic: v.GetString("telegram.topic"),
Message: fmt.Sprintf("<b>%s %s</b>\n%s", html.EscapeString(title), "🚀:", message),

Client: httpClient,
Expand Down
2 changes: 2 additions & 0 deletions internal/command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var baseDefaults = map[string]interface{}{

"telegram.chatId": "",
"telegram.token": "",
"telegram.topic": "",

"zulip.key": "",
"zulip.botAddress": "",
Expand Down Expand Up @@ -129,6 +130,7 @@ var keyEnvBindings = map[string]string{

"telegram.chatId": "NOTI_TELEGRAM_CHATID",
"telegram.token": "NOTI_TELEGRAM_TOKEN",
"telegram.topic": "NOTI_TELEGRAM_TOPIC",

"zulip.key": "NOTI_ZULIP_KEY",
"zulip.botAddress": "NOTI_ZULIP_BOTADDRESS",
Expand Down
1 change: 1 addition & 0 deletions service/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type apiResponse struct {
// Notification is a Telegram notification.
type Notification struct {
ChatID string `json:"chat_id"`
Topic string `json:"message_thread_id"`
Message string `json:"text"`
Token string `json:"-"`
Client *http.Client `json:"-"`
Expand Down

0 comments on commit 99ed163

Please sign in to comment.