Add Telegram Messenger notifications
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
e67ab63ca8
commit
0a9ae46d19
11 changed files with 255 additions and 39 deletions
13
config.go
13
config.go
|
|
@ -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 != "")
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue