This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support telegram notifications (#145)
- Loading branch information
Alexander Matyushentsev
committed
Jan 6, 2021
1 parent
0dd62c9
commit 559df7b
Showing
13 changed files
with
87 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
# Telegram | ||
|
||
!!! note "Do you need Telegram support? Please consider contributing or thumbs up [feature request](https://github.com/argoproj-labs/argocd-notifications/issues/49)!" | ||
1. Get an API token using [@Botfather](https://t.me/Botfather). | ||
2. Store token in `argocd_notifications-secret` Secret and configure telegram integration | ||
in `argocd-notifications-cm` ConfigMap: | ||
|
||
<!-- markdownlint-disable MD033 --> | ||
<div style="text-align:center"><img src="../../assets/argo.png" /></div> | ||
<!-- markdownlint-enable MD033 --> | ||
```yaml | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: argocd-notifications-cm | ||
data: | ||
service.telegram: | | ||
token: $telegram-token | ||
``` | ||
3. Create new Telegram [channel](https://telegram.org/blog/channels) and add your bot as an administrator. | ||
4. Create subscription for your Telegram integration: | ||
```yaml | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Application | ||
metadata: | ||
annotations: | ||
notifications.argoproj.io/subscribe.on-sync-succeeded.telegram: my_channel | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,4 @@ nav: | |
- bots/telegram-bot.md | ||
- monitoring.md | ||
- Upgrading: | ||
- upgrading/0.x-1.0.md | ||
- upgrading/0.x-1.0.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package services | ||
|
||
import tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" | ||
|
||
type TelegramOptions struct { | ||
Token string `json:"token"` | ||
} | ||
|
||
func NewTelegramService(opts TelegramOptions) NotificationService { | ||
return &telegramService{opts: opts} | ||
} | ||
|
||
type telegramService struct { | ||
opts TelegramOptions | ||
} | ||
|
||
func (s telegramService) Send(notification Notification, dest Destination) error { | ||
bot, err := tgbotapi.NewBotAPI(s.opts.Token) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = bot.Send(tgbotapi.NewMessageToChannel("@"+dest.Recipient, notification.Body)) | ||
return err | ||
} |