grammyjs / conversations

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

@grammy/conversations v1.1.1 session parse error #73

Closed sc0ch closed 1 year ago

sc0ch commented 1 year ago

Reprocude:

import { Bot, session } from "grammy" import { conversations, createConversation } from '@grammyjs/conversations' const token = 'XXXXXXXXXXXXXXXXXXXXXXX' const bot = new Bot(token) function initial() { return { } } bot.use(session({ initial })) bot.use(conversations()) let c = async function (conversation, ctx) { await ctx.reply("Some message"); const { message } = await conversation.waitFrom(ctx.from) console.log(message) } bot.use(createConversation(c)) bot.on('message', ctx => { ctx.conversation.enter('c') }) bot.start()

After any message to bot i've got:

/data/____/node_modules/@grammyjs/conversations/out/conversation.js:357 if (session.conversation[id].length === 0) { ^

TypeError: Cannot read properties of undefined (reading 'length') at ctx.conversation.enter (/data/____/node_modules/@grammyjs/conversations/out/conversation.js:357:46) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

OS: Ubuntu 22.04 LTS NodeJS: 19.7.0 Grammy: 1.15.2

@grammy/conversations v1.0.3 - have not that issue.

KnorpelSenf commented 1 year ago

Could you format the source as TypeScript code and not as a heading?

Do you use a storage adapter?

You're missing an await when you enter the conversation. This is incorrect. Does adding this await fix the problem already?

sc0ch commented 1 year ago

Yep... forgot await, sorry. False issue, please close it.

KnorpelSenf commented 1 year ago

You're not the first one to forget this. I'll think about how to detect and prevent such mistakes library-side. Glad it's fixed!