grammyjs/conversations

Conversations list after first context update via await conversation.wait()

Closed this issue · 8 comments

Versions
grammy: 1.21.1
@grammyjs/conversations: 1.2.0

To reproduce: Start the bot. Enter /start command and then any text.

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

const bot = new Bot('<YOUR_BOT_TOKEN>')

function one (conversation, ctx) {
  // Some function data
}

async function two (conversation, ctx) {
  console.log(ctx.conversation, 'Conversations list immidiately after enter')
  const newContext = await conversation.wait()
  console.log(newContext.conversation, 'Conversations list after context wait')
}

function three (conversation, ctx) {
  // Some function data
}

function four (conversation, ctx) {
  // Some function data
}

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

// Install the conversations plugin.
bot.use(conversations())

bot.use(createConversation(one))
bot.use(createConversation(two))
bot.use(createConversation(three))
bot.use(createConversation(four))

bot.command('start', (ctx) => ctx.conversation.enter('two'))

bot.start()

Behavior: four conversations before context update, and only two after (depends of order of processing on creation createConversation function in code):

ConversationControls {
  enter: [AsyncFunction (anonymous)],
  [Symbol(conversations)]: {
    ids: Set(4) { 'one', 'two', 'three', 'four' },
    session: [AsyncFunction (anonymous)]
  }
} Conversations list immidiately after enter

.... (Sending any to bot)

ConversationControls {
  enter: [AsyncFunction (anonymous)],
  [Symbol(conversations)]: {
    ids: Set(2) { 'one', 'two' },
    session: [AsyncFunction (anonymous)]
  }
} Conversations list after context wait

Expected behavior: list of all conversations:

Is it an issue, or i'm doing something wrong ?

What is your question?

Is it an issue, or i'm doing something wrong ?

Neither, everything looks as expected

How to get a list of all installed conversations inside active conversation after <context> update ?

There's no way to list installed conversations. You're logging internal data that is only accessible to the plugin. Why do you need that?

Sometimes, needs an ability to enter other conversation from current. It there another way ?

Yes. Just call await four(conversation, ctx).

Thank you so much. Can be closed. Went to read it.