Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make update in webhook adapters a function #697

Open
Tracked by #675
KnorpelSenf opened this issue Dec 15, 2024 · 3 comments
Open
Tracked by #675

feat: make update in webhook adapters a function #697

KnorpelSenf opened this issue Dec 15, 2024 · 3 comments

Comments

@KnorpelSenf
Copy link
Member

Using a function instead of a property for update lets use fix #613

@KnorpelSenf KnorpelSenf mentioned this issue Dec 15, 2024
51 tasks
@shevernitskiy
Copy link
Contributor

shevernitskiy commented Jan 17, 2025

We can wrap update with Promise.allSettled in framework handlers and gracefully stop Update processing. Like:

update type:

Promise<[PromiseSettledResult<Update>]>
if (header !== secretToken) {
    await unauthorized();
    // TODO: investigate deno bug that happens when this console logging is removed
    console.log(handlerReturn);
    return handlerReturn;
}

const [updateData] = await update;
if (updateData.status === "rejected") {
    await badRequest();
    console.log(handlerReturn);
    return handlerReturn;
}

let usedWebhookReply = false;
const webhookReplyEnvelope: WebhookReplyEnvelope = {
    async send(json) {
        usedWebhookReply = true;
        await respond(json);
    },
};
await timeoutIfNecessary(
    bot.handleUpdate(updateData.value, webhookReplyEnvelope),
    typeof onTimeout === "function"
        ? () => onTimeout(...args)
        : onTimeout,
    timeoutMilliseconds,
);

Answer with bad request feels right, but we need to introduce this extra callback in every framework handler then.

As an alternative, we can make update type

Update

Most of handlers will remove Promise.resolve(). The rest will have to safely resolve promise like:

await c.req.json().catch(() => ({}))

then we can check it in webhookCallback by if (!update.update_id)

@KnorpelSenf
Copy link
Member Author

Is this related to the refactoring suggested in the issue description?

@shevernitskiy
Copy link
Contributor

Is this related to the refactoring suggested in the issue description?

Yep, will do a PQ an 5-10mins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants