-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot_service.py
More file actions
33 lines (28 loc) · 972 Bytes
/
Copy pathbot_service.py
File metadata and controls
33 lines (28 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import requests
from colorama import init, Fore
from dotenv import load_dotenv
import findspark
findspark.init()
class BotService:
def __init__(self):
load_dotenv()
init(autoreset=True)
try:
self.BOT_TOKEN = os.getenv("BOT_TOKEN")
if self.validate_token(self.BOT_TOKEN):
print(Fore.GREEN + f"{self.bot_username} has successfully connected to telegram")
else:
print(Fore.RED + 'Invalid bot token')
except:
print(Fore.RED + 'please add your telegram bot token in the env file')
exit
def validate_token(self, bot_token):
url = f'https://api.telegram.org/bot{bot_token}/getMe'
response = requests.get(url)
data = response.json()
if response.status_code == 200 and data["ok"]:
self.bot_username = data["result"]['username']
return True
else:
return False