Hi,
I would like to only allow a few specific people to send commands to my bot. I was going to just filter messages and commands based on the chat_id. Is there a way I can have a RegexHandler filter out some commands or messages based on chat_id and discard them?
Something like this:
def filter_chat_id(bot, update):
if update.message.chat_id not in allowed_chat_ids:
# Stop here and skip all other handlers
updater = Updater(token)
dp = updater.dispatcher
dp.add_handler(RegexHandler('.*', filter_chat_id), group=1)
dp.add_handler(CommandHandler("help", help))
dp.add_handler(CommandHandler("status", status))
Or is there a better way to achieve this? I know I could just add a conditional inside every single handler that compares the chat_id but I think this is a bit messy and hoping there is a cleaner way.
Thanks!
Hi,
I would like to only allow a few specific people to send commands to my bot. I was going to just filter messages and commands based on the chat_id. Is there a way I can have a RegexHandler filter out some commands or messages based on chat_id and discard them?
Something like this:
Or is there a better way to achieve this? I know I could just add a conditional inside every single handler that compares the chat_id but I think this is a bit messy and hoping there is a cleaner way.
Thanks!