multi bot webhook only use WebhookHTTPServeMux #269
tonyhorton
started this conversation in
Ideas
Replies: 2 comments 4 replies
-
core code: func(handler TGBotAPI.WebhookHandler) error {
return func(handler TGBotAPI.WebhookHandler) error {
BotWebhookServerRouter.POST(fmt.Sprintf("/bot_%d", botConfig.BotID), func(ctx *fasthttp.RequestCtx) {
// 验证 Secret Token
if BotsList[botID].SecretToken() != "" && BotsList[botID].SecretToken() != string(ctx.Request.Header.Peek(TGBotAPI.WebhookSecretTokenHeader)) {
ctx.SetStatusCode(fasthttp.StatusUnauthorized)
return
}
if err := handler(ctx, ctx.PostBody()); err != nil {
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
return
}
ctx.SetStatusCode(fasthttp.StatusOK)
})
return nil
}(handler)
}, |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yep, fasthttp can be used for multibot webhooks too, I just didn't add this example because pure fasthttp requires router (https://github.com/fasthttp/router or https://github.com/gofiber/fiber) to be used, I guess it still will be usefull to add that example |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Document cases can only use ServeMux of the standard library, and use fastthttp to achieve the same function. Therefore, with the appearance of the following code, it can continue to use fastthttp and support multi_bot_webhook while supporting multi_bot_webhook.
I implemented a method myself, which can then use fastthttp as the webhook server and supports multiplexed handlers(The code is handwritten for extracting key parts. The actual project structure is too complex. The following code is for reference only):
Beta Was this translation helpful? Give feedback.
All reactions