grammyjs/conversations

Conversation doesn't end when maxMillisecondsToWait reaches timeout when use waitFor('message:text')

Opened this issue · 2 comments

This simple echo bot works: you type /start, bot sends you hello, you type hello, bot sends you hello, when you type hello again, bot didn't answer

node 18.18.0
grammy 1.19.0
conversations 1.1.2

snippet to reproduce the bag:

import { Bot, session } from 'grammy';
import { conversations, createConversation } from '@grammyjs/conversations';

const token = '';
const bot = new Bot(token);

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

bot.use(conversations());

bot.use(createConversation(async (conversation, ctx) => {
        await ctx.reply('hello');
        ctx = await conversation.waitFor('message:text'); // Don't stops here
        await ctx.reply(ctx.msg.text);
        ctx = await conversation.wait(); // Stops here
        await ctx.reply(ctx.msg.text);
}, {
        id: 'default',
        maxMillisecondsToWait: 0,
}));

bot.command('start', (ctx) => {
        return ctx.conversation.enter('default');
});

bot.start();

if you pass { maxMilliseconds: 0 } to waitFor(), it works

i think at this line missing default value for maxMilliseconds

const { otherwise, drop, maxMilliseconds } = toObj(opts);

       const { otherwise, drop, maxMilliseconds = this.timeout } = toObj(opts);