Update bot_telegram.py
Browse files- bot_telegram.py +17 -17
bot_telegram.py
CHANGED
|
@@ -53,16 +53,16 @@ class TelegramBot:
|
|
| 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 |
|
|
@@ -125,12 +125,12 @@ class TelegramBot:
|
|
| 125 |
await update.message.reply_text("❌ You are not authenticated. Please enter the password first.")
|
| 126 |
return
|
| 127 |
|
| 128 |
-
if not self.auth_token:
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
if not self.auth_token:
|
| 132 |
-
|
| 133 |
-
|
| 134 |
|
| 135 |
user_message = update.message.text
|
| 136 |
|
|
@@ -157,7 +157,7 @@ class TelegramBot:
|
|
| 157 |
bot_reply = response.json().get("answer", "I didn't understand that.")
|
| 158 |
elif response.status_code == 401:
|
| 159 |
logging.warning("Authorization expired. Re-authenticating...")
|
| 160 |
-
self.authenticate()
|
| 161 |
await self.chat_with_ai(update, context)
|
| 162 |
return
|
| 163 |
else:
|
|
@@ -178,12 +178,12 @@ class TelegramBot:
|
|
| 178 |
await update.message.reply_text("❌ You are not authenticated. Please enter the password first.")
|
| 179 |
return
|
| 180 |
|
| 181 |
-
if not self.auth_token:
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
if not self.auth_token:
|
| 185 |
-
|
| 186 |
-
|
| 187 |
|
| 188 |
document = update.message.document
|
| 189 |
if not document.file_name.endswith(('.xls', '.xlsx')):
|
|
@@ -228,7 +228,7 @@ class TelegramBot:
|
|
| 228 |
|
| 229 |
elif response.status == 401:
|
| 230 |
logging.warning("Authorization expired. Re-authenticating...")
|
| 231 |
-
self.authenticate()
|
| 232 |
await self.handle_excel(update, context)
|
| 233 |
else:
|
| 234 |
error_text = await response.text()
|
|
|
|
| 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 |
|
|
|
|
| 125 |
await update.message.reply_text("❌ You are not authenticated. Please enter the password first.")
|
| 126 |
return
|
| 127 |
|
| 128 |
+
# if not self.auth_token:
|
| 129 |
+
# self.authenticate()
|
| 130 |
+
#
|
| 131 |
+
# if not self.auth_token:
|
| 132 |
+
# await update.message.reply_text("Authentication failed. Please try again later.")
|
| 133 |
+
# return
|
| 134 |
|
| 135 |
user_message = update.message.text
|
| 136 |
|
|
|
|
| 157 |
bot_reply = response.json().get("answer", "I didn't understand that.")
|
| 158 |
elif response.status_code == 401:
|
| 159 |
logging.warning("Authorization expired. Re-authenticating...")
|
| 160 |
+
# self.authenticate()
|
| 161 |
await self.chat_with_ai(update, context)
|
| 162 |
return
|
| 163 |
else:
|
|
|
|
| 178 |
await update.message.reply_text("❌ You are not authenticated. Please enter the password first.")
|
| 179 |
return
|
| 180 |
|
| 181 |
+
# if not self.auth_token:
|
| 182 |
+
# self.authenticate()
|
| 183 |
+
#
|
| 184 |
+
# if not self.auth_token:
|
| 185 |
+
# await update.message.reply_text("Authentication failed. Please try again later.")
|
| 186 |
+
# return
|
| 187 |
|
| 188 |
document = update.message.document
|
| 189 |
if not document.file_name.endswith(('.xls', '.xlsx')):
|
|
|
|
| 228 |
|
| 229 |
elif response.status == 401:
|
| 230 |
logging.warning("Authorization expired. Re-authenticating...")
|
| 231 |
+
# self.authenticate()
|
| 232 |
await self.handle_excel(update, context)
|
| 233 |
else:
|
| 234 |
error_text = await response.text()
|