[2ff88f42] Full End-to-End integration: Webhooks, Auto-Enrichment, Notion-Sync, UI updates and new Connector Architecture
This commit is contained in:
60
connector-superoffice/register_webhook.py
Normal file
60
connector-superoffice/register_webhook.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import sys
|
||||
import os
|
||||
from superoffice_client import SuperOfficeClient
|
||||
|
||||
# Configuration
|
||||
WEBHOOK_NAME = "Gemini Connector Hook"
|
||||
TARGET_URL = "https://floke-ai.duckdns.org/connector/webhook?token=changeme" # Token match .env
|
||||
EVENTS = [
|
||||
"contact.created",
|
||||
"contact.changed",
|
||||
"person.created",
|
||||
"person.changed"
|
||||
]
|
||||
|
||||
def register():
|
||||
print("🚀 Initializing SuperOffice Client...")
|
||||
try:
|
||||
client = SuperOfficeClient()
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to connect: {e}")
|
||||
return
|
||||
|
||||
print("🔎 Checking existing webhooks...")
|
||||
webhooks = client._get("Webhook")
|
||||
|
||||
if webhooks and 'value' in webhooks:
|
||||
for wh in webhooks['value']:
|
||||
if wh['Name'] == WEBHOOK_NAME:
|
||||
print(f"⚠️ Webhook '{WEBHOOK_NAME}' already exists (ID: {wh['WebhookId']}).")
|
||||
|
||||
# Check if URL matches
|
||||
if wh['TargetUrl'] != TARGET_URL:
|
||||
print(f" ⚠️ URL Mismatch! Deleting old webhook...")
|
||||
# Warning: _delete is not implemented in generic client yet, skipping auto-fix
|
||||
print(" Please delete it manually via API or extend client.")
|
||||
return
|
||||
|
||||
print(f"✨ Registering new webhook: {WEBHOOK_NAME}")
|
||||
payload = {
|
||||
"Name": WEBHOOK_NAME,
|
||||
"Events": EVENTS,
|
||||
"TargetUrl": TARGET_URL,
|
||||
"Secret": "changeme", # Used for signature calculation by SO
|
||||
"State": "Active",
|
||||
"Type": "Webhook"
|
||||
}
|
||||
|
||||
try:
|
||||
# Note: _post is defined in your client, returns JSON
|
||||
res = client._post("Webhook", payload)
|
||||
if res and "WebhookId" in res:
|
||||
print(f"✅ SUCCESS! Webhook created with ID: {res['WebhookId']}")
|
||||
print(f" Target: {res['TargetUrl']}")
|
||||
else:
|
||||
print(f"❌ Creation failed. Response: {res}")
|
||||
except Exception as e:
|
||||
print(f"❌ Error during registration: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
Reference in New Issue
Block a user