2023-08-19 12:47:33 +03:00
|
|
|
package tg
|
|
|
|
|
2023-09-08 17:37:32 +03:00
|
|
|
import (
|
|
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MessageId int64
|
2023-08-19 12:47:33 +03:00
|
|
|
|
2023-09-25 23:43:22 +03:00
|
|
|
// Implementing the interface provides
|
|
|
|
// way to define what message will be
|
|
|
|
// sent to the side of a user.
|
2023-09-26 17:13:31 +03:00
|
|
|
type Sendable interface {
|
|
|
|
SendConfig(*Context) (*SendConfig)
|
|
|
|
SetMessage(*Message)
|
2023-09-16 14:34:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Errorer interface {
|
|
|
|
Err() error
|
2023-09-08 17:37:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// The type is used as an endpoint to send messages
|
|
|
|
// via bot.Send .
|
|
|
|
type SendConfig struct {
|
2023-09-16 14:34:17 +03:00
|
|
|
// The name will be used to store
|
|
|
|
// the message in the map.
|
|
|
|
Name string
|
|
|
|
// Message with text and keyboard.
|
2023-09-08 17:37:32 +03:00
|
|
|
Message *tgbotapi.MessageConfig
|
|
|
|
|
|
|
|
// The image to be sent.
|
|
|
|
Image *tgbotapi.PhotoConfig
|
2023-09-16 14:34:17 +03:00
|
|
|
Error error
|
2023-08-19 12:47:33 +03:00
|
|
|
}
|
2023-09-08 17:37:32 +03:00
|
|
|
|
2023-09-16 14:34:17 +03:00
|
|
|
func (cfg *SendConfig) WithName(name string) *SendConfig {
|
|
|
|
cfg.Name = name
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
type MessageMap map[string] *Message
|
|
|
|
|
2023-09-08 17:37:32 +03:00
|
|
|
// Convert to the bot.Api.Send format.
|
|
|
|
func (config *SendConfig) ToApi() tgbotapi.Chattable {
|
|
|
|
if config.Message != nil {
|
|
|
|
return *config.Message
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.Image != nil {
|
|
|
|
return *config.Image
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|