I'm developing a telegram bot using the python library (telegram.ext) and I need that my bot accepts only the employees of my company. I do not want to use an authorization based on username, first/last name or chat_id, because in that way I have to add in the authorized list every new user, but I want to use some kind of password/keyword someone need to enter, before being able to use any command in the bot. The conversation flow would be like:
@Companybot:Welcome to the company bot, please enter your password!
@Employee: 12345test!
@CompanyBot: Password accepted! Please select a command from the command list!
I'm running the bot from my pc right now, not using any hosting service.
I tried to search in the internet for a solution but it seems that I'm asking the wrong questions, because I didn't find anything that could help me.
Thanks everybody for your help!
EDIT:
what i've tried is reported on https://github.com/python-telegram-bot/python-telegram-bot/wiki/Code-snippets#restrict-access-to-a-handler-decorator. This is the code I wrote:
def start(update, context):
chat_id = update.message.chat_id
first_name =update.message.chat.first_name
last_name = update.message.chat.last_name
username = update.message.chat.username
print("chat_id : {} and firstname : {} lastname : {} username {}". format(chat_id, first_name, last_name , username))
context.bot.send_message(chat_id, 'Ciao ' + first_name + 'text')
LIST_OF_ADMINS = [592769136]
def restricted(func):
@wraps(func)
def wrapped(update, context):
user_id = update.effective_user.id
if user_id not in LIST_OF_ADMINS:
print("Unauthorized access denied for {}.".format(user_id))
return
return func(update, context)
return wrapped
def main():
#updater (aggioramento):
updater = Updater(token=token, use_context=True)
#dispatcher (distribuzione aggiornamento):
dispatcher = updater.dispatcher
#lista di comandi da distribuire, ripresi dalle funzioni descritte all'inizio:
@restricted
start_handler = CommandHandler('start', start) # il comando è il primo termine, la funzione il secondo
dispatcher.add_handler(start_handler)
#comando per accendere il bot:
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
When I run the script, I get this error:
File "bot.py", line 88
start_handler = CommandHandler('start', start) # il comando è il primo termine, la funzione il secondo
^
SyntaxError: invalid syntax
Because, it doesn't recognize the wrapper.
This is the only method I tried, I didn't find any other option.