grammyjs / conversations

Conversational interfaces for grammY.
https://grammy.dev/plugins/conversations
MIT License
44 stars 17 forks source link

Request timeout on Supabase Edge Functions #101

Open hoching87 opened 3 months ago

hoching87 commented 3 months ago

Simply installing the plugin on Supabase will cause it to load indefinitely on each request and throw no error. It was working before until recently I think.

Sample code for reproduction :

console.log(`Function "telegram-bot" up and running!`);

import {
  Bot,
  Context,
  session,
  webhookCallback,
} from "https://deno.land/x/grammy@v1.21.1/mod.ts";
import {
  type ConversationFlavor,
  conversations,
} from "https://deno.land/x/grammy_conversations@v1.2.0/mod.ts";

type MyContext = Context & ConversationFlavor;
const bot = new Bot<MyContext>(Deno.env.get("BOT_TOKEN") || "");

// Install the session plugin.
bot.use(session({
  initial() {
    // return empty object for now
    return {};
  },
}));

// Install the conversations plugin.
bot.use(conversations()); // comment this line and the whole app works fine

bot.command("start", (ctx) => ctx.reply("Welcome! Up and running."));

bot.command("ping", (ctx) => ctx.reply(`Pong! ${new Date()} ${Date.now()}`));

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

Deno.serve(async (req) => {
  try {
    return await handleUpdate(req);
  } catch (err) {
    console.error(err);
  }
});
KnorpelSenf commented 3 months ago

Is this the exact code you used? You didn't add a storage adapter or anything before deployment?

hoching87 commented 3 months ago

This is just some sample code I was try with to test and see if it was really the conversation plugin that was faulty. I had been using the plugin and was working fine until now. I am not sure what the problems was or what had changed but removing the conversation plugin seem to be the fix.

I had try to add some storage adapter and it still not working. I tested with both Supabase and RAM adapter.

const storage = supabaseAdapter({
  supabase,
  table: "bot_session", // table name
});
// Install the session plugin.
bot.use(session({
  initial() {
    // return empty object for now
    return {};
  },
  storage,
  //   storage: new MemorySessionStorage(),
}));
KnorpelSenf commented 3 months ago

I'll take that as a yes. Does that same code work locally?

chingiz19 commented 1 month ago

I have exactly the same issue. Script above pasted by @hoching87 works fine if you run it locally with deno, but not on supabase (supabase also has local development setup).

Simply running it with deno run --allow-read --allow-write --allow-env --allow-net --allow-run scripts/test.ts works.

Having said that there is still a type mismatch after new grammy version.