Merge remote-tracking branch 'pr0head/master' into develop
commit
4ec899a62e
|
@ -266,7 +266,7 @@ func TestSendWithContact(t *testing.T) {
|
|||
func TestSendWithLocation(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
_, err := bot.Send(tgbotapi.NewLocation(ChatID, 40, 40))
|
||||
_, err := bot.Send(tgbotapi.NewLocation(ChatID, 40, 40, 86400))
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
|
49
configs.go
49
configs.go
|
@ -573,6 +573,7 @@ type LocationConfig struct {
|
|||
BaseChat
|
||||
Latitude float64 // required
|
||||
Longitude float64 // required
|
||||
LivePeriod int // optional
|
||||
}
|
||||
|
||||
// values returns a url.Values representation of LocationConfig.
|
||||
|
@ -584,6 +585,9 @@ func (config LocationConfig) values() (url.Values, error) {
|
|||
|
||||
v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64))
|
||||
v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64))
|
||||
if config.LivePeriod != 0 {
|
||||
v.Add("live_period", strconv.Itoa(config.LivePeriod))
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
@ -593,6 +597,51 @@ func (config LocationConfig) method() string {
|
|||
return "sendLocation"
|
||||
}
|
||||
|
||||
// LocationConfig contains information about a SendLocation request.
|
||||
type EditMessageLiveLocationConfig struct {
|
||||
BaseEdit
|
||||
Latitude float64 // required
|
||||
Longitude float64 // required
|
||||
}
|
||||
|
||||
// values returns a url.Values representation of EditMessageLiveLocationConfig.
|
||||
func (config EditMessageLiveLocationConfig) values() (url.Values, error) {
|
||||
v, err := config.BaseEdit.values()
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
|
||||
v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64))
|
||||
v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64))
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// method returns Telegram API method name for edit message Live Location.
|
||||
func (config EditMessageLiveLocationConfig) method() string {
|
||||
return "editMessageLiveLocation"
|
||||
}
|
||||
|
||||
// LocationConfig contains information about a StopMessageLiveLocation request.
|
||||
type StopMessageLiveLocationConfig struct {
|
||||
BaseEdit
|
||||
}
|
||||
|
||||
// values returns a url.Values representation of StopMessageLiveLocationConfig.
|
||||
func (config StopMessageLiveLocationConfig) values() (url.Values, error) {
|
||||
v, err := config.BaseEdit.values()
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// method returns Telegram API method name for stop message Live Location.
|
||||
func (config StopMessageLiveLocationConfig) method() string {
|
||||
return "stopMessageLiveLocation"
|
||||
}
|
||||
|
||||
// VenueConfig contains information about a SendVenue request.
|
||||
type VenueConfig struct {
|
||||
BaseChat
|
||||
|
|
|
@ -268,13 +268,14 @@ func NewContact(chatID int64, phoneNumber, firstName string) ContactConfig {
|
|||
// NewLocation shares your location.
|
||||
//
|
||||
// chatID is where to send it, latitude and longitude are coordinates.
|
||||
func NewLocation(chatID int64, latitude float64, longitude float64) LocationConfig {
|
||||
func NewLocation(chatID int64, latitude float64, longitude float64, live_period int) LocationConfig {
|
||||
return LocationConfig{
|
||||
BaseChat: BaseChat{
|
||||
ChatID: chatID,
|
||||
},
|
||||
Latitude: latitude,
|
||||
Longitude: longitude,
|
||||
LivePeriod: live_period,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,13 +466,14 @@ func NewInlineQueryResultDocument(id, url, title, mimeType string) InlineQueryRe
|
|||
}
|
||||
|
||||
// NewInlineQueryResultLocation creates a new inline query location.
|
||||
func NewInlineQueryResultLocation(id, title string, latitude, longitude float64) InlineQueryResultLocation {
|
||||
func NewInlineQueryResultLocation(id, title string, latitude, longitude float64, live_period int) InlineQueryResultLocation {
|
||||
return InlineQueryResultLocation{
|
||||
Type: "location",
|
||||
ID: id,
|
||||
Title: title,
|
||||
Latitude: latitude,
|
||||
Longitude: longitude,
|
||||
LivePeriod: live_period,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -127,13 +127,14 @@ func TestNewInlineQueryResultDocument(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewInlineQueryResultLocation(t *testing.T) {
|
||||
result := tgbotapi.NewInlineQueryResultLocation("id", "name", 40, 50)
|
||||
result := tgbotapi.NewInlineQueryResultLocation("id", "name", 40, 50, 86400)
|
||||
|
||||
if result.Type != "location" ||
|
||||
result.ID != "id" ||
|
||||
result.Title != "name" ||
|
||||
result.Latitude != 40 ||
|
||||
result.Longitude != 50 {
|
||||
result.Longitude != 50 ||
|
||||
result.LivePeriod != 86400 {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
|
1
types.go
1
types.go
|
@ -662,6 +662,7 @@ type InlineQueryResultLocation struct {
|
|||
ID string `json:"id"` // required
|
||||
Latitude float64 `json:"latitude"` // required
|
||||
Longitude float64 `json:"longitude"` // required
|
||||
LivePeriod int `json:"live_period"` // optional
|
||||
Title string `json:"title"` // required
|
||||
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
||||
|
|
Loading…
Reference in New Issue