grammyjs / conversations

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

Unexpected operation performed during replay after rejecting an external function #7

Closed x066it closed 2 years ago

x066it commented 2 years ago
import { Bot, session } from "grammy";
import { conversations, createConversation } from "@grammyjs/conversations";

const bot = new Bot();

bot.use(session({ initial: () => ({}) }));
bot.use(conversations());
bot.use(
    createConversation(async (conversation, ctx) => {
        console.debug("Received /start");
        await ctx.reply(`Entered conversation`);
        await conversation.wait();
        await conversation.external({
            task: () => Promise.reject("fail"),
        });
    }, "start")
);

bot.command("start", async (ctx) => await ctx.conversation.enter("start"));

bot.catch((err) => console.error(err?.error || err));
bot.start();

Expected log when sending '/start' many times:

Received /start
fail
Received /start
fail
but got this:

```js Received /start Received /start fail Received /start Error: Unexpected operation performed during replay (expected 'wait' but was 'ext')! It looks like the conversation builder function is non-deterministic, or it relies on external data sources. at ConversationHandle._replayOp (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.1_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:301:19) at ConversationHandle.external (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.1_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:427:41) at file:///home/chaotik/git/trontrack/mre.js:13:22 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async run (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.1_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:126:13) at async runUntilComplete (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.1_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:175:26) at async /home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.1_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:225:26 at async /home/chaotik/git/trontrack/node_modules/.pnpm/grammy@1.8.3/node_modules/grammy/out/composer.js:61:13 at async /home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.1_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:142:9 at async /home/chaotik/git/trontrack/node_modules/.pnpm/grammy@1.8.3/node_modules/grammy/out/composer.js:61:13 Received /start Error: Unexpected operation performed during replay (expected 'wait' but was 'ext')! It looks like the conversation builder function is non-deterministic, or it relies on external data sources. Node.js v17.7.1 ```

KnorpelSenf commented 2 years ago

I have a vague idea what could be the issue, I'll look into it soon:tm:

KnorpelSenf commented 2 years ago

@x066it can you review #8?

x066it commented 2 years ago

@KnorpelSenf Now after first fail it starts failing immidiately after each invoking /start, not waiting for user reply in the middle of conversation. I don't think it should be like this.

Received /start
Received /start
fail
Received /start
fail
Received /start
fail
Received /start
fail