Skip to content

Commit 6b714f1

Browse files
committed
feat: support more channels
1 parent 301e9e9 commit 6b714f1

File tree

5 files changed

+298
-118
lines changed

5 files changed

+298
-118
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
go-version: [1.22.x]
19+
os: [ubuntu-latest]
20+
21+
steps:
22+
- name: Checkout source code
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: ${{ matrix.go-version }}
29+
30+
- name: Install required tools
31+
run: |
32+
go install github.com/gotify/plugin-api/cmd/gomod-cap@latest
33+
34+
- name: Build the plugin
35+
run: |
36+
make build
37+
38+
- name: Upload build artifacts
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: telegram-plugin
42+
path: build/*.so

README.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This Gotify plugin forwards all received messages to Telegram through the Telegr
1616

1717
4. Restart gotify.
1818

19+
5. Config the plugin.
20+
1921
* **Build from source**
2022

2123
1. Change GOTIFY_VERSION in Makefile.
@@ -28,21 +30,40 @@ This Gotify plugin forwards all received messages to Telegram through the Telegr
2830
2931
3. Follow instructions from step 2 in the shared object installation.
3032
33+
## Configuration
34+
35+
The configuration contains three keys: `clients`, `gotify_host` and `token`.
36+
37+
### Clients
38+
39+
The `clients` configuration key describes which client(channel?) we are going to listen on and which telegram channel (and topic optionally!) we are forwarding the message to.
40+
41+
```yaml
42+
clients:
43+
- app_id: "The Gotify App ID to be matched. use -1 for all-matching."
44+
telegram:
45+
chat_id: "ID of the telegram chat"
46+
token: "The bot token"
47+
thread_id: "Thread ID of the telegram topic. Leave it empty if we are not sending to a topic."
48+
- app_id: "Maybe the second Gotify Client Token, yay!"
49+
telegram:
50+
chat_id: "ID of the telegram chat"
51+
token: "The bot token"
52+
thread_id: "Thread ID of the telegram topic. Leave it empty if we are not sending to a topic."
53+
```
54+
55+
### Gotify Host
56+
57+
The `gotify_host` configuration key should be set to `ws://YOUR_GOTIFY_IP` (depending on your setup, `ws://localhost:80` will likely work by default)
58+
59+
### Token
60+
61+
The `token` configuration key should be set to a valid token that can be created in the "Clients" tab.
62+
3163
## Troubleshooting
3264
1. When only the Gotify dashboard receives your message, but not Telegram:
3365

3466
If, when making the API call to get your bot's chat ID, no data is returned, you may need to change the bot's privacy settings.
3567

3668
- In the BotFather chat, list your created bots and select the respective bot for which you want to change the Group Privacy setting.
3769
- Turn off the Group Privacy setting.
38-
39-
## Appendix
40-
Mandatory secrets.
41-
42-
```(shell)
43-
GOTIFY_HOST=ws://YOUR_GOTIFY_IP (depending on your setup, "ws://localhost:80" will likely work by default)
44-
GOTIFY_CLIENT_TOKEN=YOUR_CLIENT_TOKEN (create a new Client in Gotify and use the Token from there, or you can use an existing client)
45-
TELEGRAM_CHAT_ID=YOUR_TELEGRAM_CHAT_ID (conversation ID from the Telegram API call above)
46-
TELEGRAM_BOT_TOKEN=YOUR_TELEGRAM_BOT_TOKEN (API token provided by BotFather)
47-
```
48-

config.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
type Telegram struct {
8+
ChatId string `yaml:"chat_id"`
9+
BotToken string `yaml:"token"`
10+
ThreadId string `yaml:"thread_id"`
11+
}
12+
13+
type SubClient struct {
14+
AppId int `yaml:"app_id"`
15+
Telegram Telegram `yaml:"telegram"`
16+
}
17+
18+
// Config is user plugin configuration
19+
type Config struct {
20+
Clients []SubClient `yaml:"clients"`
21+
GotifyHost string `yaml:"gotify_host"`
22+
GotifyClientToken string `yaml:"token"`
23+
}
24+
25+
// DefaultConfig implements plugin.Configurer
26+
func (c *Plugin) DefaultConfig() interface{} {
27+
return &Config{
28+
Clients: []SubClient{
29+
SubClient{
30+
AppId: 0,
31+
Telegram: Telegram{
32+
ChatId: "-100123456789",
33+
BotToken: "YourBotTokenHere",
34+
ThreadId: "OptionalThreadIdHere",
35+
},
36+
},
37+
},
38+
GotifyHost: "ws://localhost:80",
39+
GotifyClientToken: "ExampleToken",
40+
}
41+
}
42+
43+
// ValidateAndSetConfig implements plugin.Configurer
44+
func (c *Plugin) ValidateAndSetConfig(config interface{}) error {
45+
newConfig := config.(*Config)
46+
47+
if newConfig.GotifyClientToken == "ExampleToken" {
48+
return fmt.Errorf("gotify client token is required")
49+
}
50+
for i, client := range newConfig.Clients {
51+
if client.AppId == 0 {
52+
return fmt.Errorf("gotify app id is required for client %d", i)
53+
}
54+
if client.Telegram.BotToken == "" {
55+
return fmt.Errorf("telegram bot token is required for client %d", i)
56+
}
57+
if client.Telegram.ChatId == "" {
58+
return fmt.Errorf("telegram chat id is required for client %d", i)
59+
}
60+
}
61+
62+
c.config = newConfig
63+
return nil
64+
}

0 commit comments

Comments
 (0)