Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise an exception if dialog with MessageInput is started with StartMode.NEW_STACK parameter #122

Open
t3m8ch opened this issue Jan 26, 2022 · 3 comments
Labels
core Something, that affects core functionality

Comments

@t3m8ch
Copy link
Contributor

t3m8ch commented Jan 26, 2022

If you start the dialog with MessageInput with StartMode.NEW_STACK, the messages are ignored by the bot, as if the dialog is not started.

from aiogram_dialog import Dialog, Window, DialogManager, DialogRegistry, StartMode
from aiogram_dialog.widgets.input import MessageInput
from aiogram_dialog.widgets.text import Const
from aiogram import Bot, Dispatcher
from aiogram.types import Message
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram.contrib.fsm_storage.memory import MemoryStorage

import asyncio
import logging
import os

TOKEN = os.getenv("TOKEN")


class DialogSG(StatesGroup):
    input_name = State()
    input_age = State()


async def on_input_name(msg: Message, dialog: Dialog, manager: DialogManager):
    manager.current_context().dialog_data["name"] = msg.text
    await dialog.next()


async def on_input_age(msg: Message, dialog: Dialog, manager: DialogManager):
    if not msg.text.isnumeric() or int(msg.text) < 0:
        await msg.answer("Not correct")
        return

    await msg.answer(
        f"Name: {manager.current_context().dialog_data['name']}]\n"
        f"Age: {msg.text}"
    )
    await manager.done()


dialog = Dialog(
    Window(
        Const("Input name"),
        MessageInput(on_input_name),
        state=DialogSG.input_name,
    ),
    Window(
        Const("Input age"),
        MessageInput(on_input_age),
        state=DialogSG.input_age
    ),
)


async def handler(msg: Message, dialog_manager: DialogManager):
    await dialog_manager.start(DialogSG.input_name, mode=StartMode.NEW_STACK)


async def main():
    logging.basicConfig(level=logging.INFO)
    storage = MemoryStorage()
    bot = Bot(token=TOKEN)
    dp = Dispatcher(bot, storage=storage)
    registry = DialogRegistry(dp)
    registry.register(dialog)
    dp.register_message_handler(handler, commands=["start"])

    await dp.start_polling()


if __name__ == "__main__":
    asyncio.run(main())

This behavior is due to the fact that MessageInput is used only in the stack by default. Using this widget with other stacks is unacceptable behavior, so an exception should be thrown so that the developer does not wonder why the bot ignores messages.

@Tishka17
Copy link
Owner

Not sure about exception, but could be a warning.
Also window switches might be also processed

@t3m8ch
Copy link
Contributor Author

t3m8ch commented Jan 26, 2022

Not sure about exception, but could be a warning. Also window switches might be also processed

The developer may not have logging enabled. Also, I'm not sure that this bot's behavior is not an error, which should throw an exception.

@Tishka17 Tishka17 added the core Something, that affects core functionality label Jan 29, 2022
@Tishka17
Copy link
Owner

Tishka17 commented Jul 3, 2022

in #164 inputs are supported via reply to message in non-default stack. Anyway we need at least on button there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Something, that affects core functionality
Projects
None yet
Development

No branches or pull requests

2 participants