AstraOS commited on
Commit
4f3ea19
·
verified ·
1 Parent(s): 5488580

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -15,8 +15,8 @@ app = FastAPI()
15
  # -------------------------------------------------------------------
16
  # Configuration & Global Variables
17
  # -------------------------------------------------------------------
18
- TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
19
- TELEGRAM_API_URL = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}"
20
 
21
  # Conversation state
22
  user_inputs = {}
@@ -119,7 +119,8 @@ def help_text():
119
  "*Stream Bot Help*\n\n"
120
  "*/start* - Begin setup for streaming (simple mode: only Input & Output URL)\n"
121
  "*/setting* - Enter advanced settings (Input URL, Quality Settings, Video Codec, Audio Codec, Output URL)\n"
122
- "*/help* - Display this help text\n\n"
 
123
  "After inputs are collected, press the inline *Start Streaming* button.\n\n"
124
  "While streaming, you can use inline buttons or commands:\n"
125
  "*/pause* - Pause the stream\n"
@@ -191,6 +192,19 @@ def live_log_updater(chat_id):
191
  except Exception as e:
192
  logging.error(f"Error in live log updater: {e}")
193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  # -------------------------------------------------------------------
195
  # Conversation Handlers
196
  # -------------------------------------------------------------------
@@ -488,6 +502,8 @@ async def telegram_webhook(request: Request):
488
  return handle_start(chat_id)
489
  elif text.startswith("/help"):
490
  return handle_help(chat_id)
 
 
491
  elif text.startswith("/pause"):
492
  return pause_stream(chat_id)
493
  elif text.startswith("/resume"):
 
15
  # -------------------------------------------------------------------
16
  # Configuration & Global Variables
17
  # -------------------------------------------------------------------
18
+ # TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
19
+ # TELEGRAM_API_URL = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}"
20
 
21
  # Conversation state
22
  user_inputs = {}
 
119
  "*Stream Bot Help*\n\n"
120
  "*/start* - Begin setup for streaming (simple mode: only Input & Output URL)\n"
121
  "*/setting* - Enter advanced settings (Input URL, Quality Settings, Video Codec, Audio Codec, Output URL)\n"
122
+ "*/help* - Display this help text\n"
123
+ "*/logs* - Show the log history\n\n"
124
  "After inputs are collected, press the inline *Start Streaming* button.\n\n"
125
  "While streaming, you can use inline buttons or commands:\n"
126
  "*/pause* - Pause the stream\n"
 
192
  except Exception as e:
193
  logging.error(f"Error in live log updater: {e}")
194
 
195
+ # -------------------------------------------------------------------
196
+ # Logs History Handler (/logs)
197
+ # -------------------------------------------------------------------
198
+ def logs_history(chat_id):
199
+ # Show the last 50 log lines in HTML format
200
+ log_text = "<pre>" + "\n".join(live_log_lines[-50:]) + "</pre>"
201
+ return {
202
+ "method": "sendMessage",
203
+ "chat_id": chat_id,
204
+ "text": log_text,
205
+ "parse_mode": "HTML"
206
+ }
207
+
208
  # -------------------------------------------------------------------
209
  # Conversation Handlers
210
  # -------------------------------------------------------------------
 
502
  return handle_start(chat_id)
503
  elif text.startswith("/help"):
504
  return handle_help(chat_id)
505
+ elif text.startswith("/logs"):
506
+ return logs_history(chat_id)
507
  elif text.startswith("/pause"):
508
  return pause_stream(chat_id)
509
  elif text.startswith("/resume"):