-
Notifications
You must be signed in to change notification settings - Fork 106
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
Add Deno.serveHttp
adapter for webhookCallback
#91
Conversation
This will have to wait until #61 is merged, which will largely refactor how adapters are organised. |
We'll wait. But what will be done to |
The API I desire is to have a bunch of framework adapters supported out of the box and accessible via simple string identifiers. If you're using some esoteric stuff that grammY doesn't support, you can still pass your own definition. I am still waiting for feedback on this.
What do you mean? |
Feedback on how adapters should work? |
I mean: will we support both |
Feedback on my suggestion that it's superfluous to expose 20 framework adapters when all you can do with them is to pass them to the same function. They shouldn't be accessible as objects. Continue this here: #61 (comment) |
They're different abstractions. Why not? |
Please resolve the conflicts. |
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct that this can be used without explicitly responding to the request manually? I'd expect the created callback to be able to handle this automatically, and if I understand correctly, that's the case.
Sorry, I don't understand you. What is the "this" in "this can be used"? |
Sorry for being ambiguous. Does this work? import {
Bot,
webhookCallback,
} from "https://raw.githubusercontent.com/rojserbest/grammY/main/src/mod.ts";
const bot = new Bot('') // <-- your bot token here;
const handleUpdate = webhookCallback(bot, "serveHttp");
bot.command("start", (ctx) => ctx.reply("Hi!"));
const server = Deno.listen({ port: 8000 });
for await (const conn of server) {
serveHttp(conn);
}
async function serveHttp(conn: Deno.Conn) {
const httpConn = Deno.serveHttp(conn);
for await (const requestEvent of httpConn) {
if (requestEvent.request.method == "POST") {
await handleUpdate(requestEvent);
}
}
} |
Sure it does. You can even test it fast using Deno deploy. |
So there's no reason you called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@all-contributors add @rojserbest for code |
I've put up a pull request to add @rojserbest! 🎉 |
But now you're still responding to the request twice, aren't you? Once inside the adapter, and once afterwards in the try block |
That line would make sense if someone sent a get request, so they would know that the server is running. After all, it's just an example and you can remove that line and it will still work. |
It will also run on POST requests |
Now it's good |
My bad, I'm lazy. |
No worries, just wanted to know if I understood it correctly |
Example usage: