telegram

package
v0.0.0-...-8ef2c1b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	// contains filtered or unexported fields
}

Bot runs the alertmanager telegram

func NewBot

func NewBot(chats BotChatStore, token string, admin int, opts ...BotOption) (*Bot, error)

NewBot creates a Bot with the UserStore and telegram telegram

func (*Bot) Run

func (b *Bot) Run(ctx context.Context, webhooks <-chan notify.WebhookMessage) error

Run the telegram and listen to messages send to the telegram

func (*Bot) SendAdminMessage

func (b *Bot) SendAdminMessage(adminID int, message string)

SendAdminMessage to the admin's ID with a message

type BotChatStore

type BotChatStore interface {
	List() ([]telebot.Chat, error)
	Add(telebot.Chat) error
	Remove(telebot.Chat) error
}

BotChatStore is all the Bot needs to store and read

type BotOption

type BotOption func(b *Bot)

BotOption passed to NewBot to change the default instance

func WithAddr

func WithAddr(addr string) BotOption

WithAddr sets the internal listening addr of the bot's web server receiving webhooks

func WithAlertmanager

func WithAlertmanager(u *url.URL) BotOption

WithAlertmanager sets the connection url for the Alertmanager

func WithExtraAdmins

func WithExtraAdmins(ids ...int) BotOption

WithExtraAdmins allows the specified additional user IDs to issue admin commands to the bot.

func WithLogger

func WithLogger(l log.Logger) BotOption

WithLogger sets the logger for the Bot as an option

func WithRevision

func WithRevision(r string) BotOption

WithRevision is setting the Bot's revision for status commands

func WithStartTime

func WithStartTime(st time.Time) BotOption

WithStartTime is setting the Bot's start time for status commands

func WithTemplates

func WithTemplates(t *template.Template) BotOption

WithTemplates uses Alertmanager template to render messages for Telegram

type ChatStore

type ChatStore struct {
	// contains filtered or unexported fields
}

ChatStore writes the users to a libkv store backend

func NewChatStore

func NewChatStore(kv store.Store) (*ChatStore, error)

NewChatStore stores telegram chats in the provided kv backend

func (*ChatStore) Add

func (s *ChatStore) Add(c telebot.Chat) error

Add a telegram chat to the kv backend

func (*ChatStore) List

func (s *ChatStore) List() ([]telebot.Chat, error)

List all chats saved in the kv backend

func (*ChatStore) Remove

func (s *ChatStore) Remove(c telebot.Chat) error

Remove a telegram chat from the kv backend

type Data

type Data struct {
	Receiver string          `json:"receiver"`
	Status   string          `json:"status"`
	Alerts   template.Alerts `json:"alerts"`

	GroupLabels       template.KV `json:"groupLabels"`
	CommonLabels      template.KV `json:"commonLabels"`
	CommonAnnotations template.KV `json:"commonAnnotations"`
	Data              template.KV `json:"data"`

	ExternalURL string `json:"externalURL"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL