grammyjs / examples

Examples to kickstart your journey with grammY.
https://grammy.dev/demo/examples
MIT License
130 stars 33 forks source link

Deno deploy example #49

Closed opimand closed 6 months ago

opimand commented 6 months ago

After deploying the bot on Deno Deploy, it works for a few hours and then requires sending an HTTP request to the webhook URL. I think this is not the behavior we expect.

KnorpelSenf commented 6 months ago

You are likely calling bot.start. That is incorrect. You cannot run a bot with polling on serverless platforms. Instead, you have to use webhooks as explained here: https://grammy.dev/guide/deployment-types#how-to-use-webhooks

opimand commented 6 months ago
import { serve } from "https://deno.land/std@0.154.0/http/server.ts";
import { bot } from "./bot.ts";
import { webhookCallback } from "./deps.deno.ts";

const handleUpdate = webhookCallback(bot, "std/http");

serve(async (req) => {
  if (req.method == "POST") {
    const url = new URL(req.url);
    if (url.pathname.slice(1) == bot.token) {
      try {
        return await handleUpdate(req);
      } catch (err) {
        console.error(err);
      }
    }
  }
  return new Response();
});

My code in server.ts is default with webhook, like in the example. And post request for webhook sent. And sure don't use API key somewhere second time

image
KnorpelSenf commented 6 months ago

My answer stays the same. The screenshot confirms that you are running the bot with polling somewhere. Do you call bot.start in bot.ts? https://grammy.dev/resources/faq#_409-conflict-terminated-by-other-getupdates-request

opimand commented 6 months ago

Thanks for your support. You are right.

KnorpelSenf commented 6 months ago

Glad It's fixed! 🎉