-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocument_func.go
47 lines (39 loc) · 908 Bytes
/
document_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
45
46
47
package telebot
import (
"encoding/json"
"fmt"
"go.mamad.dev/telebot/validation"
)
func (b *bot) SendDocument(to Recipient, doc File, options ...any) (*AccessibleMessage, error) {
params := sendDocumentParams{
ChatID: to.Recipient(),
Document: &doc,
}
for _, option := range options {
switch v := option.(type) {
case string:
err := validation.ValidateCaptionLength(v)
if err != nil {
panic("telebot: Bad Caption: " + err.Error())
}
params.Caption = &v
case *File:
params.Thumbnail = v
default:
if !b.format(¶ms, options...) {
panic(fmt.Errorf(GeneralBadInputError, v, methodSendDocument))
}
}
}
var resp struct {
Result *AccessibleMessage
}
req, err := b.sendMethodRequest(methodSendDocument, params)
if err != nil {
return nil, err
}
if err = json.Unmarshal(req, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}