@@ -5,9 +5,9 @@ package tgbotapi
5
5
import (
6
6
"bytes"
7
7
"context"
8
+ "encoding/json"
8
9
"errors"
9
10
"fmt"
10
- "github.com/pquerna/ffjson/ffjson"
11
11
"github.com/strongo/logus"
12
12
"github.com/technoweenie/multipartstreamer"
13
13
"io"
@@ -130,7 +130,7 @@ func (bot *BotAPI) MakeRequest(telegramMethod string, params url.Values) (apiRes
130
130
}
131
131
}
132
132
133
- if err = ffjson .Unmarshal (apiResp .Result , & apiResp ); err != nil {
133
+ if err = json .Unmarshal (apiResp .Result , & apiResp ); err != nil {
134
134
logRequestAndResponse ()
135
135
return apiResp , fmt .Errorf ("telegram API returned non JSON response or unknown JSON: %w:\n %s" , err , string (apiResp .Result ))
136
136
} else if ! apiResp .Ok {
@@ -162,7 +162,7 @@ func (bot *BotAPI) makeMessageRequest(endpoint string, params url.Values) (Messa
162
162
}
163
163
164
164
if string (resp .Result ) != "true" { // TODO: This is a workaround for "answerCallbackQuery" that returns just "true".
165
- if err = ffjson .Unmarshal (resp .Result , & message ); err != nil {
165
+ if err = json .Unmarshal (resp .Result , & message ); err != nil {
166
166
return message , fmt .Errorf ("failed to call json.Unmarshal(s): %w: s=%s" , err , string (resp .Result ))
167
167
}
168
168
}
@@ -255,7 +255,7 @@ func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldna
255
255
logus .Debugf (bot .c , string (body ))
256
256
}
257
257
258
- if err = ffjson .Unmarshal (body , & apiResp ); err != nil {
258
+ if err = json .Unmarshal (body , & apiResp ); err != nil {
259
259
return
260
260
}
261
261
@@ -292,7 +292,7 @@ func (bot *BotAPI) GetMe() (User, error) {
292
292
return user , err
293
293
}
294
294
295
- if err = ffjson .Unmarshal (resp .Result , & user ); err != nil {
295
+ if err = json .Unmarshal (resp .Result , & user ); err != nil {
296
296
return user , err
297
297
}
298
298
@@ -309,7 +309,7 @@ func (bot *BotAPI) GetChat(chatID string) (Chat, error) {
309
309
return chat , err
310
310
}
311
311
312
- if err = ffjson .Unmarshal (resp .Result , & chat ); err != nil {
312
+ if err = json .Unmarshal (resp .Result , & chat ); err != nil {
313
313
return chat , err
314
314
}
315
315
@@ -379,7 +379,7 @@ func (bot *BotAPI) uploadAndSend(method string, config Fileable) (Message, error
379
379
return message , err
380
380
}
381
381
382
- if err = ffjson .Unmarshal (resp .Result , & message ); err != nil {
382
+ if err = json .Unmarshal (resp .Result , & message ); err != nil {
383
383
return message , err
384
384
}
385
385
@@ -429,7 +429,7 @@ func (bot *BotAPI) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserPro
429
429
return profilePhotos , err
430
430
}
431
431
432
- if err = ffjson .Unmarshal (resp .Result , & profilePhotos ); err != nil {
432
+ if err = json .Unmarshal (resp .Result , & profilePhotos ); err != nil {
433
433
return profilePhotos , err
434
434
}
435
435
@@ -452,7 +452,7 @@ func (bot *BotAPI) GetFile(config FileConfig) (File, error) {
452
452
return file , err
453
453
}
454
454
455
- if err = ffjson .Unmarshal (resp .Result , & file ); err != nil {
455
+ if err = json .Unmarshal (resp .Result , & file ); err != nil {
456
456
return file , err
457
457
}
458
458
@@ -487,7 +487,7 @@ func (bot *BotAPI) GetUpdates(config *UpdateConfig) ([]Update, error) {
487
487
return updates , err
488
488
}
489
489
490
- if err = ffjson .Unmarshal (resp .Result , & updates ); err != nil {
490
+ if err = json .Unmarshal (resp .Result , & updates ); err != nil {
491
491
return updates , err
492
492
}
493
493
@@ -520,7 +520,7 @@ func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
520
520
return apiResp , err
521
521
}
522
522
523
- if err = ffjson .Unmarshal (resp .Result , & apiResp ); err != nil {
523
+ if err = json .Unmarshal (resp .Result , & apiResp ); err != nil {
524
524
return apiResp , err
525
525
}
526
526
@@ -567,7 +567,7 @@ func (bot *BotAPI) ListenForWebhook(pattern string) <-chan Update {
567
567
body , _ := io .ReadAll (r .Body )
568
568
569
569
var update Update
570
- if err := ffjson .Unmarshal (body , & update ); err != nil {
570
+ if err := json .Unmarshal (body , & update ); err != nil {
571
571
logus .Errorf (context .Background (), fmt .Errorf ("failed to unmarshal update JSON: %w" , err ).Error ())
572
572
return
573
573
}
@@ -595,23 +595,19 @@ func (bot *BotAPI) AnswerInlineQuery(config InlineConfig) (APIResponse, error) {
595
595
v .Add ("next_offset" , config .NextOffset )
596
596
}
597
597
598
- data , err := ffjson . Marshal (config .Results )
598
+ data , err := encodeToJson (config .Results )
599
599
if err != nil {
600
- ffjson .Pool (data )
601
600
return APIResponse {}, err
602
601
}
603
602
v .Add ("results" , string (data ))
604
603
605
604
if config .Button != nil {
606
- if data , err = ffjson .Marshal (config .Button ); err != nil {
607
- ffjson .Pool (data )
605
+ if data , err = encodeToJson (config .Button ); err != nil {
608
606
return APIResponse {}, err
609
607
}
610
608
v .Add ("button" , string (data ))
611
609
}
612
610
613
- ffjson .Pool (data )
614
-
615
611
bot .debugLog ("answerInlineQuery" , v , nil )
616
612
617
613
return bot .MakeRequest ("answerInlineQuery" , v )
@@ -680,7 +676,7 @@ func (bot *BotAPI) SendCustomMessage(ctx context.Context, config Sendable, resul
680
676
if err != nil {
681
677
return
682
678
}
683
- if err = ffjson .Unmarshal (apiResponse .Result , & result ); err != nil {
679
+ if err = json .Unmarshal (apiResponse .Result , & result ); err != nil {
684
680
err = fmt .Errorf ("failed to unmarshal telegram response to type %T: %s: %w" , result , string (apiResponse .Result ), err )
685
681
return
686
682
}
0 commit comments