Skip to content

Commit c535558

Browse files
committed
KeyboardButton: don't push null field to server
1 parent 1afbe4e commit c535558

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

telebot/keyboard.nim

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import types, json, strutils, utils, options
1+
import types, json, strutils, utils, options, tables
22

33
proc initKeyBoardButton*(text: string): KeyboardButton =
44
result.text = text
@@ -63,7 +63,15 @@ proc `$`*(k: KeyboardMarkup): string =
6363
for row in k.inlineKeyboard:
6464
var n = newJArray()
6565
for button in row:
66-
n.add(%button)
66+
var b = %button
67+
for key in b.getFields.keys:
68+
var new_key = formatName(key)
69+
if b[key].kind == JNull:
70+
b.delete(key)
71+
elif new_key != key:
72+
b[new_key] = b[key]
73+
b.delete(key)
74+
n.add(b)
6775
kb.add(n)
6876
j["inline_keyboard"] = kb
6977
of kReplyKeyboardRemove:

telebot/utils.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ proc makeRequest*(endpoint: string, data: MultipartData = nil): Future[JsonNode]
7272
raise newException(IOError, r.status)
7373
client.close()
7474

75-
proc formatName(s: string): string {.compileTime.} =
75+
proc formatName*(s: string): string =
7676
if s == "kind":
7777
return "type"
7878
if s == "fromUser":

0 commit comments

Comments
 (0)