-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilders.go
More file actions
288 lines (248 loc) · 8.13 KB
/
Copy pathbuilders.go
File metadata and controls
288 lines (248 loc) · 8.13 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package telegram
import (
"context"
"io"
)
// MessageBuilder provides a fluent interface for building and sending text messages.
type MessageBuilder struct {
client *Client
params SendMessageParams
}
// NewMessage initializes a fluent builder for sending a text message.
func (c *Client) NewMessage(chatID any, text string) *MessageBuilder {
return &MessageBuilder{
client: c,
params: SendMessageParams{
ChatID: chatID,
Text: text,
},
}
}
// ParseMode sets the message parsing mode (e.g., "HTML", "Markdown", "MarkdownV2").
func (b *MessageBuilder) ParseMode(mode string) *MessageBuilder {
b.params.ParseMode = mode
return b
}
// DisableWebPagePreview disables the preview of links in the message.
func (b *MessageBuilder) DisableWebPagePreview(disable bool) *MessageBuilder {
b.params.DisableWebPagePreview = disable
return b
}
// DisableNotification sends the message silently without sound alerts.
func (b *MessageBuilder) DisableNotification(disable bool) *MessageBuilder {
b.params.DisableNotification = disable
return b
}
// ReplyTo sets the ID of the message to reply to.
func (b *MessageBuilder) ReplyTo(messageID int64) *MessageBuilder {
b.params.ReplyParameters = &ReplyParameters{MessageID: messageID}
return b
}
// ReplyMarkup attaches an inline keyboard or reply keyboard.
func (b *MessageBuilder) ReplyMarkup(markup any) *MessageBuilder {
b.params.ReplyMarkup = markup
return b
}
// Send executes the request and returns the sent Message.
func (b *MessageBuilder) Send(ctx context.Context) (*Message, error) {
return b.client.SendMessage(ctx, &b.params)
}
// DocumentBuilder provides a fluent interface for building and streaming document uploads.
type DocumentBuilder struct {
client *Client
params SendDocumentParams
}
// NewDocument initializes a fluent builder for sending a document stream.
func (c *Client) NewDocument(chatID any, document io.Reader, filename string) *DocumentBuilder {
return &DocumentBuilder{
client: c,
params: SendDocumentParams{
ChatID: chatID,
Document: document,
Filename: filename,
},
}
}
// Caption sets the document caption text.
func (b *DocumentBuilder) Caption(caption string) *DocumentBuilder {
b.params.Caption = caption
return b
}
// ParseMode sets the parse mode for the document caption.
func (b *DocumentBuilder) ParseMode(mode string) *DocumentBuilder {
b.params.ParseMode = mode
return b
}
// DisableNotification sends the document silently.
func (b *DocumentBuilder) DisableNotification(disable bool) *DocumentBuilder {
b.params.DisableNotification = disable
return b
}
// ReplyTo sets the ID of the message to reply to.
func (b *DocumentBuilder) ReplyTo(messageID int64) *DocumentBuilder {
b.params.ReplyParameters = &ReplyParameters{MessageID: messageID}
return b
}
// ReplyMarkup attaches a keyboard layout to the document.
func (b *DocumentBuilder) ReplyMarkup(markup any) *DocumentBuilder {
b.params.ReplyMarkup = markup
return b
}
// Send executes the streaming request and returns the sent Message.
func (b *DocumentBuilder) Send(ctx context.Context) (*Message, error) {
return b.client.SendDocument(ctx, &b.params)
}
// PhotoBuilder provides a fluent interface for building and streaming photo uploads.
type PhotoBuilder struct {
client *Client
params SendPhotoParams
}
// NewPhoto initializes a fluent builder for sending a photo stream.
func (c *Client) NewPhoto(chatID any, photo io.Reader, filename string) *PhotoBuilder {
return &PhotoBuilder{
client: c,
params: SendPhotoParams{
ChatID: chatID,
Photo: photo,
Filename: filename,
},
}
}
// Caption sets the photo caption text.
func (b *PhotoBuilder) Caption(caption string) *PhotoBuilder {
b.params.Caption = caption
return b
}
// ParseMode sets the parse mode for the photo caption.
func (b *PhotoBuilder) ParseMode(mode string) *PhotoBuilder {
b.params.ParseMode = mode
return b
}
// DisableNotification sends the photo silently.
func (b *PhotoBuilder) DisableNotification(disable bool) *PhotoBuilder {
b.params.DisableNotification = disable
return b
}
// ReplyTo sets the ID of the message to reply to.
func (b *PhotoBuilder) ReplyTo(messageID int64) *PhotoBuilder {
b.params.ReplyParameters = &ReplyParameters{MessageID: messageID}
return b
}
// ReplyMarkup attaches a keyboard layout to the photo.
func (b *PhotoBuilder) ReplyMarkup(markup any) *PhotoBuilder {
b.params.ReplyMarkup = markup
return b
}
// Send executes the streaming request and returns the sent Message.
func (b *PhotoBuilder) Send(ctx context.Context) (*Message, error) {
return b.client.SendPhoto(ctx, &b.params)
}
// InlineKeyboardBuilder provides a fluent builder for InlineKeyboardMarkup.
type InlineKeyboardBuilder struct {
rows [][]InlineKeyboardButton
}
// NewInlineKeyboard initializes a fluent inline keyboard builder.
func NewInlineKeyboard() *InlineKeyboardBuilder {
return &InlineKeyboardBuilder{
rows: make([][]InlineKeyboardButton, 0),
}
}
// AddButton adds an inline button to the last row, or creates a new row if empty.
func (b *InlineKeyboardBuilder) AddButton(text, callbackData string) *InlineKeyboardBuilder {
btn := InlineKeyboardButton{
Text: text,
CallbackData: &callbackData,
}
if len(b.rows) == 0 {
b.rows = append(b.rows, []InlineKeyboardButton{btn})
} else {
lastIdx := len(b.rows) - 1
b.rows[lastIdx] = append(b.rows[lastIdx], btn)
}
return b
}
// AddURLButton adds a URL inline button to the last row, or creates a new row if empty.
func (b *InlineKeyboardBuilder) AddURLButton(text, url string) *InlineKeyboardBuilder {
btn := InlineKeyboardButton{
Text: text,
URL: &url,
}
if len(b.rows) == 0 {
b.rows = append(b.rows, []InlineKeyboardButton{btn})
} else {
lastIdx := len(b.rows) - 1
b.rows[lastIdx] = append(b.rows[lastIdx], btn)
}
return b
}
// AddButtonRow adds a new row containing a single callback button.
func (b *InlineKeyboardBuilder) AddButtonRow(text, callbackData string) *InlineKeyboardBuilder {
btn := InlineKeyboardButton{
Text: text,
CallbackData: &callbackData,
}
b.rows = append(b.rows, []InlineKeyboardButton{btn})
return b
}
// AddURLButtonRow adds a new row containing a single URL button.
func (b *InlineKeyboardBuilder) AddURLButtonRow(text, url string) *InlineKeyboardBuilder {
btn := InlineKeyboardButton{
Text: text,
URL: &url,
}
b.rows = append(b.rows, []InlineKeyboardButton{btn})
return b
}
// Build constructs and returns the InlineKeyboardMarkup structure.
func (b *InlineKeyboardBuilder) Build() InlineKeyboardMarkup {
return InlineKeyboardMarkup{
InlineKeyboard: b.rows,
}
}
// ReplyKeyboardBuilder provides a fluent builder for ReplyKeyboardMarkup.
type ReplyKeyboardBuilder struct {
rows [][]KeyboardButton
resizeKeyboard bool
oneTimeKeyboard bool
}
// NewReplyKeyboard initializes a fluent reply keyboard builder.
func NewReplyKeyboard() *ReplyKeyboardBuilder {
return &ReplyKeyboardBuilder{
rows: make([][]KeyboardButton, 0),
}
}
// AddButton adds a keyboard button to the last row, or creates a new row if empty.
func (b *ReplyKeyboardBuilder) AddButton(text string) *ReplyKeyboardBuilder {
btn := KeyboardButton{Text: text}
if len(b.rows) == 0 {
b.rows = append(b.rows, []KeyboardButton{btn})
} else {
lastIdx := len(b.rows) - 1
b.rows[lastIdx] = append(b.rows[lastIdx], btn)
}
return b
}
// AddButtonRow adds a new row containing a single reply keyboard button.
func (b *ReplyKeyboardBuilder) AddButtonRow(text string) *ReplyKeyboardBuilder {
btn := KeyboardButton{Text: text}
b.rows = append(b.rows, []KeyboardButton{btn})
return b
}
// ResizeKeyboard requests clients to resize the keyboard vertically for optimal fit.
func (b *ReplyKeyboardBuilder) ResizeKeyboard(resize bool) *ReplyKeyboardBuilder {
b.resizeKeyboard = resize
return b
}
// OneTimeKeyboard requests clients to hide the keyboard as soon as it's been used.
func (b *ReplyKeyboardBuilder) OneTimeKeyboard(oneTime bool) *ReplyKeyboardBuilder {
b.oneTimeKeyboard = oneTime
return b
}
// Build constructs and returns the ReplyKeyboardMarkup structure.
func (b *ReplyKeyboardBuilder) Build() ReplyKeyboardMarkup {
return ReplyKeyboardMarkup{
Keyboard: b.rows,
ResizeKeyboard: b.resizeKeyboard,
OneTimeKeyboard: b.oneTimeKeyboard,
}
}