-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontact_func.go
44 lines (36 loc) · 893 Bytes
/
contact_func.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
package telebot
import (
"encoding/json"
"fmt"
)
func (b *bot) SendContact(to Recipient, contact Contact, options ...any) (*AccessibleMessage, error) {
if contact.UserID != nil {
panic("telebot: contact.UserID must be nil in SendContact.")
}
params := sendContactRequest{
ChatID: to.Recipient(),
PhoneNumber: contact.PhoneNumber,
FirstName: contact.FirstName,
LastName: contact.LastName,
VCard: contact.VCard,
}
for _, option := range options {
switch v := option.(type) {
default:
if !b.format(¶ms, options...) {
panic(fmt.Errorf(GeneralBadInputError, v, methodSendContact))
}
}
}
var resp struct {
Result *AccessibleMessage
}
req, err := b.sendMethodRequest(methodSendContact, params)
if err != nil {
return nil, err
}
if err = json.Unmarshal(req, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}