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 {
|
2023-10-10 12:42:05 +03:00
|
|
|
SendConfig(SessionId, *Bot) (*SendConfig)
|
2023-09-26 17:13:31 +03:00
|
|
|
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
|
|
|
// Message with text and keyboard.
|
2023-09-08 17:37:32 +03:00
|
|
|
Message *tgbotapi.MessageConfig
|
|
|
|
|
|
|
|
// The image to be sent.
|
2023-12-25 17:35:00 +03:00
|
|
|
Photo *tgbotapi.PhotoConfig
|
|
|
|
Document *tgbotapi.DocumentConfig
|
2023-10-11 14:20:25 +03:00
|
|
|
Location *tgbotapi.LocationConfig
|
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
|
|
|
|
|
|
|
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 {
|
2023-10-11 14:20:25 +03:00
|
|
|
switch {
|
|
|
|
case config.Message != nil :
|
|
|
|
return *(config.Message)
|
2023-12-25 17:35:00 +03:00
|
|
|
case config.Photo != nil :
|
|
|
|
return *(config.Photo)
|
2023-10-11 14:20:25 +03:00
|
|
|
case config.Location != nil :
|
|
|
|
return *(config.Location)
|
2023-12-25 17:35:00 +03:00
|
|
|
case config.Document != nil :
|
|
|
|
return *(config.Document)
|
2023-09-08 17:37:32 +03:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|