Use webhook data in a mission
Give a deputy the whole story the moment an event arrives. When a payment succeeds, the mission’s prompt already holds the invoice ID, the customer and the amount, so the agent starts on the real invoice instead of looking it up. The prompt reads fields straight from the event, such as {{ .data.object.id }}, and every matching event fills them in.
Available when your administrator enables deputies and webhooks.
Before you start
- You can manage the deputy: it is yours, you lead its team, or you are an admin.
- The event source is connected. For your own system, such as a payment provider, create an endpoint: see Create a webhook endpoint. For GitHub, see Connect GitHub.
- The deputy has a mission. See Create a deputy and a mission.
Steps
1. Write a prompt that reads the event
A payment provider sends an event like this one:
{
"type": "invoice.paid",
"data": {
"object": {
"id": "in_1Q2w3E",
"customer_email": "dana@example.com",
"amount_paid": 4200,
"lines": [{"description": "Pro plan"}, {"description": "Extra seats"}]
}
}
}Open the mission and write the prompt with the same paths the event uses:
Invoice {{ .data.object.id }} was paid by {{ .data.object.customer_email }}.
Amount: {{ .data.object.amount_paid }} cents.
Items: {{ range .data.object.lines }}{{ .description }}; {{ end }}
Update the customer record and send the receipt summary to #billing.The Inputs panel lists each path as an input: data.object.id, data.object.customer_email, data.object.amount_paid and data.object.lines. Set a type for each one and whether it is required.
How the prompt reads the event:
| You write | You get |
|---|---|
{{ .data.object.id }} | The value of that field. |
{{ range .data.object.lines }}{{ .description }} {{ end }} | Each item of a list, one after another. |
{{ .data.object }} | That whole object, as JSON. |
{{ . }} | The whole event, as JSON. |
When the prompt reads both an object and a field inside it, such as {{ .data.object }} and {{ .data.object.id }}, the object is the one input.
The same works for every source. A GitHub triage prompt reads {{ .issue.title }}, {{ .issue.user.login }} and {{ .repository.full_name }} from issues.opened.
2. Try it with a dry run
On the mission’s row, click Dry run. Fill in each input with a sample value, for example in_1Q2w3E for data.object.id. Check the rendered prompt. When it reads right, click Activate.
3. Add the trigger
- In the mission’s Triggers section, click Event.
- Pick the source and the event, for example your payment endpoint and
invoice.paid. - Click Create.
That is all the prompt needs. Each input is read from the event at its own path, so data.object.id comes from data.object.id.
4. Optional: map an input
Map an input only when you want something other than its own path:
- Rename. Your prompt says
{{ .invoice_id }}and the event calls itdata.object.id: mapinvoice_idto the pathdata.object.id. - Default. Give an input a value to use when the event leaves the field out or sets it to
null. - Another field. Point an input at a different path, such as
data.object.number. - Whole payload. Choose Whole payload (the path
.) to hand the full event to an object input.
A path is a dotted path into the event: data.object.id is one field, data.object is a whole object, and data.object.lines.0.description is the first item’s description. A mapped value takes the place of the event’s own value at that path.
5. Test with a real event
See the exact prompt a real event produces, then run it, before you wait for the next delivery.
- Open the trigger with Edit. In Test against real events, select Show details.
- Pick a recent event and select Run with this event. To use an event of your own, select Paste an event and paste its JSON object.
- Marshal shows the run’s title and the prompt, filled in from that event, the same way a real delivery fills it.
- Select Run. Marshal starts the run and links to it. When a concurrency limit holds the launch, the run waits in the queue and starts when a slot frees.
The confirmation also tells you whether the trigger’s condition matches the event. The run starts either way, so you can try the prompt on any event you like. A test run carries a test label on the runs list and the run page, and it counts like any other run.
How event data reaches the prompt
- The event is the prompt’s data. Any field the prompt reads comes straight from the event.
{{ . }}prints the whole event as JSON. - Required inputs. A required input with no value in the event and no default stops that firing, and the firing records which input was missing. The agent never works from a half-filled prompt.
- Nulls. A field that is
nullinside an object printsnull. A required input that isnullcounts as missing, so its default applies. - Size. An event up to 32 KB reaches the prompt in full. For a larger event, the prompt gets each field the mission declares, up to 8 KB each, and a
_marshal_notefield that tells the agent the event was trimmed to those fields.
What you should see
- The trigger in the mission’s Triggers list with an
onbadge. - When an invoice is paid, a new run on the deputy. Its prompt names the invoice ID, the customer and the amount.
- A run you started with Run with this event shows a
testlabel.
Next
Narrow the trigger with a condition, such as event.data.object.amount_paid > 100000, in Schedules and triggers.