Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(blocks): add a generic webhook block (#9584)

Nicholas Tindled879df062ec9
diff --git a/autogpt_platform/backend/backend/blocks/generic_webhook/triggers.py b/autogpt_platform/backend/backend/blocks/generic_webhook/triggers.py
new file mode 100644
index 0000000000..1c9d37dd83
--- /dev/null
+++ b/autogpt_platform/backend/backend/blocks/generic_webhook/triggers.py
@@ -0,0 +1,51 @@
+from backend.data.block import (
+ Block,
+ BlockCategory,
+ BlockManualWebhookConfig,
+ BlockOutput,
+ BlockSchema,
+)
+from backend.data.model import SchemaField
+from backend.integrations.providers import ProviderName
+from backend.integrations.webhooks.generic import GenericWebhookType
+
+
+class GenericWebhookTriggerBlock(Block):
+ class Input(BlockSchema):
+ payload: dict = SchemaField(hidden=True, default={})
+ constants: dict = SchemaField(
+ description="The constants to be set when the block is put on the graph",
+ default={},
+ )
+
+ class Output(BlockSchema):
+ payload: dict = SchemaField(
+ description="The complete webhook payload that was received from the generic webhook."
+ )
+ constants: dict = SchemaField(
+ description="The constants to be set when the block is put on the graph"
+ )
+
+ example_payload = {"message": "Hello, World!"}
+
+ def __init__(self):
+ super().__init__(
+ id="8fa8c167-2002-47ce-aba8-97572fc5d387",
+ description="This block will output the contents of the generic input for the webhook.",
+ categories={BlockCategory.INPUT},
+ input_schema=GenericWebhookTriggerBlock.Input,
+ output_schema=GenericWebhookTriggerBlock.Output,
+ webhook_config=BlockManualWebhookConfig(
+ provider=ProviderName.GENERIC_WEBHOOK,
+ webhook_type=GenericWebhookType.PLAIN,
+ ),
+ test_input={"constants": {"key": "value"}, "payload": self.example_payload},
+ test_output=[
+ ("constants", {"key": "value"}),
+ ("payload", self.example_payload),
+ ],
+ )
+
+ def run(self, input_data: Input, **kwargs) -> BlockOutput:
+ yield "constants", input_data.constants
+ yield "payload", input_data.payload
diff --git a/autogpt_platform/backend/backend/integrations/providers.py b/autogpt_platform/backend/backend/integrations/providers.py
index eb1f513c2e..bf409b68d3 100644
--- a/autogpt_platform/backend/backend/integrations/providers.py
+++ b/autogpt_platform/backend/backend/integrations/providers.py
@@ -11,6 +11,7 @@ class ProviderName(str, Enum):
E2B = "e2b"
EXA = "exa"
FAL = "fal"
+ GENERIC_WEBHOOK = "generic_webhook"
GITHUB = "github"
GOOGLE = "google"
GOOGLE_MAPS = "google_maps"
diff --git a/autogpt_platform/backend/backend/integrations/webhooks/__init__.py b/autogpt_platform/backend/backend/integrations/webhooks/__init__.py
index b3b64ee270..b1774aa3fd 100644
--- a/autogpt_platform/backend/backend/integrations/webhooks/__init__.py
+++ b/autogpt_platform/backend/backend/integrations/webhooks/__init__.py
@@ -13,6 +13,7 @@ def load_webhook_managers() -> dict["ProviderName", type["BaseWebhooksManager"]]
return _WEBHOOK_MANAGERS
from .compass import CompassWebhookManager
+ from .generic import GenericWebhooksManager
from .github import GithubWebhooksManager
from .slant3d import Slant3DWebhooksManager
@@ -23,6 +24,7 @@ def load_webhook_managers() -> dict["ProviderName", type["BaseWebhooksManager"]]
CompassWebhookManager,
GithubWebhooksManager,
Slant3DWebhooksManager,
+ GenericWebhooksManager,
]
}
)
diff --git a/autogpt_platform/backend/backend/integrations/webhooks/generic.py b/autogpt_platform/backend/backend/integrations/webhooks/generic.py
new file mode 100644
index 0000000000..d5308417e8
--- /dev/null
+++ b/autogpt_platform/backend/backend/integrations/webhooks/generic.py
@@ -0,0 +1,29 @@
+import logging
+
+from fastapi import Request
+from strenum import StrEnum
+
+from backend.data import integrations
+from backend.integrations.providers import ProviderName
+
+from ._manual_base import ManualWebhookManagerBase
+
+logger = logging.getLogger(__name__)
+
+
+class GenericWebhookType(StrEnum):
+ PLAIN = "plain"
+
+
+class GenericWebhooksManager(ManualWebhookManagerBase):
+ PROVIDER_NAME = ProviderName.GENERIC_WEBHOOK
+ WebhookType = GenericWebhookType
+
+ @classmethod
+ async def validate_payload(
+ cls, webhook: integrations.Webhook, request: Request
+ ) -> tuple[dict, str]:
+ payload = await request.json()
+ event_type = GenericWebhookType.PLAIN
+
+ return payload, event_type