Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
feat: support telegram notifications (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Matyushentsev committed Jan 6, 2021
1 parent 0dd62c9 commit 559df7b
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

### Features

* feat: triggers with multiple conditions and multiple templates per condition
* feat: support `oncePer` trigger property that allows sending notification "once per" app field value (#60)
* feat: add support for proxy settings (#42)
* feat: support self-signed certificates in all HTTP based integrations (#61)
* feat: subscription support specifying message template
* feat: support Telegram notifications (#49)

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Argo CD Notifications continuously monitors Argo CD applications and provides a flexible way to notify
users about important changes in the applications state. The project includes a bundle of useful
built-in triggers and notification templates, integrates with various notification services such as
☑ Slack, ☑ SMTP and plans to support Telegram, Discord, etc.
☑ Slack, ☑ SMTP, ☑ Opsgenie, ☑ Telegram and anything else using custom webhooks.

![demo](./docs/demo.gif)

Expand Down
4 changes: 4 additions & 0 deletions docs/argocd-notifications-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ data:
$opsgenie-team-id: $opsgenie-team-api-key
...
# Telegram
service.telegram: |
token: $telegram-token
# Context holds list of variables that can be referenced in templates
context: |
argocdUrl: https://cd.apps.argoproj.io/
Expand Down
2 changes: 0 additions & 2 deletions docs/bots/overview.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Bot (v0.5)

The optional bot component simplifies managing subscriptions. The end users can use bot commands to manage subscriptions
even if they don't have access to the Kubernetes API and cannot modify annotations.

Expand Down
2 changes: 1 addition & 1 deletion docs/bots/slack-bot.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Slack bot (v0.5)
# Slack bot

The Slack bot leverages [slash commands](https://api.slack.com/interactivity/slash-commands). The bot allows slack users
to view existing channel subscriptions and subscribe or unsubscribe channels.
Expand Down
12 changes: 10 additions & 2 deletions docs/services/grafana.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Grafana

!!! note "Requires version v0.6+"

To be able to create Grafana annotation with argocd-notifications you have to create an [API Key](https://grafana.com/docs/grafana/latest/http_api/auth/#create-api-key) inside your [Grafana](https://grafana.com).

![sample](https://user-images.githubusercontent.com/958983/76374272-1cfe9500-6319-11ea-8477-b62d14ac3c9b.png)
Expand All @@ -23,3 +21,13 @@ data:
apiUrl: https://grafana.example.com/api
apiKey: <grafana-api-key>
```
7. Create subscription for your Grafana integration
```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
subscribe.argocd-notifications.argoproj.io: grafana:tag1|tag2 # list of tags separated with |
```
27 changes: 23 additions & 4 deletions docs/services/telegram.md
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
```
11 changes: 9 additions & 2 deletions docs/services/webhook.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
## Configuration

!!! note "Requires version v0.6+"

The webhook notification service allows sending a generic HTTP request using the templatized request body and URL.
Using Webhook you might trigger a Jenkins job, update Github commit status.

Expand Down Expand Up @@ -41,6 +39,15 @@ data:
body: |
<optional-body-template>
```
3 Create subscription for webhook integration:
```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
notifications.argoproj.io/subscribe.sync-operation-change.<webhook-name>: ""
```
## Examples
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/argoproj/argo-cd v1.8.0
github.com/evanphx/json-patch v4.9.0+incompatible
github.com/ghodss/yaml v1.0.0
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
github.com/golang/mock v1.4.4
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect
github.com/huandu/xstrings v1.3.0 // indirect
Expand All @@ -22,6 +23,7 @@ require (
github.com/slack-go/slack v0.6.6
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.6.1
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
github.com/whilp/git-urls v0.0.0-20191001220047-6db9661140c0
gomodules.xyz/notify v0.1.0
k8s.io/api v0.19.2
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ github.com/go-redis/cache/v8 v8.2.1/go.mod h1:8PFGBZrRqG2nToSHw76mSsozxgSKrn3vsZ
github.com/go-redis/redis/v8 v8.3.2/go.mod h1:jszGxBCez8QA1HWSmQxJO9Y82kNibbUmeYhKWrBejTU=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU=
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM=
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 Expand Up @@ -708,6 +710,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
github.com/thecodeteam/goscaleio v0.1.0/go.mod h1:68sdkZAsK8bvEwBlbQnlLS+xU+hvLYM/iQ8KXej1AwM=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ nav:
- bots/telegram-bot.md
- monitoring.md
- Upgrading:
- upgrading/0.x-1.0.md
- upgrading/0.x-1.0.md
6 changes: 6 additions & 0 deletions pkg/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func NewService(serviceType string, optsData []byte) (NotificationService, error
return nil, err
}
return NewWebhookService(opts), nil
case "telegram":
var opts TelegramOptions
if err := yaml.Unmarshal(optsData, &opts); err != nil {
return nil, err
}
return NewTelegramService(opts), nil
default:
return nil, fmt.Errorf("service type '%s' is not supported", serviceType)
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/services/telegram.go
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
}

0 comments on commit 559df7b

Please sign in to comment.