1
0
telegram/send_contact.go

60 lines
1.7 KiB
Go
Raw Normal View History

2018-02-14 22:58:27 +00:00
package telegram
import json "github.com/pquerna/ffjson/ffjson"
2018-04-19 13:02:15 +00:00
// SendContactParameters represents data for SendContact method.
2018-02-14 22:58:27 +00:00
type SendContactParameters struct {
// Unique identifier for the target private chat
ChatID int64 `json:"chat_id"`
// Contact's phone number
PhoneNumber string `json:"phone_number"`
// Contact's first name
FirstName string `json:"first_name"`
// Contact's last name
LastName string `json:"last_name"`
// Additional data about the contact in the form of a vCard, 0-2048 bytes
VCard string `json:"vcard,omitempty"`
2018-02-14 22:58:27 +00:00
// Sends the message silently. Users will receive a notification with no
// sound.
DisableNotification bool `json:"disable_notification,omitempty"`
// If the message is a reply, ID of the original message
ReplyToMessageID int `json:"reply_to_message_id,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"`
}
2018-04-19 13:02:15 +00:00
// NewContact creates SendContactParameters only with required parameters.
2018-02-14 22:58:27 +00:00
func NewContact(chatID int64, phoneNumber, firstName string) *SendContactParameters {
return &SendContactParameters{
ChatID: chatID,
PhoneNumber: phoneNumber,
FirstName: firstName,
}
}
// SendContact send phone contacts. On success, the sent Message is returned.
2018-08-21 11:05:04 +00:00
func (bot *Bot) SendContact(params *SendContactParameters) (msg *Message, err error) {
2018-02-14 22:58:27 +00:00
dst, err := json.Marshal(*params)
if err != nil {
2018-08-21 11:05:04 +00:00
return
2018-02-14 22:58:27 +00:00
}
2018-04-12 11:58:05 +00:00
resp, err := bot.request(dst, MethodSendContact)
2018-02-14 22:58:27 +00:00
if err != nil {
2018-08-21 11:05:04 +00:00
return
2018-02-14 22:58:27 +00:00
}
2018-08-21 11:05:04 +00:00
msg = new(Message)
err = json.Unmarshal(*resp.Result, msg)
return
2018-02-14 22:58:27 +00:00
}