grammyjs/conversations

Loosing ctx.conversation after first conversation update

sc0ch opened this issue · 4 comments

sc0ch commented

Conversation function:

async function (conversation, ctx) {
console.log(ctx.conversation, 'first update')
// Ask the user for their home address.
await ctx.reply("Could you state your home address?");

    // Wait for the user to send their address:
    const userHomeAddressContext = await conversation.wait();

    console.log(ctx.conversation, 'second update')
    // Ask the user for their nationality.
    await ctx.reply("Could you also please state your nationality?");

    // Wait for the user to state their nationality:
    const userNationalityContext = await conversation.wait();

    console.log(ctx.conversation, 'third update')
    await ctx.reply(
      "That was the final step. Now that I have received all relevant information, I will forward them to our team for review. Thank you!",
    );

}

Console.log data:
[ First message to bot]
ConversationControls {
enter: [AsyncFunction (anonymous)],
[Symbol(conversations)]: {
ids: Set(1) { 'auth' },
session: [AsyncFunction (anonymous)]
}
} first update
... [ Second message to bot]
undefined first update
undefined second update
.. [ Third message to bot]
undefined first update
undefined second update
undefined third update

@grammyjs/conversations@1.1.1

This the the correct and intended behaviour. Why are you sharing this?

sc0ch commented

Because i'm can't enter to other conversation after any update in that.
What is the right way to do this?

You generally should not call enter when you're already inside a conversation. There's no point to that, because enter makes you enter a conversation when you're not inside one.

If you want to jump from one conversation to another, use regular JS function calls: https://grammy.dev/plugins/conversations.html#functions-and-recursion

Feel free to reopen if you have further questions.