grammyjs / conversations

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

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

Closed sc0ch closed 8 months ago

sc0ch commented 8 months ago

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 ?

KnorpelSenf commented 8 months ago

What is your question?

KnorpelSenf commented 8 months ago

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

Neither, everything looks as expected

sc0ch commented 8 months ago

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

KnorpelSenf commented 8 months ago

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?

sc0ch commented 8 months ago

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

KnorpelSenf commented 8 months ago

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

KnorpelSenf commented 8 months ago

Docs: https://grammy.dev/plugins/conversations#functions-and-recursion

sc0ch commented 8 months ago

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