Skip to content

Instantly share code, notes, and snippets.

@VycktorStark
Last active June 29, 2020 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VycktorStark/58454ddafe9ff0444332c69606aafbfc to your computer and use it in GitHub Desktop.
Save VycktorStark/58454ddafe9ff0444332c69606aafbfc to your computer and use it in GitHub Desktop.
An example function to analyze if the ID defined in it, left the chat blocked for the bot to send new messages.
__author__ = "Vycktor Stark"
import requests, os
token = os.environ['SECRET_KEY'] #Defining bot token (This information can be loaded in another way)
apitelegram = f"https://api.telegram.org/bot{token}" #Defining api of telegram (This information can be loaded in another way)
def checkchat(idchat):
"""
This function was created to analyze if the defined ID when it is called,
has the chat blocked for the bot or not.
"""
data = requests.post(f"{apitelegram}/sendChatAction", params={"chat_id":idchat,"action":'typing'},
headers={'content-type': 'application/json', 'Cache-Control': 'no-cache'})
if (data.status_code == 200):
return True
else:
return False
# Example of how to call the function:
print(checkchat(idchat=884431779))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment