Skip to content

Instantly share code, notes, and snippets.

@JosXa
Last active February 6, 2017 19:06
Show Gist options
  • Save JosXa/ecb0df25d67a64ff3454bc4582d91245 to your computer and use it in GitHub Desktop.
Save JosXa/ecb0df25d67a64ff3454bc4582d91245 to your computer and use it in GitHub Desktop.
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