feat: now the API provides ability to send location on the API itself
level.
This commit is contained in:
parent
dd549d5350
commit
6324599eed
4 changed files with 61 additions and 6 deletions
|
@ -313,6 +313,15 @@ WithUsage(tg.Func(func(c *tg.Context){
|
|||
WithAction(tg.Func(func(c *tg.Context){
|
||||
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() {
|
||||
log.Println(beh.Screens)
|
||||
|
|
29
tg/location.go
Normal file
29
tg/location.go
Normal 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
|
||||
}
|
||||
|
|
@ -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(
|
||||
sid SessionId, bot *Bot,
|
||||
) (*SendConfig) {
|
||||
|
|
14
tg/send.go
14
tg/send.go
|
@ -29,6 +29,7 @@ type SendConfig struct {
|
|||
|
||||
// The image to be sent.
|
||||
Image *tgbotapi.PhotoConfig
|
||||
Location *tgbotapi.LocationConfig
|
||||
Error error
|
||||
}
|
||||
|
||||
|
@ -41,12 +42,13 @@ type MessageMap map[string] *Message
|
|||
|
||||
// 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
|
||||
switch {
|
||||
case config.Message != nil :
|
||||
return *(config.Message)
|
||||
case config.Image != nil :
|
||||
return *(config.Image)
|
||||
case config.Location != nil :
|
||||
return *(config.Location)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue