cevheri commited on
Commit
d363e07
·
verified ·
1 Parent(s): d00c9a8

Update bot_telegram.py

Browse files
Files changed (1) hide show
  1. bot_telegram.py +23 -23
bot_telegram.py CHANGED
@@ -14,8 +14,8 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(
14
  BOT_TOKEN = os.getenv("BOT_TOKEN")
15
  BASE_URL = os.getenv("BASE_URL")
16
  HF_TOKEN = os.getenv("HF_TOKEN")
17
- API_USERNAME = os.getenv("API_USERNAME")
18
- API_PASSWORD = os.getenv("API_PASSWORD")
19
 
20
  # Set the secret password for authentication
21
  SECRET_PASSWORD = "secure123" # Change this to your desired password
@@ -32,9 +32,9 @@ class TelegramBot:
32
  """Initialize the bot with Telegram API token, API credentials, and authentication."""
33
  self.bot_token = bot_token
34
  self.base_url = base_url
35
- self.username = username
36
- self.password = password
37
- self.auth_token = None
38
 
39
  # API Endpoints
40
  self.login_url = f"{self.base_url}/api/v1/auth/login"
@@ -47,24 +47,24 @@ class TelegramBot:
47
 
48
  # Authenticate with API
49
  logging.info("Authenticating with API...")
50
- self.authenticate()
51
-
52
- def authenticate(self):
53
- """Authenticate with the API and retrieve an access token."""
54
- payload = {"username": self.username, "password": self.password}
55
- headers = {"Content-Type": "application/json", "accept": "application/json"}
56
-
57
- try:
58
- response = requests.post(self.login_url, headers=headers, json=payload)
59
-
60
- if response.status_code == 200:
61
- self.auth_token = response.json().get("access_token")
62
- logging.info("Successfully authenticated with API")
63
- else:
64
- logging.error(f"Authentication failed: {response.status_code} - {response.text}")
65
-
66
- except Exception as e:
67
- logging.error(f"Authentication Error: {e}")
68
 
69
  async def start_command(self, update: Update, context: CallbackContext):
70
  """Handles the /start command and asks for a password if the user is not authenticated."""
 
14
  BOT_TOKEN = os.getenv("BOT_TOKEN")
15
  BASE_URL = os.getenv("BASE_URL")
16
  HF_TOKEN = os.getenv("HF_TOKEN")
17
+ # API_USERNAME = os.getenv("API_USERNAME")
18
+ # API_PASSWORD = os.getenv("API_PASSWORD")
19
 
20
  # Set the secret password for authentication
21
  SECRET_PASSWORD = "secure123" # Change this to your desired password
 
32
  """Initialize the bot with Telegram API token, API credentials, and authentication."""
33
  self.bot_token = bot_token
34
  self.base_url = base_url
35
+ # self.username = username
36
+ # self.password = password
37
+ # self.auth_token = None
38
 
39
  # API Endpoints
40
  self.login_url = f"{self.base_url}/api/v1/auth/login"
 
47
 
48
  # Authenticate with API
49
  logging.info("Authenticating with API...")
50
+ # self.authenticate()
51
+
52
+ # def authenticate(self):
53
+ # """Authenticate with the API and retrieve an access token."""
54
+ # payload = {"username": self.username, "password": self.password}
55
+ # headers = {"Content-Type": "application/json", "accept": "application/json"}
56
+ #
57
+ # try:
58
+ # response = requests.post(self.login_url, headers=headers, json=payload)
59
+ #
60
+ # if response.status_code == 200:
61
+ # self.auth_token = response.json().get("access_token")
62
+ # logging.info("Successfully authenticated with API")
63
+ # else:
64
+ # logging.error(f"Authentication failed: {response.status_code} - {response.text}")
65
+ #
66
+ # except Exception as e:
67
+ # logging.error(f"Authentication Error: {e}")
68
 
69
  async def start_command(self, update: Update, context: CallbackContext):
70
  """Handles the /start command and asks for a password if the user is not authenticated."""