Skip to content

Commit 0a57807

Browse files
author
Syfaro
committed
Additional changes for Telegram API updates.
1 parent f3a33ae commit 0a57807

File tree

5 files changed

+82
-13
lines changed

5 files changed

+82
-13
lines changed

bot.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ func (bot *BotAPI) AnswerCallbackQuery(config CallbackConfig) (APIResponse, erro
525525
if config.URL != "" {
526526
v.Add("url", config.URL)
527527
}
528+
v.Add("cache_time", strconv.Itoa(config.CacheTime))
528529

529530
bot.debugLog("answerCallbackQuery", v, nil)
530531

bot_test.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os"
99
"testing"
10+
"time"
1011
)
1112

1213
const (
@@ -25,6 +26,7 @@ func getBot(t *testing.T) (*tgbotapi.BotAPI, error) {
2526
bot, err := tgbotapi.NewBotAPI(TestToken)
2627

2728
if err != nil {
29+
t.Error(err)
2830
t.Fail()
2931
}
3032

@@ -35,6 +37,7 @@ func TestNewBotAPI_notoken(t *testing.T) {
3537
_, err := tgbotapi.NewBotAPI("")
3638

3739
if err == nil {
40+
t.Error(err)
3841
t.Fail()
3942
}
4043
}
@@ -47,6 +50,7 @@ func TestGetUpdates(t *testing.T) {
4750
_, err := bot.GetUpdates(u)
4851

4952
if err != nil {
53+
t.Error(err)
5054
t.Fail()
5155
}
5256
}
@@ -59,6 +63,7 @@ func TestSendWithMessage(t *testing.T) {
5963
_, err := bot.Send(msg)
6064

6165
if err != nil {
66+
t.Error(err)
6267
t.Fail()
6368
}
6469
}
@@ -71,6 +76,7 @@ func TestSendWithMessageReply(t *testing.T) {
7176
_, err := bot.Send(msg)
7277

7378
if err != nil {
79+
t.Error(err)
7480
t.Fail()
7581
}
7682
}
@@ -82,6 +88,7 @@ func TestSendWithMessageForward(t *testing.T) {
8288
_, err := bot.Send(msg)
8389

8490
if err != nil {
91+
t.Error(err)
8592
t.Fail()
8693
}
8794
}
@@ -94,6 +101,7 @@ func TestSendWithNewPhoto(t *testing.T) {
94101
_, err := bot.Send(msg)
95102

96103
if err != nil {
104+
t.Error(err)
97105
t.Fail()
98106
}
99107
}
@@ -109,6 +117,7 @@ func TestSendWithNewPhotoWithFileBytes(t *testing.T) {
109117
_, err := bot.Send(msg)
110118

111119
if err != nil {
120+
t.Error(err)
112121
t.Fail()
113122
}
114123
}
@@ -124,6 +133,7 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {
124133
_, err := bot.Send(msg)
125134

126135
if err != nil {
136+
t.Error(err)
127137
t.Fail()
128138
}
129139
}
@@ -137,6 +147,7 @@ func TestSendWithNewPhotoReply(t *testing.T) {
137147
_, err := bot.Send(msg)
138148

139149
if err != nil {
150+
t.Error(err)
140151
t.Fail()
141152
}
142153
}
@@ -149,6 +160,7 @@ func TestSendWithExistingPhoto(t *testing.T) {
149160
_, err := bot.Send(msg)
150161

151162
if err != nil {
163+
t.Error(err)
152164
t.Fail()
153165
}
154166
}
@@ -160,6 +172,7 @@ func TestSendWithNewDocument(t *testing.T) {
160172
_, err := bot.Send(msg)
161173

162174
if err != nil {
175+
t.Error(err)
163176
t.Fail()
164177
}
165178
}
@@ -171,6 +184,7 @@ func TestSendWithExistingDocument(t *testing.T) {
171184
_, err := bot.Send(msg)
172185

173186
if err != nil {
187+
t.Error(err)
174188
t.Fail()
175189
}
176190
}
@@ -187,6 +201,7 @@ func TestSendWithNewAudio(t *testing.T) {
187201
_, err := bot.Send(msg)
188202

189203
if err != nil {
204+
t.Error(err)
190205
t.Fail()
191206
}
192207
}
@@ -202,6 +217,7 @@ func TestSendWithExistingAudio(t *testing.T) {
202217
_, err := bot.Send(msg)
203218

204219
if err != nil {
220+
t.Error(err)
205221
t.Fail()
206222
}
207223
}
@@ -214,6 +230,7 @@ func TestSendWithNewVoice(t *testing.T) {
214230
_, err := bot.Send(msg)
215231

216232
if err != nil {
233+
t.Error(err)
217234
t.Fail()
218235
}
219236
}
@@ -226,6 +243,7 @@ func TestSendWithExistingVoice(t *testing.T) {
226243
_, err := bot.Send(msg)
227244

228245
if err != nil {
246+
t.Error(err)
229247
t.Fail()
230248
}
231249
}
@@ -236,6 +254,7 @@ func TestSendWithContact(t *testing.T) {
236254
contact := tgbotapi.NewContact(ChatID, "5551234567", "Test")
237255

238256
if _, err := bot.Send(contact); err != nil {
257+
t.Error(err)
239258
t.Fail()
240259
}
241260
}
@@ -246,6 +265,7 @@ func TestSendWithLocation(t *testing.T) {
246265
_, err := bot.Send(tgbotapi.NewLocation(ChatID, 40, 40))
247266

248267
if err != nil {
268+
t.Error(err)
249269
t.Fail()
250270
}
251271
}
@@ -256,6 +276,7 @@ func TestSendWithVenue(t *testing.T) {
256276
venue := tgbotapi.NewVenue(ChatID, "A Test Location", "123 Test Street", 40, 40)
257277

258278
if _, err := bot.Send(venue); err != nil {
279+
t.Error(err)
259280
t.Fail()
260281
}
261282
}
@@ -270,6 +291,7 @@ func TestSendWithNewVideo(t *testing.T) {
270291
_, err := bot.Send(msg)
271292

272293
if err != nil {
294+
t.Error(err)
273295
t.Fail()
274296
}
275297
}
@@ -284,6 +306,7 @@ func TestSendWithExistingVideo(t *testing.T) {
284306
_, err := bot.Send(msg)
285307

286308
if err != nil {
309+
t.Error(err)
287310
t.Fail()
288311
}
289312
}
@@ -296,6 +319,7 @@ func TestSendWithNewSticker(t *testing.T) {
296319
_, err := bot.Send(msg)
297320

298321
if err != nil {
322+
t.Error(err)
299323
t.Fail()
300324
}
301325
}
@@ -308,6 +332,7 @@ func TestSendWithExistingSticker(t *testing.T) {
308332
_, err := bot.Send(msg)
309333

310334
if err != nil {
335+
t.Error(err)
311336
t.Fail()
312337
}
313338
}
@@ -316,10 +341,11 @@ func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {
316341
bot, _ := getBot(t)
317342

318343
msg := tgbotapi.NewStickerUpload(ChatID, "tests/image.jpg")
319-
msg.ReplyMarkup = tgbotapi.ReplyKeyboardHide{true, false}
344+
msg.ReplyMarkup = tgbotapi.ReplyKeyboardRemove{true, false}
320345
_, err := bot.Send(msg)
321346

322347
if err != nil {
348+
t.Error(err)
323349
t.Fail()
324350
}
325351
}
@@ -328,12 +354,12 @@ func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) {
328354
bot, _ := getBot(t)
329355

330356
msg := tgbotapi.NewStickerShare(ChatID, ExistingStickerFileID)
331-
msg.ReplyMarkup = tgbotapi.ReplyKeyboardHide{true, false}
357+
msg.ReplyMarkup = tgbotapi.ReplyKeyboardRemove{true, false}
332358

333359
_, err := bot.Send(msg)
334360

335361
if err != nil {
336-
362+
t.Error(err)
337363
t.Fail()
338364
}
339365
}
@@ -346,6 +372,7 @@ func TestGetFile(t *testing.T) {
346372
_, err := bot.GetFile(file)
347373

348374
if err != nil {
375+
t.Error(err)
349376
t.Fail()
350377
}
351378
}
@@ -356,6 +383,7 @@ func TestSendChatConfig(t *testing.T) {
356383
_, err := bot.Send(tgbotapi.NewChatAction(ChatID, tgbotapi.ChatTyping))
357384

358385
if err != nil {
386+
t.Error(err)
359387
t.Fail()
360388
}
361389
}
@@ -365,6 +393,7 @@ func TestSendEditMessage(t *testing.T) {
365393

366394
msg, err := bot.Send(tgbotapi.NewMessage(ChatID, "Testing editing."))
367395
if err != nil {
396+
t.Error(err)
368397
t.Fail()
369398
}
370399

@@ -378,6 +407,7 @@ func TestSendEditMessage(t *testing.T) {
378407

379408
_, err = bot.Send(edit)
380409
if err != nil {
410+
t.Error(err)
381411
t.Fail()
382412
}
383413
}
@@ -387,18 +417,22 @@ func TestGetUserProfilePhotos(t *testing.T) {
387417

388418
_, err := bot.GetUserProfilePhotos(tgbotapi.NewUserProfilePhotos(ChatID))
389419
if err != nil {
420+
t.Error(err)
390421
t.Fail()
391422
}
392423
}
393424

394425
func TestSetWebhookWithCert(t *testing.T) {
395426
bot, _ := getBot(t)
396427

428+
time.Sleep(time.Second * 2)
429+
397430
bot.RemoveWebhook()
398431

399432
wh := tgbotapi.NewWebhookWithCert("https://example.com/tgbotapi-test/"+bot.Token, "tests/cert.pem")
400433
_, err := bot.SetWebhook(wh)
401434
if err != nil {
435+
t.Error(err)
402436
t.Fail()
403437
}
404438

@@ -408,11 +442,14 @@ func TestSetWebhookWithCert(t *testing.T) {
408442
func TestSetWebhookWithoutCert(t *testing.T) {
409443
bot, _ := getBot(t)
410444

445+
time.Sleep(time.Second * 2)
446+
411447
bot.RemoveWebhook()
412448

413449
wh := tgbotapi.NewWebhook("https://example.com/tgbotapi-test/" + bot.Token)
414450
_, err := bot.SetWebhook(wh)
415451
if err != nil {
452+
t.Error(err)
416453
t.Fail()
417454
}
418455

@@ -427,6 +464,7 @@ func TestUpdatesChan(t *testing.T) {
427464
_, err := bot.GetUpdatesChan(ucfg)
428465

429466
if err != nil {
467+
t.Error(err)
430468
t.Fail()
431469
}
432470
}

configs.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ func (config AudioConfig) values() (url.Values, error) {
296296
if config.Title != "" {
297297
v.Add("title", config.Title)
298298
}
299+
if config.Caption != "" {
300+
v.Add("caption", config.Caption)
301+
}
299302

300303
return v, nil
301304
}
@@ -314,6 +317,9 @@ func (config AudioConfig) params() (map[string]string, error) {
314317
if config.Title != "" {
315318
params["title"] = config.Title
316319
}
320+
if config.Caption != "" {
321+
params["caption"] = config.Caption
322+
}
317323

318324
return params, nil
319325
}
@@ -561,13 +567,14 @@ func (config GameConfig) method() string {
561567

562568
// SetGameScoreConfig allows you to update the game score in a chat.
563569
type SetGameScoreConfig struct {
564-
UserID int
565-
Score int
566-
ChatID int
567-
ChannelUsername string
568-
MessageID int
569-
InlineMessageID string
570-
EditMessage bool
570+
UserID int
571+
Score int
572+
Force bool
573+
DisableEditMessage bool
574+
ChatID int
575+
ChannelUsername string
576+
MessageID int
577+
InlineMessageID string
571578
}
572579

573580
func (config SetGameScoreConfig) values() (url.Values, error) {
@@ -585,7 +592,7 @@ func (config SetGameScoreConfig) values() (url.Values, error) {
585592
} else {
586593
v.Add("inline_message_id", config.InlineMessageID)
587594
}
588-
v.Add("edit_message", strconv.FormatBool(config.EditMessage))
595+
v.Add("disable_edit_message", strconv.FormatBool(config.DisableEditMessage))
589596

590597
return v, nil
591598
}
@@ -756,6 +763,7 @@ type CallbackConfig struct {
756763
Text string `json:"text"`
757764
ShowAlert bool `json:"show_alert"`
758765
URL string `json:"url"`
766+
CacheTime int `json:"cache_time"`
759767
}
760768

761769
// ChatMemberConfig contains information about a user in a chat for use

0 commit comments

Comments
 (0)