Last active
June 29, 2020 20:56
-
-
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.
This file contains 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
__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