Telebot listener
Project description
Installing
pip3 install -U tele-mod
Telemod
Message listener example
import asyncio
from telebot import async_telebot, types
from telemod import Listener
bot = async_telebot.AsyncTeleBot(token="")
loop = asyncio.get_event_loop()
listener = Listener(bot=bot, loop=loop)
@bot.message_handler(commands=["start"])
async def _(message: types.Message):
msg = await listener.listen_to(m=message, text="What's Your name?")
await bot.reply_to(msg, f"Your name is {msg.text}")
# to delete question message
# await bot.delete_message(chat_id=message.chat.id, message_id=msg.output.id)
async def main():
print((await bot.get_me()).first_name)
await bot.infinity_polling(skip_pending=True)
loop.run_until_complete(main())
CallbackQuery Listener Example
@bot.callback_query_handler(func = lambda query: True)
async def _(query: types.CallbackQuery):
if query.data == "name":
msg = await listener.listen_to(
query,
"What's your name?",
filters=["text"]
)
return await bot.reply_to(msg, f"Your name is {msg.text}")
Simple usage example
msg = await listener.listen(
chat_id=chat_id,
text="What's your name",
from_id=from_id,
filters=["text", "photo"]
)
print(msg)
Time out example
@bot.message_handler(commands=["start"])
async def start_handler(message: types.Message):
try:
msg = await listener.listen_to(message, "What's your name?", timeout=10)
except TimeOut:
msg = None
await bot.reply_to(message, "Time Out")
if msg:
return await bot.reply_to(msg, f"Hi {msg.text}")
Filters type example
@bot.message_handler(commands=["ask"], chat_types=["supergroup"])
async def _(message: types.Message):
msg = await listener.listen(
chat_id=message.chat.id,
text="What's your name",
filters=["sender_chat", "text"],
filters_type=2
) # will only listen to an message has "sender_chat" and "text" attribute
msg = await listener.listen(
chat_id=message.chat.id,
text="What's your name",
filters=["sender_chat", "text"],
filters_type=1
) # will listen to any messgae has "sender_chat" or "text" attribute
return await bot.reply_to(msg, msg.text)
Community
- Join To Our Channel: https://t.me/Y88F8
Examples
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tele-mod-2.5.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file tele-mod-2.5.tar.gz
.
File metadata
- Download URL: tele-mod-2.5.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69c6a9b0dd9392c4d2524fd324bc8872db775085ebff0231c390f476f66def35 |
|
MD5 | e96b04b6698d7dd70997a52e5df661de |
|
BLAKE2b-256 | 63176ad814959a0c1949c58ce18c31a61a271c2bd524ffe942ed62415ae35550 |
File details
Details for the file tele_mod-2.5-py3-none-any.whl
.
File metadata
- Download URL: tele_mod-2.5-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c53eea4010d22ea7f073091fadbaa611b8177e7b16fce50b8f0d4229a10e4b23 |
|
MD5 | c07ce050bde93cca7407671c8ebb282e |
|
BLAKE2b-256 | 35f7aaab98a6b3e7f7591eec606b34abe0e3ad3a4ec8e9c6b78961ac106ffa9d |