Skip to main content
Chris Stanley

Webhooks with Responses

We’re excited to announce the release of Response Webhooks, our most highly requested feature over the past few months. Developers can now directly call API endpoints in Patterns to execute workflows, and get the resulting response from those workflows all in a single HTTP request. This unlocks major use cases such as calling Patterns directly from a client app. Now you can build a chat interface in React and leverage Patterns as your agent-based GPT backend.

One of the most common use cases for Patterns is to integrate with external systems. Before Response Webhooks, if developers wanted to call an endpoint, execute a workflow, and get a response they’d have to POST to a webhook and setup a callback URL to ingest the response. This works well for some use cases but not for others, now with Response Webhooks, you can call Patterns directly and wait for a response synchronously.

Using Response Webhooks

resp webhook Link to docs

There are now two types of webhooks you can use in Patterns depending on your use case. The first type is an ingest only webhook that will return immediately with an empty response body after calling it. The second is an ingest and respond webhook. When you call an ingest and respond endpoint, it will add a field named patterns_request_key when it writes the record to its Table. In a Python node, you can pass that request key to the function respond_to_request along with a payload which will be sent as the body of the webhook response.

response.py
from patterns import (
Table,
respond_to_request
)

webhook_table = Table("webhook")

for record in webhook_table.as_stream():
request_key = record["patterns_request_key"]

# The response_payload will be sent to the webhook identified by the response_key.
# It can contain any value that can be encoded to json.
response_payload = {"hello": "world", "count": 2}
respond_to_request(request_key, response_payload)

Webhooks Video Tutorial