-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
draft.go
67 lines (57 loc) · 1.67 KB
/
draft.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
58
59
60
61
62
63
64
65
66
67
package message
import (
"context"
"golang.org/x/xerrors"
"github.com/gotd/td/telegram/message/entity"
"github.com/gotd/td/telegram/message/styling"
"github.com/gotd/td/tg"
)
func (b *Builder) saveDraftRequest(
peer tg.InputPeerClass,
msg string,
entities []tg.MessageEntityClass,
) *tg.MessagesSaveDraftRequest {
return &tg.MessagesSaveDraftRequest{
NoWebpage: b.noWebpage,
Peer: peer,
ReplyToMsgID: b.replyToMsgID,
Message: msg,
Entities: entities,
}
}
// ClearDraft clears draft.
// Also, you can use Clear() builder option with any other message send method.
//
// See https://core.telegram.org/api/drafts#clearing-drafts.
func (b *Builder) ClearDraft(ctx context.Context) error {
p, err := b.peer(ctx)
if err != nil {
return xerrors.Errorf("peer: %w", err)
}
return b.sender.saveDraft(ctx, &tg.MessagesSaveDraftRequest{Peer: p})
}
// SaveDraft saves given message as draft.
//
// See https://core.telegram.org/api/drafts#saving-drafts.
func (b *Builder) SaveDraft(ctx context.Context, msg string) error {
p, err := b.peer(ctx)
if err != nil {
return xerrors.Errorf("peer: %w", err)
}
return b.sender.saveDraft(ctx, b.saveDraftRequest(p, msg, nil))
}
// SaveStyledDraft saves given styled message as draft.
//
// See https://core.telegram.org/api/drafts#saving-drafts.
func (b *Builder) SaveStyledDraft(ctx context.Context, texts ...StyledTextOption) error {
p, err := b.peer(ctx)
if err != nil {
return xerrors.Errorf("peer: %w", err)
}
tb := entity.Builder{}
if err := styling.Perform(&tb, texts...); err != nil {
return err
}
msg, entities := tb.Complete()
return b.sender.saveDraft(ctx, b.saveDraftRequest(p, msg, entities))
}