@devries-cameron20 / composio Mirror · read-only / commits / 37a0e0ac8
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 23, 00:30 UTC

hot fix triggers

Rahul Tarak committed Jun 18, 2025 at 21:00 UTC 37a0e0ac83b8221ac08c965d75118af3f0dd93df
1 file changed +28 -31
python/composio/core/models/triggers.py
+28 -31
@@ -317,12 +317,6 @@ class _SubcriptionBuilder(WithLogger):
317 class Triggers(Resource):
318 """Triggers (instance) class"""
319
320 - enable: t.Callable
321 - """Enables a trigger given its id"""
322 -
323 - disable: t.Callable
324 - """Disables a trigger given its id"""
325 -
320 def __init__(self, client: HttpClient):
321 """
322 Initialize the triggers resource.
@@ -332,15 +326,24 @@ class Triggers(Resource):
326 self._client = client
327 self.list_enum = self._client.triggers_types.retrieve_enum
328 self.list = self._client.triggers_types.list
335 - self.delete = self._client.trigger_instances.manage.delete
329 self.get_type = self._client.triggers_types.retrieve
337 - self.enable = functools.partial(
338 - self._client.trigger_instances.manage.update,
330 +
331 + def delete(self, trigger_id: str):
332 + """Delete a trigger instance by ID"""
333 + return self._client.trigger_instances.remove_upsert(slug=trigger_id)
334 +
335 + def enable(self, trigger_id: str):
336 + """Enable a trigger instance by ID"""
337 + return self._client.trigger_instances.update_status(
338 status="enable",
339 + slug=trigger_id,
340 )
341 - self.disable = functools.partial(
342 - self._client.trigger_instances.manage.update,
341 +
342 + def disable(self, trigger_id: str):
343 + """Disable a trigger instance by ID"""
344 + return self._client.trigger_instances.update_status(
345 status="disable",
346 + slug=trigger_id,
347 )
348
349 def list_active(
@@ -410,10 +413,21 @@ class Triggers(Resource):
413 :return: The trigger instance
414 """
415 if user_id is not None:
413 - connected_account_id = self._get_connected_account_for_user(
414 - trigger=slug,
415 - user_id=user_id,
416 + connected_account_id = self.get_type(slug=slug).toolkit.name
417 + connected_accounts = self._client.connected_accounts.list(
418 + toolkit_slugs=[connected_account_id]
419 )
420 + if len(connected_accounts.items) == 0:
421 + raise exceptions.NoItemsFound(
422 + f"No connected accounts found for {slug}"
423 + )
424 +
425 + account, *_ = sorted(
426 + connected_accounts.items,
427 + key=lambda x: x.created_at,
428 + reverse=True,
429 + )
430 + connected_account_id = account.id
431
432 if connected_account_id is None:
433 raise exceptions.InvalidParams(
@@ -426,23 +440,6 @@ class Triggers(Resource):
440 body_trigger_config_1=trigger_config or self._client.not_given,
441 )
442
429 - def _get_connected_account_for_user(self, trigger: str, user_id: str) -> str:
430 - toolkit = self.get_type(slug=trigger).toolkit.name
431 - connected_accounts = self._client.connected_accounts.list(
432 - toolkit_slugs=[toolkit]
433 - )
434 - if len(connected_accounts.items) == 0:
435 - raise exceptions.NoItemsFound(
436 - f"No connected accounts found for {trigger} and {user_id}"
437 - )
438 -
439 - account, *_ = sorted(
440 - connected_accounts.items,
441 - key=lambda x: x.created_at,
442 - reverse=True,
443 - )
444 - return account.id
445 -
443 def subscribe(self, timeout: float = 15.0) -> TriggerSubscription:
444 """
445 Subscribe to a trigger and receive trigger events.