-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
text.go
74 lines (62 loc) · 1.79 KB
/
text.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
68
69
70
71
72
73
74
package message
import (
"context"
"github.com/go-faster/errors"
"github.com/gotd/td/telegram/message/entity"
"github.com/gotd/td/telegram/message/styling"
"github.com/gotd/td/tg"
)
func (b *Builder) sendRequest(
p tg.InputPeerClass,
msg string,
entities []tg.MessageEntityClass,
) *tg.MessagesSendMessageRequest {
return &tg.MessagesSendMessageRequest{
NoWebpage: b.noWebpage,
Silent: b.silent,
Background: b.background,
ClearDraft: b.clearDraft,
Noforwards: b.noForwards,
Peer: p,
ReplyTo: &tg.InputReplyToMessage{ReplyToMsgID: b.replyToMsgID},
Message: msg,
RandomID: 0,
ReplyMarkup: b.replyMarkup,
Entities: entities,
ScheduleDate: b.scheduleDate,
SendAs: b.sendAs,
}
}
// Text sends text message.
func (b *Builder) Text(ctx context.Context, msg string) (tg.UpdatesClass, error) {
p, err := b.peer(ctx)
if err != nil {
return nil, errors.Wrap(err, "peer")
}
upd, err := b.sender.sendMessage(ctx, b.sendRequest(p, msg, nil))
if err != nil {
return nil, errors.Wrap(err, "send text")
}
return upd, nil
}
// Textf formats and sends text message.
func (b *Builder) Textf(ctx context.Context, format string, args ...interface{}) (tg.UpdatesClass, error) {
return b.Text(ctx, formatMessage(format, args...))
}
// StyledText sends styled text message.
func (b *Builder) StyledText(ctx context.Context, texts ...StyledTextOption) (tg.UpdatesClass, error) {
p, err := b.peer(ctx)
if err != nil {
return nil, errors.Wrap(err, "peer")
}
tb := entity.Builder{}
if err := styling.Perform(&tb, texts...); err != nil {
return nil, err
}
msg, entities := tb.Complete()
upd, err := b.sender.sendMessage(ctx, b.sendRequest(p, msg, entities))
if err != nil {
return nil, errors.Wrap(err, "send styled text")
}
return upd, nil
}