This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
send_location.go
57 lines (45 loc) · 1.7 KB
/
send_location.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package telegram
import json "github.com/pquerna/ffjson/ffjson"
// SendLocationParameters represents data for SendLocation method.
type SendLocationParameters struct {
// Unique identifier for the target private chat
ChatID int64 `json:"chat_id"`
// Latitude of the location
Latitude float32 `json:"latitude"`
// Longitude of the location
Longitude float32 `json:"longitude"`
// Period in seconds for which the location will be updated (see Live
// Locations), should be between 60 and 86400.
LivePeriod int `json:"live_period,omitempty"`
// If the message is a reply, ID of the original message
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
// Sends the message silently. Users will receive a notification with no
// sound.
DisableNotification bool `json:"disable_notification,omitempty"`
// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total
// price' button will be shown. If not empty, the first button must be a Pay
// button.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// NewLocation creates SendLocationParameters only with required parameters.
func NewLocation(chatID int64, latitude, longitude float32) *SendLocationParameters {
return &SendLocationParameters{
ChatID: chatID,
Latitude: latitude,
Longitude: longitude,
}
}
// SendLocation send point on the map. On success, the sent Message is returned.
func (bot *Bot) SendLocation(params *SendLocationParameters) (*Message, error) {
dst, err := json.Marshal(params)
if err != nil {
return nil, err
}
resp, err := bot.request(dst, MethodSendLocation)
if err != nil {
return nil, err
}
var data Message
err = json.Unmarshal(*resp.Result, &data)
return &data, err
}