From 65947daaab88cefc8f87b936cb1fafb60d09115d Mon Sep 17 00:00:00 2001 From: pr0head Date: Fri, 13 Oct 2017 17:00:04 +0300 Subject: [PATCH 1/4] Added `live_period` for Location --- configs.go | 8 ++++++-- helpers.go | 20 +++++++++++--------- types.go | 21 ++++++++++++--------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/configs.go b/configs.go index c0293ce..84912ab 100644 --- a/configs.go +++ b/configs.go @@ -571,8 +571,9 @@ func (config VoiceConfig) method() string { // LocationConfig contains information about a SendLocation request. type LocationConfig struct { BaseChat - Latitude float64 // required - Longitude float64 // required + 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 } diff --git a/helpers.go b/helpers.go index 132d957..2c5d046 100644 --- a/helpers.go +++ b/helpers.go @@ -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, + 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, + Type: "location", + ID: id, + Title: title, + Latitude: latitude, + Longitude: longitude, + LivePeriod: live_period, } } diff --git a/types.go b/types.go index 91875bb..691a645 100644 --- a/types.go +++ b/types.go @@ -331,8 +331,9 @@ type Contact struct { // Location contains information about a place. type Location struct { - Longitude float64 `json:"longitude"` - Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + Latitude float64 `json:"latitude"` + LivePeriod int `json:"live_period"` } // Venue contains information about a venue, including its Location. @@ -639,11 +640,12 @@ type InlineQueryResultDocument struct { // InlineQueryResultLocation is an inline query response location. type InlineQueryResultLocation struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - Latitude float64 `json:"latitude"` // required - Longitude float64 `json:"longitude"` // required - Title string `json:"title"` // required + Type string `json:"type"` // required + 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"` ThumbURL string `json:"thumb_url"` @@ -679,8 +681,9 @@ type InputTextMessageContent struct { // InputLocationMessageContent contains a location for displaying // as an inline query result. type InputLocationMessageContent struct { - Latitude float64 `json:"latitude"` - Longitude float64 `json:"longitude"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + LivePeriod int `json:"live_period"` } // InputVenueMessageContent contains a venue for displaying From 7031d820be302f01d2e6380912101e3be6736878 Mon Sep 17 00:00:00 2001 From: pr0head Date: Fri, 13 Oct 2017 22:53:47 +0300 Subject: [PATCH 2/4] Added `live_period` for Location (tests) --- bot_test.go | 2 +- helpers_test.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bot_test.go b/bot_test.go index a811a27..968f78b 100644 --- a/bot_test.go +++ b/bot_test.go @@ -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) diff --git a/helpers_test.go b/helpers_test.go index 9542f02..7c510e9 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -126,13 +126,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() } } From 5cbecde819a8e220f3fafcf748aef01cf4cffcd8 Mon Sep 17 00:00:00 2001 From: pr0head Date: Sat, 14 Oct 2017 01:05:24 +0300 Subject: [PATCH 3/4] Added `editMessageLiveLocation` and `stopMessageLiveLocation` methods --- configs.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ types.go | 21 +++++++++------------ 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/configs.go b/configs.go index 84912ab..337c601 100644 --- a/configs.go +++ b/configs.go @@ -597,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 diff --git a/types.go b/types.go index 691a645..91875bb 100644 --- a/types.go +++ b/types.go @@ -331,9 +331,8 @@ type Contact struct { // Location contains information about a place. type Location struct { - Longitude float64 `json:"longitude"` - Latitude float64 `json:"latitude"` - LivePeriod int `json:"live_period"` + Longitude float64 `json:"longitude"` + Latitude float64 `json:"latitude"` } // Venue contains information about a venue, including its Location. @@ -640,12 +639,11 @@ type InlineQueryResultDocument struct { // InlineQueryResultLocation is an inline query response location. type InlineQueryResultLocation struct { - Type string `json:"type"` // required - 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 + Type string `json:"type"` // required + ID string `json:"id"` // required + Latitude float64 `json:"latitude"` // required + Longitude float64 `json:"longitude"` // required + Title string `json:"title"` // required ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` ThumbURL string `json:"thumb_url"` @@ -681,9 +679,8 @@ type InputTextMessageContent struct { // InputLocationMessageContent contains a location for displaying // as an inline query result. type InputLocationMessageContent struct { - Latitude float64 `json:"latitude"` - Longitude float64 `json:"longitude"` - LivePeriod int `json:"live_period"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` } // InputVenueMessageContent contains a venue for displaying From dffc002f9e2338af6f66ecd72df5db722c9e285d Mon Sep 17 00:00:00 2001 From: pr0head Date: Tue, 17 Oct 2017 19:00:20 +0300 Subject: [PATCH 4/4] Fix struct for InlineQueryResultLocation --- types.go | 1 + 1 file changed, 1 insertion(+) diff --git a/types.go b/types.go index 91875bb..e59afbb 100644 --- a/types.go +++ b/types.go @@ -643,6 +643,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"`