feat: now the API provides ability to send location on the API itself

level.
This commit is contained in:
Andrey Parhomenko 2023-10-11 14:20:25 +03:00
parent dd549d5350
commit 6324599eed
4 changed files with 61 additions and 6 deletions

View file

@ -313,6 +313,15 @@ WithUsage(tg.Func(func(c *tg.Context){
WithAction(tg.Func(func(c *tg.Context){ WithAction(tg.Func(func(c *tg.Context){
c.Sendf("%q", c.History()) c.Sendf("%q", c.History())
})), })),
tg.NewCommand("washington").
Desc("Send location of the Washington").
WithAction(tg.Func(func(c *tg.Context){
c.Send(
tg.NewMessage("").Location(
47.751076, -120.740135,
),
)
})),
)) ))
func main() { func main() {
log.Println(beh.Screens) log.Println(beh.Screens)

29
tg/location.go Normal file
View file

@ -0,0 +1,29 @@
package tg
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
type Location = tgbotapi.Location
type LocationCompo struct {
*MessageCompo
Location
}
func (compo *LocationCompo) SendConfig(
sid SessionId, bot *Bot,
) (*SendConfig) {
cid := sid.ToApi()
loc := tgbotapi.NewLocation(
cid,
compo.Latitude,
compo.Longitude,
)
ret := &SendConfig{
Location: &loc,
}
return ret
}

View file

@ -77,6 +77,21 @@ func (msg *MessageCompo) Reply(reply *Reply) *ReplyCompo {
} }
} }
// Transform the message component into the location one.
func (msg *MessageCompo) Location(
lat, long float64,
) *LocationCompo {
ret := &LocationCompo{
MessageCompo: msg,
Location: Location{
Latitude: lat,
Longitude: long,
},
}
return ret
}
// Implementing the Sendable interface.
func (config *MessageCompo) SendConfig( func (config *MessageCompo) SendConfig(
sid SessionId, bot *Bot, sid SessionId, bot *Bot,
) (*SendConfig) { ) (*SendConfig) {

View file

@ -29,6 +29,7 @@ type SendConfig struct {
// The image to be sent. // The image to be sent.
Image *tgbotapi.PhotoConfig Image *tgbotapi.PhotoConfig
Location *tgbotapi.LocationConfig
Error error Error error
} }
@ -41,12 +42,13 @@ type MessageMap map[string] *Message
// Convert to the bot.Api.Send format. // Convert to the bot.Api.Send format.
func (config *SendConfig) ToApi() tgbotapi.Chattable { func (config *SendConfig) ToApi() tgbotapi.Chattable {
if config.Message != nil { switch {
return *config.Message case config.Message != nil :
} return *(config.Message)
case config.Image != nil :
if config.Image != nil { return *(config.Image)
return *config.Image case config.Location != nil :
return *(config.Location)
} }
return nil return nil
} }