···44looks something like this:
55661. An HTTP request is received at a path like `/webhooks/tangled`
77-2. Lure matches the path to a template file on disk, e.g.
88- `./lures/tangled.lure`. The `.lure` file is part config, part template (more
99- on this later).
77+2. Lure strips the configured base path and matches the remainder to a template
88+ file on disk, e.g. with base path `/webhooks`, the path `/webhooks/tangled`
99+ matches `./lures/tangled.lure`. Nested paths are supported: `/webhooks/github/push`
1010+ matches `./lures/github/push.lure`. The `.lure` file is part config, part
1111+ template (more on this later).
10123. According to the config, Lure validates the webhook according to the
1113 specified strategy (e.g. API key or HMAC verification)
12144. If validation succeeds, Lure executes some callback with the string result of
···24262527```md
2628---
2727-register: manual
2829verify:
2930 hmac:
3031 location: header
···3233 secret: $MY_WEBHOOK_SECRET
3334payload:
3435 contentType: json
3535- schema: https://example.com/schema
3636config:
3737 arbitrary: true
3838 someValue: 3
3939---
40404141-You have received information about a <%= it.payload.event => event on My
4141+You have received information about a <%= it.payload.event %> event on My
4242Service. Read the following payload and respond according to your skills:
43434444<%= it.payload.body %>
4545```
46464747-Different registration and verification methods can be supported, for generic
4848-implementations or vendor-specific requirements. Only one verification method
4949-can be specified per lure.
4747+Different verification methods can be supported, for generic implementations or
4848+vendor-specific requirements. Only one verification method can be specified per
4949+lure.
5050+5151+### Template scope
5252+5353+Templates are evaluated using [eta](https://eta.js.org). The following
5454+properties are available on `it`:
5555+5656+- `it.payload`: The request body. For `contentType: json`, this is the parsed
5757+ JSON value.
5858+- `it.headers`: The request headers as a [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) object.
5959+- `it.query`: The query string parameters as a [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) object.
50605161## Usage
5262···55655666Both handler constructors take the following parameters:
57676868+- `basePath`: The URL path prefix under which all lure endpoints are mounted,
6969+ e.g. `/webhooks`. Lure only handles requests whose path begins with this
7070+ prefix; all other requests are passed through.
5871- `configSchema`: A Standard Schema for validating any extra config you would
5972 like to allow in the `config` frontmatter key
6073- `luresDir`: A path to a directory of lures
6174- `callback`: A function that you want to run in response to incoming webhooks.
6275 It will be called with the templated prompt `prompt` and the value of the
6376 `config` frontmatter value.
7777+- `maxAttempts`: How many times to attempt the `callback` before giving up.
7878+ Defaults to `1` (no retries). If all attempts fail, the webhook is dropped.
64796580## Lifecycle
6681···77921. The requested path is checked against registered lure paths.
78932. On a hit, we immediately return a 204 response, to keep the response
7994 time as low as possible.
8080-3. Webhook requests are copied and added to a queue for processing.
8181-3. The queue processor removes requests from the queue FIFO. If verification
9595+3. Webhook requests are copied and added to an in-memory queue for processing.
9696+ Requests in the queue will be lost if the process exits.
9797+4. The queue processor removes requests from the queue FIFO. If verification
8298 fails, the request is dropped.
8383-4. On successful verification, the lure template is evaluated using the
9999+5. On successful verification, the lure template is evaluated using the
84100 request.
8585-5. Finally, the provided `callback` is executed with the fully-formed prompt,
8686- and the config object from the original `.lure` frontmatter.
101101+6. The provided `callback` is executed with the fully-formed prompt and the
102102+ config object from the original `.lure` frontmatter. If the callback throws,
103103+ it will be retried up to `maxAttempts` times before the webhook is dropped.