Telegraf-Test icon indicating copy to clipboard operation
Telegraf-Test copied to clipboard

Cannot test when using multiple Scenes

Open mbernardes19 opened this issue 4 years ago • 1 comments

I have a bot made with Telegraf that works in this way:

When bot receives any message -> Show list of commands (default message)

When bot receives /start command -> Enters a Scene -> Sends 2 messages one after another -> Enters another Scene -> Then send another message that expects a reply.

That reply is the user's payment method. Based on that, I wrote this test:

    it('listens to payment method answer', async () => {
        const r = await test.sendMessage({text: '/start', entities: [{type: 'bot_command', offset: 0, length: 6}]})
        const response = await test.sendMessageWithText('cartao')
        expect(response.data.text).toBe('Certo!')
    })

But when I run this test, I actually receive as result that response.data.text brought the list of commands (default message) instead of the answer for the reply.

It seems that the test doesn't keep the state of the conversation (the Scene), so every sendMessageWithText is as if I was starting a new conversation every time.

Is there a way to keep that conversation state in the API? Or do we need to implement it?

mbernardes19 avatar Nov 25 '20 19:11 mbernardes19