Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ipwhitelistshaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ func (i *IPWhitelistShaper) sendNotification(message string) {
loweredURL := strings.ToLower(urlStr)
isDiscord := strings.Contains(loweredURL, "discord.com/api/webhooks")
isSlack := strings.Contains(loweredURL, "hooks.slack.com/services")
isTelegram := strings.Contains(loweredURL, "api.telegram.org/bot")

var reqBody *bytes.Buffer
contentType := "application/x-www-form-urlencoded"
Expand All @@ -809,6 +810,21 @@ func (i *IPWhitelistShaper) sendNotification(message string) {
values.Set("payload", string(jsonData))
reqBody = bytes.NewBufferString(values.Encode())

case isTelegram:
payload := map[string]interface{}{
"text": msg,
"link_preview_options": map[string]bool{
"is_disabled": true,
},
}
jsonData, err := json.Marshal(payload)
if err != nil {
fmt.Printf("[%s] ERROR creating Telegram payload: %v\n", pluginName, err)
return
}
reqBody = bytes.NewBuffer(jsonData)
contentType = "application/json"

default:
values := url.Values{}
values.Set("message", msg)
Expand Down
15 changes: 15 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ ipwhitelistshaper:

The plugin automatically detects Discord webhook URLs and formats messages appropriately.

### Telegram Webhook Integration

To use Telegram for notifications:

1. Create a telegram bot and retrieve the api token
2. Find the chat_id of the chat to use
3. Add it to your configuration:

```yaml
ipwhitelistshaper:
notificationURL: "https://api.telegram.org/bot<token>?chat_id=<chat_id>"
```

The plugin automatically detects Telegram api URLs and formats messages appropriately.

### Other Notification Services

For other webhook-based notification services, simply provide the webhook URL:
Expand Down