Skip to content

Commit d9f5621

Browse files
committed
debug request body
1 parent 0db9662 commit d9f5621

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

telebot/api.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ proc cleanUpdates*(b: TeleBot) {.async.} =
690690
proc loop(b: TeleBot, timeout = 50, offset, limit = 0) {.async.} =
691691
try:
692692
let me = waitFor b.getMe()
693+
b.id = me.id
693694
if me.username.isSome:
694695
b.username = me.username.get().toLowerAscii()
695696
except IOError, OSError:

telebot/types.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type
1616
catchallCommandCallback*: CatchallCommandCallback
1717
inlineQueryCallbacks*: seq[InlineQueryCallback]
1818
proxy*: Proxy
19+
id*: int
1920
username*: string
2021

2122
CatchallCommand* = object of TelegramObject

telebot/webhook.nim

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ proc getWebhookInfo*(b: TeleBot): Future[WebhookInfo] {.async.} =
5252
result = getWebhookInfo(res)
5353

5454

55-
proc startWebhook*(b: Telebot, secret, url: string, port = 8080) =
55+
proc startWebhook*(b: Telebot, secret, url: string, port=Port(8080)) =
5656
try:
5757
let me = waitFor b.getMe()
58+
b.id = me.id
5859
if me.username.isSome:
5960
b.username = me.username.get().toLowerAscii()
6061
except IOError, OSError:
@@ -63,14 +64,20 @@ proc startWebhook*(b: Telebot, secret, url: string, port = 8080) =
6364
waitFor b.setWebhook(url)
6465

6566
proc callback(req: Request) {.async, gcsafe.} =
67+
d("GET: ", req.body)
6668
if req.url.path == "/" & secret:
67-
let
68-
json = parse(req.body)
69-
update = unmarshal(json, Update)
70-
await b.handleUpdate(update)
71-
await req.respond(Http200, "OK")
69+
try:
70+
let
71+
json = parse(req.body)
72+
update = unmarshal(json, Update)
73+
await b.handleUpdate(update)
74+
await req.respond(Http200, "OK\n")
75+
except:
76+
await req.respond(Http500, "FAIL\n")
7277
else:
73-
await req.respond(Http404, "Not Found")
78+
await req.respond(Http404, "Not Found\n")
7479

7580
var server = newAsyncHttpServer()
76-
waitFor server.serve(port=port.Port, callback=callback)
81+
d("Starting webhook, listens on port ", port.int)
82+
d("URL: ", url)
83+
waitFor server.serve(port=port, callback=callback)

0 commit comments

Comments
 (0)