Archived
1
0
Fork 0

Add Telegram Messenger notifications

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-03-23 18:12:44 +01:00
commit 0a9ae46d19
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7
11 changed files with 255 additions and 39 deletions

View file

@ -9,6 +9,7 @@ import (
// Config to store JSON configuration
type Config struct {
TwitterConfig `json:"twitter"`
TelegramConfig `json:"telegram"`
URLs []string `json:"urls"`
IncludeRegex string `json:"include_regex"`
ExcludeRegex string `json:"exclude_regex"`
@ -24,6 +25,13 @@ type TwitterConfig struct {
Hashtags []map[string]string `json:"hashtags"`
}
// TelegramConfig to store Telegram API key
type TelegramConfig struct {
Token string `json:"token"`
ChatID int64 `json:"chat_id"`
ChannelName string `json:"channel_name"`
}
// NewConfig creates a Config struct
func NewConfig() *Config {
return &Config{}
@ -52,3 +60,8 @@ func (c *Config) Read(file string) error {
func (c *Config) HasTwitter() bool {
return (c.TwitterConfig.AccessToken != "" && c.TwitterConfig.AccessTokenSecret != "" && c.TwitterConfig.ConsumerKey != "" && c.TwitterConfig.ConsumerSecret != "")
}
// HasTelegram returns true when Telegram has been configured
func (c *Config) HasTelegram() bool {
return c.TelegramConfig.Token != "" && (c.TelegramConfig.ChatID != 0 || c.TelegramConfig.ChannelName != "")
}