Skip to content
This repository was archived by the owner on Oct 21, 2023. It is now read-only.
This repository was archived by the owner on Oct 21, 2023. It is now read-only.

Sessions with async functions does not works #27

@nightSamurai

Description

@nightSamurai

Hi everyone!

I uses Telegraf + Redis-session + Stage in my bot. But session doesn't works with Promise

This very similar like this issues ( 1, 2, 3, 4 ), but nothing was helpful for me

Into my scene on "enter" event i try to set something like this: ctx.scene.state.{key} = {value}. And this work fine only if use it without promise or async function. For example:

export const scene = new BaseScene(MY_SCENE)

// My enter scene logic
scene.enter(async (ctx) => {
    // this works
    ctx.scene.state.number = 1 
    
    // this set value into a state variable, but NOT save it in sessions
    ctx.scene.state.promise = await (
        new Promise<number>((resolve, reject) => {
            setTimeout(() => {
                resolve(1)
            }, 1000)
        })
    )

    console.log( ctx.scene.state )
    // output { number: 1, promise: 1 }


    // another code here...
})

// on any of event type will be the same behavior
scene.on('message', (ctx) => {
    console.log(
        ctx.scene.state
    )
    // output { number: 1 }
    // expected to be { number: 1, promise: 1 }
})

So, maybe exists the way, to trigger sync process? Or some utility function for force update the session?

I will be glad of any help, thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions