tg/send.go
2023-10-22 20:41:01 +03:00

55 lines
1.1 KiB
Go

package tg
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
type MessageId int64
// Implementing the interface provides
// way to define what message will be
// sent to the side of a user.
type Sendable interface {
SendConfig(SessionId, *Bot) (*SendConfig)
SetMessage(*Message)
}
type Errorer interface {
Err() error
}
// The type is used as an endpoint to send messages
// via bot.Send .
type SendConfig struct {
// The name will be used to store
// the message in the map.
Name string
// Message with text and keyboard.
Message *tgbotapi.MessageConfig
// The image to be sent.
Image *tgbotapi.PhotoConfig
Location *tgbotapi.LocationConfig
Error error
}
func (cfg *SendConfig) WithName(name string) *SendConfig {
cfg.Name = name
return cfg
}
type MessageMap map[string] *Message
// Convert to the bot.Api.Send format.
func (config *SendConfig) ToApi() tgbotapi.Chattable {
switch {
case config.Message != nil :
return *(config.Message)
case config.Image != nil :
return *(config.Image)
case config.Location != nil :
return *(config.Location)
}
return nil
}