messenger

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CalendarAPILimit    = 5 // 5 req/s per user
	CalendarWindow      = 1 * time.Second
	CalendarMinDelay    = CalendarWindow / CalendarAPILimit
	CalendarMaxResults  = 100
	CalendarCredentials = "assets/calendar_credentials.json" // embedded Google Calendar credentials file

)
View Source
const (
	DiscordAPILimit = 50 // 50 API req/s per user/IP
	DiscordWindow   = 1 * time.Second
	DiscordMinDelay = DiscordWindow / DiscordAPILimit
)
View Source
const (
	MailSendLimit = 20 // 20 emails per 1 hour
	MailWindow    = 1 * time.Hour
	MailMinDelay  = MailWindow / MailSendLimit
	MailSubject   = "Nova ocjena iz e-Dnevnika"
)
View Source
const (
	SlackAPILImit = 1 // typically 1 req/s per user
	SlackWindow   = 1 * time.Second
	SlackMinDelay = SlackWindow / SlackAPILImit
)
View Source
const (
	TelegramAPILimit = 30 // 30 API req/s per user
	TelegramWindow   = 1 * time.Second
	TelegramMinDelay = TelegramWindow / TelegramAPILimit
)

Variables

View Source
var (
	ErrCalendarReadingCreds = errors.New("unable to read credentials file")
	ErrCalendarParsingCreds = errors.New("unable to parse credentials file")
	ErrCalendarNotFound     = errors.New("unable to find Google Calendar ID")
)
View Source
var (
	ErrDiscordEmptyAPIKey     = errors.New("empty Discord API key")
	ErrDiscordEmptyUserIds    = errors.New("empty list of Discord User IDs")
	ErrDiscordCreatingSession = errors.New("error creating Discord session")
	ErrDiscordCreatingChannel = errors.New("error creating Discord channel")
	ErrDiscordSendingMessage  = errors.New("error sending Discord message")
)
View Source
var (
	ErrMailSendingMessage = errors.New("error sending mail message")
	ErrMailInvalidPort    = errors.New("invalid or missing SMTP port, will try with default 587/tcp")
)
View Source
var (
	ErrSlackEmptyAPIKey    = errors.New("empty Slack API key")
	ErrSlackEmptyUserIds   = errors.New("empty list of Slack Chat IDs")
	ErrSlackSendingMessage = errors.New("error sending Slack message")
)
View Source
var (
	ErrTelegramEmptyAPIKey    = errors.New("empty Telegram API key")
	ErrTelegramEmptyUserIds   = errors.New("empty list of Telegram Chat IDs")
	ErrTelegramInvalidChatID  = errors.New("invalid Telegram Chat ID")
	ErrTelegramSendingMessage = errors.New("error sending Telegram message")
)

Functions

func Calendar added in v0.10.0

func Calendar(ctx context.Context, ch <-chan interface{}, name, tokFile string, retries uint) error

Calendar is a function that processes messages from a channel and creates events in Google Calendar.

It takes the following parameters: - ctx: the context.Context object for managing the execution of the function - ch: a channel for receiving messages - name: the name of the calendar - tokFile: the path to the token file - retries: the number of retry attempts for inserting a Google Calendar event

It returns an error indicating any issues encountered during the execution of the function.

func Discord

func Discord(ctx context.Context, ch <-chan interface{}, token string, userIDs []string, retries uint) error

Discord sends messages through the Discord API to the specified user IDs.

ctx: The context.Context that can be used to cancel the operation. ch: The channel from which to receive messages. token: The Discord API token. userIDs: The list of user IDs to send the messages to. retries: The number of attempts to send the message before giving up. Returns an error if there was a problem sending the message.

func InitCalendar added in v0.14.0

func InitCalendar(ctx context.Context, tokFile string, name string) (*calendar.Service, string, error)

InitCalendar initializes a Google Calendar service and retrieves the calendar ID.

ctx: The context.Context for the function. tokFile: The path to the token file. name: The name of the calendar. returns: - *calendar.Service: A pointer to the calendar.Service. - string: The calendar ID. - error: Any error that occurred during initialization.

func Mail

func Mail(ctx context.Context, ch <-chan interface{}, server, port, username, password, from, subject string, to []string, retries uint) error

Mail sends a message through the mail service.

The function takes the following parameters: - ctx: the context.Context object for cancellation and timeouts. - ch: a channel from which messages are received. - server: the address of the mail server. - port: the port number for the mail server. - username: the username for authentication. - password: the password for authentication. - from: the email address of the sender. - subject: the subject of the email. - to: a slice of email addresses of the recipients. - retries: the number of retry attempts to send the message.

The function returns an error.

func Slack

func Slack(ctx context.Context, ch <-chan interface{}, token string, chatIDs []string, retries uint) error

Slack sends messages through the Slack API.

ctx: the context in which the function is executed. ch: the channel from which messages are received. token: the Slack API key. chatIDs: the IDs of the recipients. retries: the number of retries in case of failure. error: an error if there was a problem sending the message.

func Telegram

func Telegram(ctx context.Context, ch <-chan interface{}, apiKey string, chatIDs []string, retries uint) error

Telegram sends messages through the Telegram API.

It takes the following parameters: - ctx: the context.Context object for handling deadlines and cancellations. - ch: a channel for receiving messages to be sent. - apiKey: the API key for accessing the Telegram API. - chatIDs: a slice of strings containing the IDs of the chat recipients. - retries: the number of times to retry sending a message in case of failure.

It returns an error indicating any failures that occurred during the process.

Types

This section is empty.

Jump to

Keyboard shortcuts

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