This commit is contained in:
Iyeoluwa Akinrinola
2025-05-16 15:52:20 +01:00
parent 1896298a18
commit 463923278a
2 changed files with 60 additions and 1 deletions
+35 -1
View File
@@ -321,6 +321,34 @@ async def get_config():
"available_models": list(model_service.AVAILABLE_MODELS.keys())
}
@app.get("/test-webhook")
async def test_webhook():
"""
Test the webhook registration.
Returns:
Webhook registration status.
"""
# Get the public URL of this service
service_url = f"http://{config.API_HOST}:{config.API_PORT}"
if config.PUBLIC_URL:
service_url = config.PUBLIC_URL
# Webhook URL
webhook_url = f"{service_url}/webhooks/channel-message"
# Try to register the webhook again
success = openwebui_channels.register_webhook(webhook_url)
# Get all registered webhooks
webhooks = openwebui_channels.get_webhooks()
return {
"webhook_url": webhook_url,
"registration_success": success,
"registered_webhooks": webhooks
}
# Model endpoints
@@ -586,7 +614,13 @@ async def channel_message_webhook(request: ChannelMessageWebhook):
Processing status.
"""
try:
print(f"Received channel message webhook: {request.channel_id}, {request.user_id}, {request.message}")
print("=" * 50)
print("WEBHOOK RECEIVED")
print(f"Channel ID: {request.channel_id}")
print(f"User ID: {request.user_id}")
print(f"Message: {request.message}")
print(f"Timestamp: {request.timestamp}")
print("=" * 50)
# Find the chat associated with this OpenWebUI channel
chat_id = None
+25
View File
@@ -271,5 +271,30 @@ class OpenWebUIChannels:
print(f"Error sending message to channel: {str(e)}")
return None
def get_webhooks(self) -> List[Dict[str, Any]]:
"""
Get all registered webhooks.
Returns:
List of webhook data.
"""
try:
# Make API request to get webhooks
response = requests.get(
f"{self.openwebui_url}/api/webhooks",
headers=self.headers,
timeout=30
)
if response.status_code == 200:
return response.json()
else:
print(f"Error getting webhooks: {response.status_code} - {response.text}")
return []
except Exception as e:
print(f"Error getting webhooks: {str(e)}")
return []
# Create a singleton instance
openwebui_channels = OpenWebUIChannels()