Last active
February 6, 2017 19:06
-
-
Save JosXa/ecb0df25d67a64ff3454bc4582d91245 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def uid_from_update(update): | |
""" | |
Extract the user id from update | |
:param update: `telegram.Update` | |
:return: user_id extracted from the update | |
""" | |
user_id = None | |
try: | |
user_id = update.message.from_user.id | |
except (NameError, AttributeError): | |
try: | |
user_id = update.inline_query.from_user.id | |
except (NameError, AttributeError): | |
try: | |
user_id = update.chosen_inline_result.from_user.id | |
except (NameError, AttributeError): | |
try: | |
user_id = update.callback_query.from_user.id | |
except (NameError, AttributeError): | |
logging.error("No chat_id available in update.") | |
return user_idchat_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment