Skip to content

Commit

Permalink
Add option for Telegram to use a thread
Browse files Browse the repository at this point in the history
Signed-off-by: Christiaan de Die le Clercq <[email protected]>
  • Loading branch information
Techwolf12 committed Feb 9, 2024
1 parent 4222fe0 commit 10867d7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions docs/services/telegram.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ metadata:
annotations:
notifications.argoproj.io/subscribe.on-sync-succeeded.telegram: -1000000000000
```

If your private chat contains threads, you can optionally specify a thread id by seperating it with a `|`:
```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
notifications.argoproj.io/subscribe.on-sync-succeeded.telegram: -1000000000000|2
```
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,5 @@ require (
)

replace github.com/prometheus/client_golang => github.com/prometheus/client_golang v1.14.0

replace github.com/go-telegram-bot-api/telegram-bot-api/v5 => github.com/OvyFlash/telegram-bot-api/v5 v5.0.0-20240108230938-63e5c59035bf
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYr
github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA=
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/OvyFlash/telegram-bot-api/v5 v5.0.0-20240108230938-63e5c59035bf h1:a7VKhbjKYPO8twGy/1AxMpM2Fp0qT7bf25fmCVMVu4s=
github.com/OvyFlash/telegram-bot-api/v5 v5.0.0-20240108230938-63e5c59035bf/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/PagerDuty/go-pagerduty v1.7.0 h1:S1NcMKECxT5hJwV4VT+QzeSsSiv4oWl1s2821dUqG/8=
github.com/PagerDuty/go-pagerduty v1.7.0/go.mod h1:PuFyJKRz1liIAH4h5KVXVD18Obpp1ZXRdxHvmGXooro=
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
Expand Down Expand Up @@ -174,8 +176,6 @@ github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
Expand Down
12 changes: 11 additions & 1 deletion pkg/services/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func (s telegramService) Send(notification Notification, dest Destination) error
}

if strings.HasPrefix(dest.Recipient, "-") {
chatID, err := strconv.ParseInt(dest.Recipient, 10, 64)
chatChannel := strings.Split(dest.Recipient, "|")

chatID, err := strconv.ParseInt(chatChannel[0], 10, 64)
if err != nil {
return err
}
Expand All @@ -35,6 +37,14 @@ func (s telegramService) Send(notification Notification, dest Destination) error
msg := tgbotapi.NewMessage(chatID, notification.Message)
msg.ParseMode = "Markdown"

if len(chatChannel) > 1 {
threadID, err := strconv.Atoi(chatChannel[1])
if err != nil {
return err
}
msg.MessageThreadID = threadID
}

_, err = bot.Send(msg)
if err != nil {
return err
Expand Down

0 comments on commit 10867d7

Please sign in to comment.