-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
message_text.go
59 lines (50 loc) · 1.75 KB
/
message_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
package inline
import (
"github.com/gotd/td/telegram/message/entity"
"github.com/gotd/td/telegram/message/markup"
"github.com/gotd/td/telegram/message/styling"
"github.com/gotd/td/tg"
)
// MessageTextBuilder is a builder of inline result text message.
type MessageTextBuilder struct {
message *tg.InputBotInlineMessageText
options []styling.StyledTextOption
}
func (b *MessageTextBuilder) apply() (tg.InputBotInlineMessageClass, error) {
tb := entity.Builder{}
if err := styling.Perform(&tb, b.options...); err != nil {
return nil, err
}
msg, entities := tb.Complete()
r := *b.message
r.Message = msg
r.Entities = entities
return &r, nil
}
// MessageText creates new message text option builder.
func MessageText(msg string) *MessageTextBuilder {
return MessageStyledText(styling.Plain(msg))
}
// MessageStyledText creates new message text option builder.
func MessageStyledText(texts ...styling.StyledTextOption) *MessageTextBuilder {
return &MessageTextBuilder{
message: &tg.InputBotInlineMessageText{},
options: texts,
}
}
// NoWebpage sets flag to disable generation of the webpage preview.
func (b *MessageTextBuilder) NoWebpage() *MessageTextBuilder {
b.message.NoWebpage = true
return b
}
// Markup sets reply markup for sending bot buttons.
// NB: markup will not be used, if you send multiple media attachments.
func (b *MessageTextBuilder) Markup(m tg.ReplyMarkupClass) *MessageTextBuilder {
b.message.ReplyMarkup = m
return b
}
// Row sets single row keyboard markup for sending bot buttons.
// NB: markup will not be used, if you send multiple media attachments.
func (b *MessageTextBuilder) Row(button tg.KeyboardButtonClass, buttons ...tg.KeyboardButtonClass) *MessageTextBuilder {
return b.Markup(markup.InlineRow(button, buttons...))
}