conversation.py

 1import asyncio
 2from bale import Bot, Update, Message
 3from bale.handlers import CommandHandler
 4from bale.checks import Author, TEXT
 5
 6client = Bot(token="Your Token")
 7
 8@client.event
 9async def on_ready():
10    print(client.user, "is Ready!")
11
12@client.handle(CommandHandler('give_name_without_timeout'))
13async def conversation_handler(message: Message):
14    await message.reply('what is your name?')
15    received_update: Update = await client.wait_for(Author(message.author.id) & TEXT)
16    return await received_update.message.reply(f'Your name is {received_update.message.text}')
17
18@client.handle(CommandHandler('give_name_with_timeout'))
19async def conversation_handler_2(message: Message):
20    await message.reply('what is your name?')
21
22    try:
23        received_update: Update = await client.wait_for(Author(message.author.id) & TEXT, timeout=10.0)
24    except asyncio.TimeoutError:
25        return await message.chat.send('No response received; Therefore, the operation was canceled.')
26    else:
27        return await received_update.message.reply(f'Your name is {received_update.message.text}')
28
29client.run()