grammyjs/conversations

Error with conversation.external crash the bot

FernandoTBarros opened this issue · 4 comments

When calling waitFor or conversation.form after conversation.external the bot simply crash with no errors.

This code will reproduce this error:

require('dotenv').config();
import { Conversation, ConversationFlavor, conversations, createConversation } from "@grammyjs/conversations";
import { Bot, Context, session } from "grammy";

const BOT_TOKEN = process.env.BOT_TOKEN;

export type MyContext = Context & ConversationFlavor;

async function greeting(conversation: Conversation<MyContext>, ctx: MyContext) {
  const response = await conversation.external(() => Promise.resolve('ok'));
  conversation.log(response);
  const codigo = await conversation.form.text();
  conversation.log(codigo);
}

const bot = new Bot<MyContext>(BOT_TOKEN!);

bot.use(session({
  initial: () => ({}),
}));

// Install the conversations plugin.
bot.use(conversations());
bot.use(createConversation(greeting));

// Handle the /start command.
bot.command("start", async (ctx) => await ctx.conversation.enter("greeting"));
bot.catch((err) => {
  console.error(err);
});
// Start the bot.
bot.start();

console.log("Bot running...")

I cannot reproduce this. The above code works correctly for me. However, a different bug was fixed in #40 so now conversation.external crashes less often. Could you try out the new release and see if this is fixed? In that case, please consider closing this issue.

Closing due to inactivity. Feel free to comment or reopen if this is still an issue.

Sorry for the delay.
It's fixed now, I was able to test it and it works now.

Great to hear! Thanks for confirming!