Add OpenWebUI bot integration for channels feature

This commit is contained in:
Iyeoluwa Akinrinola
2025-05-21 09:07:10 +01:00
parent 1c75eece93
commit 4ee0da8db6
8 changed files with 760 additions and 154 deletions
+33 -2
View File
@@ -216,12 +216,43 @@ async def start_bot(
for attempt in range(1, max_retries + 1):
try:
logger.info(f"Starting bot (attempt {attempt}/{max_retries})...")
bot_task = asyncio.create_task(custom_bot_main())
logger.info("Bot started successfully!")
# Define a monitoring task to restart the bot if it fails
async def monitor_bot_task():
global bot_task
try:
# Start the main bot task
main_task = asyncio.create_task(custom_bot_main())
# Wait for the task to complete or fail
try:
await main_task
logger.warning("Bot task completed unexpectedly")
except asyncio.CancelledError:
logger.info("Bot task was cancelled")
raise
except Exception as e:
logger.error(f"Bot task failed with error: {str(e)}")
logger.error(traceback.format_exc())
# Try to restart the bot
logger.info("Attempting to restart the bot...")
await asyncio.sleep(5) # Wait a bit before restarting
restart_task = asyncio.create_task(custom_bot_main())
bot_task = restart_task # Update the global task reference
logger.info("Bot restarted successfully")
except Exception as e:
logger.error(f"Error in monitor task: {str(e)}")
logger.error(traceback.format_exc())
# Start the monitoring task
bot_task = asyncio.create_task(monitor_bot_task())
logger.info("Bot started successfully with monitoring!")
return True
except Exception as e:
last_error = e
logger.error(f"Error starting bot (attempt {attempt}/{max_retries}): {str(e)}")
logger.error(traceback.format_exc())
if attempt < max_retries:
logger.info(f"Retrying in {retry_delay} seconds...")
await asyncio.sleep(retry_delay)