grammyjs/conversations

@grammy/conversations v1.1.1 session parse error

sc0ch opened this issue · 3 comments

sc0ch commented

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.

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

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

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!