Project_id mandatory for Webhooks (#2232)
Co-authored-by: Deshraj Yadav <deshrajdry@gmail.com>
This commit is contained in:
@@ -525,7 +525,7 @@ class MemoryClient:
|
||||
raise NotImplementedError("Chat is not implemented yet")
|
||||
|
||||
@api_error_handler
|
||||
def get_webhooks(self, project_id: Optional[str] = None) -> Dict[str, Any]:
|
||||
def get_webhooks(self, project_id: str) -> Dict[str, Any]:
|
||||
"""Get webhooks configuration for the project.
|
||||
|
||||
Args:
|
||||
@@ -539,23 +539,19 @@ class MemoryClient:
|
||||
ValueError: If project_id is not set.
|
||||
"""
|
||||
|
||||
project_id = project_id or self.project_id
|
||||
|
||||
if not project_id:
|
||||
raise ValueError("project_id must be set to access webhooks")
|
||||
|
||||
response = self.client.get(f"api/v1/webhooks/{project_id}/webhook/")
|
||||
response.raise_for_status()
|
||||
capture_client_event("client.get_webhook", self)
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
def create_webhook(self, url: str, name: str, project_id: Optional[str] = None) -> Dict[str, Any]:
|
||||
def create_webhook(self, url: str, name: str, project_id: str, event_types: List[str]) -> Dict[str, Any]:
|
||||
"""Create a webhook for the current project.
|
||||
|
||||
Args:
|
||||
url: The URL to send the webhook to.
|
||||
name: The name of the webhook.
|
||||
event_types: List of event types to trigger the webhook for.
|
||||
|
||||
Returns:
|
||||
Dictionary containing the created webhook details.
|
||||
@@ -564,12 +560,8 @@ class MemoryClient:
|
||||
APIError: If the API request fails.
|
||||
ValueError: If project_id is not set.
|
||||
"""
|
||||
project_id = project_id or self.project_id
|
||||
|
||||
if not project_id:
|
||||
raise ValueError("project_id must be set to create webhook")
|
||||
|
||||
payload = {"url": url, "name": name}
|
||||
payload = {"url": url, "name": name, "event_types": event_types}
|
||||
response = self.client.post(f"api/v1/webhooks/{project_id}/webhook/", json=payload)
|
||||
response.raise_for_status()
|
||||
capture_client_event("client.create_webhook", self)
|
||||
@@ -577,15 +569,16 @@ class MemoryClient:
|
||||
|
||||
@api_error_handler
|
||||
def update_webhook(
|
||||
self, webhook_id: int, name: Optional[str] = None, url: Optional[str] = None, project_id: Optional[str] = None
|
||||
self, webhook_id: int, project_id: str, name: Optional[str] = None, url: Optional[str] = None, event_types: Optional[List[str]] = None
|
||||
) -> Dict[str, Any]:
|
||||
"""Update a webhook configuration.
|
||||
|
||||
Args:
|
||||
webhook_id: ID of the webhook to update
|
||||
project_id: The ID of the project to update the webhook for.
|
||||
name: Optional new name for the webhook
|
||||
url: Optional new URL for the webhook
|
||||
project_id: The ID of the project to update the webhook for.
|
||||
event_types: Optional list of event types to trigger the webhook for.
|
||||
|
||||
Returns:
|
||||
Dictionary containing the updated webhook details.
|
||||
@@ -594,19 +587,15 @@ class MemoryClient:
|
||||
APIError: If the API request fails.
|
||||
ValueError: If project_id is not set.
|
||||
"""
|
||||
project_id = project_id or self.project_id
|
||||
|
||||
if not project_id:
|
||||
raise ValueError("project_id must be set to update webhook")
|
||||
|
||||
payload = {k: v for k, v in {"name": name, "url": url}.items() if v is not None}
|
||||
payload = {k: v for k, v in {"name": name, "url": url, "event_types": event_types}.items() if v is not None}
|
||||
response = self.client.put(f"api/v1/webhooks/{project_id}/webhook/{webhook_id}/", json=payload)
|
||||
response.raise_for_status()
|
||||
capture_client_event("client.update_webhook", self, {"webhook_id": webhook_id})
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
def delete_webhook(self, webhook_id: int, project_id: Optional[str] = None) -> Dict[str, str]:
|
||||
def delete_webhook(self, webhook_id: int, project_id: str) -> Dict[str, str]:
|
||||
"""Delete a webhook configuration.
|
||||
|
||||
Args:
|
||||
@@ -620,10 +609,6 @@ class MemoryClient:
|
||||
APIError: If the API request fails.
|
||||
ValueError: If project_id is not set.
|
||||
"""
|
||||
project_id = project_id or self.project_id
|
||||
|
||||
if not project_id:
|
||||
raise ValueError("project_id must be set to delete webhook")
|
||||
|
||||
response = self.client.delete(f"api/v1/webhooks/{project_id}/webhook/{webhook_id}/")
|
||||
response.raise_for_status()
|
||||
@@ -975,11 +960,7 @@ class AsyncMemoryClient:
|
||||
raise NotImplementedError("Chat is not implemented yet")
|
||||
|
||||
@api_error_handler
|
||||
async def get_webhooks(self, project_id: Optional[str] = None) -> Dict[str, Any]:
|
||||
project_id = project_id or self.sync_client.project_id
|
||||
|
||||
if not project_id:
|
||||
raise ValueError("project_id must be set to access webhooks")
|
||||
async def get_webhooks(self, project_id: str) -> Dict[str, Any]:
|
||||
|
||||
response = await self.async_client.get(
|
||||
f"api/v1/webhooks/{project_id}/webhook/",
|
||||
@@ -989,14 +970,11 @@ class AsyncMemoryClient:
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
async def create_webhook(self, url: str, name: str, project_id: Optional[str] = None) -> Dict[str, Any]:
|
||||
project_id = project_id or self.sync_client.project_id
|
||||
|
||||
if not project_id:
|
||||
raise ValueError("project_id must be set to create webhook")
|
||||
async def create_webhook(self, url: str, name: str, project_id: str, event_types: List[str]) -> Dict[str, Any]:
|
||||
|
||||
payload = {"url": url, "name": name, "event_types": event_types}
|
||||
response = await self.async_client.post(
|
||||
f"api/v1/webhooks/{project_id}/webhook/", json={"url": url, "name": name}
|
||||
f"api/v1/webhooks/{project_id}/webhook/", json=payload
|
||||
)
|
||||
response.raise_for_status()
|
||||
capture_client_event("async_client.create_webhook", self.sync_client)
|
||||
@@ -1004,25 +982,17 @@ class AsyncMemoryClient:
|
||||
|
||||
@api_error_handler
|
||||
async def update_webhook(
|
||||
self, webhook_id: int, name: Optional[str] = None, url: Optional[str] = None, project_id: Optional[str] = None
|
||||
self, webhook_id: int,project_id: str, name: Optional[str] = None, url: Optional[str] = None, event_types: Optional[List[str]] = None
|
||||
) -> Dict[str, Any]:
|
||||
project_id = project_id or self.sync_client.project_id
|
||||
|
||||
if not project_id:
|
||||
raise ValueError("project_id must be set to update webhook")
|
||||
|
||||
payload = {k: v for k, v in {"name": name, "url": url}.items() if v is not None}
|
||||
payload = {k: v for k, v in {"name": name, "url": url, "event_types": event_types}.items() if v is not None}
|
||||
response = await self.async_client.put(f"api/v1/webhooks/{project_id}/webhook/{webhook_id}/", json=payload)
|
||||
response.raise_for_status()
|
||||
capture_client_event("async_client.update_webhook", self.sync_client, {"webhook_id": webhook_id})
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
async def delete_webhook(self, webhook_id: int, project_id: Optional[str] = None) -> Dict[str, str]:
|
||||
project_id = project_id or self.sync_client.project_id
|
||||
|
||||
if not project_id:
|
||||
raise ValueError("project_id must be set to delete webhook")
|
||||
async def delete_webhook(self, webhook_id: int, project_id: str) -> Dict[str, str]:
|
||||
|
||||
response = await self.async_client.delete(f"api/v1/webhooks/{project_id}/webhook/{webhook_id}/")
|
||||
response.raise_for_status()
|
||||
|
||||
Reference in New Issue
Block a user