- A webhook handler verifies the delivery’s signature, sends the event to the issue’s agent, and returns.
- A Virtual Object, keyed by the issue, runs the agent with the issue’s conversation and posts the answer.
Receive the webhook
The webhook handler is a service handler that accepts GitHub’sissues and issue_comment events:
- Verify the signature. The handler receives the unmodified body as raw bytes, computes its HMAC with the webhook’s secret, and compares the result with the
x-hub-signature-256header. A terminal error with code401rejects the delivery: Restate doesn’t retry the invocation, and in sync mode GitHub receives401. See Write the handler. - Return immediately. Senders wait only a few seconds for a response, for example 10 seconds for GitHub, while an agent run can take minutes. The handler sends the event to the agent and doesn’t wait for the run.
- Deduplicate deliveries. The idempotency key from the
x-github-deliveryheader makes Restate start one run per delivery, also when you redeliver the event from GitHub. - Skip bot events. The handler ignores deliveries whose sender is a bot. This includes the agent’s own comments when it posts them through a GitHub App: each of its comments is an
issue_commentevent too, which would otherwise start another run.
Run the agent per issue
The Virtual Object runs the agent for one issue, and posts the answer as a comment:- One run at a time per issue. Restate runs one exclusive handler per key, so the events of an issue run in the order they arrive, and different issues run in parallel.
- A conversation per issue. The agent answers a comment with the issue and its earlier answers in its history. See Sessions.
- A journaled comment.
restate.runjournals the result of posting the comment, so a replay doesn’t post it again. - Idempotency retention. Restate keeps the idempotency keys of
onEventfor 3 days, as long as GitHub allows you to redeliver an event. A redelivery within these 3 days doesn’t start another run, also when the earlier run failed.
Connect GitHub
- Register the deployment that contains
GitHubWebhookandGitHubThread, and setGITHUB_WEBHOOK_SECRETin its environment. - In Restate Cloud, create an incoming webhook for
GitHubWebhook/receive. Either delivery mode works: GitHub accepts any2xxresponse, and the handler returns well within GitHub’s 10 seconds. In sync mode, GitHub’s delivery log shows rejected deliveries. - In your repository settings, add a webhook with the webhook URL, the content type
application/json, and the same secret. Select the Issues and Issue comments events. GitHub also sends Issue comments events for comments on pull requests, so the agent answers those too. See Configure webhook senders.
http://localhost:8080/restate/call/GitHubWebhook/receive.
Other senders
The handlers for other senders follow the same steps, with the sender’s signature scheme and delivery ID:
Reject Linear and Slack deliveries whose timestamp is too old. See Configure webhook senders for the verification code of each sender.
The incoming webhooks example has handlers for GitHub, Linear, and Slack that forward events to Virtual Objects, and a script that sends signed sample deliveries. To add an agent, replace the logic in the example’s Virtual Objects with an agent run, as in
GitHubThread on this page.