mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-22 08:38:13 +02:00
chore: update docs for pre-call data fetch
This commit is contained in:
parent
79ff04d8a9
commit
418592178c
7 changed files with 142 additions and 45 deletions
|
|
@ -118,7 +118,7 @@ For example, if your request includes:
|
|||
}
|
||||
```
|
||||
|
||||
You can reference the user's name in your prompt as `{{initial_context.user.name}}`.
|
||||
You can reference the user's name in your agent prompt as `{{user.name}}` — in Agent prompts, `initial_context` fields are referenced directly by name (not prefixed with `initial_context.`). See [template variables](/voice-agent/template-variables) for the exact syntax in prompts versus webhook payloads.
|
||||
|
||||
See [Context & Variables](/core-concepts/context-and-variables) for more on how data flows through a call.
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ Pre-Call Data Fetch allows you to enrich the call context with external data bef
|
|||
1. A call arrives (inbound) or is initiated (outbound).
|
||||
2. Dograh sends a **POST** request to your configured endpoint with a standardized payload.
|
||||
3. The caller hears a ring-back tone while waiting for the response.
|
||||
4. Your API responds with a JSON object containing `dynamic_variables`.
|
||||
4. Your API responds with a JSON object containing an `initial_context` object.
|
||||
5. The variables are merged into the call's initial context.
|
||||
6. The voice agent starts with full access to the fetched data via `{{variable_name}}` syntax.
|
||||
|
||||
|
|
@ -50,12 +50,12 @@ The `Content-Type` header is set to `application/json`. If you configured a cred
|
|||
|
||||
## Expected Response Format
|
||||
|
||||
Your API should return a **JSON object** with a `2xx` status code. The variables to inject into the call context should be placed inside the `dynamic_variables` key:
|
||||
Your API should return a **JSON object** with a `2xx` status code. The variables to inject into the call context should be placed inside the `initial_context` key:
|
||||
|
||||
```json
|
||||
{
|
||||
"call_inbound": {
|
||||
"dynamic_variables": {
|
||||
"initial_context": {
|
||||
"customer_name": "Jane Doe",
|
||||
"account_status": "active",
|
||||
"loyalty_tier": "gold",
|
||||
|
|
@ -65,34 +65,38 @@ Your API should return a **JSON object** with a `2xx` status code. The variables
|
|||
}
|
||||
```
|
||||
|
||||
You can also place `dynamic_variables` at the top level:
|
||||
You can also place `initial_context` at the top level:
|
||||
|
||||
```json
|
||||
{
|
||||
"dynamic_variables": {
|
||||
"initial_context": {
|
||||
"customer_name": "Jane Doe",
|
||||
"account_status": "active"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<Note>
|
||||
The legacy `dynamic_variables` key is still accepted as a drop-in alias for `initial_context`, so existing integrations keep working without any changes. Use `initial_context` for new integrations. If a response contains both keys, `initial_context` takes precedence.
|
||||
</Note>
|
||||
|
||||
After the response is received, you can reference these values anywhere template variables are supported:
|
||||
|
||||
- **Greeting**: `Hello {{customer_name}}, thank you for calling!`
|
||||
- **Prompt**: `The customer is a {{loyalty_tier}} member with {{open_tickets}} open support tickets.`
|
||||
|
||||
<Note>
|
||||
If the response is not a valid JSON object, does not contain `dynamic_variables`, or the request fails or times out, the call proceeds normally without the additional context. The pre-call fetch never blocks or fails a call.
|
||||
If the response is not a valid JSON object, does not contain `initial_context` (or the legacy `dynamic_variables`), or the request fails or times out, the call proceeds normally without the additional context. The pre-call fetch never blocks or fails a call.
|
||||
</Note>
|
||||
|
||||
## Nested Variables
|
||||
|
||||
If your `dynamic_variables` contain nested objects, you can access them using dot notation:
|
||||
If your `initial_context` contains nested objects, you can access them using dot notation:
|
||||
|
||||
```json
|
||||
{
|
||||
"call_inbound": {
|
||||
"dynamic_variables": {
|
||||
"initial_context": {
|
||||
"customer": {
|
||||
"name": "Jane Doe",
|
||||
"address": {
|
||||
|
|
@ -153,7 +157,7 @@ app.post("/dograh/pre-call", async (req, res) => {
|
|||
|
||||
res.json({
|
||||
call_inbound: {
|
||||
dynamic_variables: {
|
||||
initial_context: {
|
||||
customer_name: customer.name,
|
||||
account_status: customer.status,
|
||||
loyalty_tier: customer.tier,
|
||||
|
|
|
|||
|
|
@ -4,13 +4,23 @@ description: "You can use Template Variables in your prompts for your Agent node
|
|||
---
|
||||
|
||||
### Template Rendering
|
||||
You can reference template variables which is passed as [`initial_context`](/core-concepts/context-and-variables#initial_context) either using the [API Trigger](/voice-agent/api-trigger) or when uploading a Sheet for a [campaign](/core-concepts/campaigns). You can also use any extracted variable as [`gathered_context`](/core-concepts/context-and-variables#gathered_context)
|
||||
|
||||
The template rendering can take nested values.
|
||||
You reference template variables with `{{double_brace}}` syntax. The data comes from [`initial_context`](/core-concepts/context-and-variables#initial_context) — set via the [API Trigger](/voice-agent/api-trigger), a [campaign](/core-concepts/campaigns) sheet, or a [Pre-Call Data Fetch](/voice-agent/pre-call-data-fetch) that enriches the context when the call starts — and, in Webhook payloads only, from [`gathered_context`](/core-concepts/context-and-variables#gathered_context) (variables extracted during the call).
|
||||
|
||||
Example: If the initial context is
|
||||
**The syntax depends on where you use it:**
|
||||
|
||||
```
|
||||
| Where | `initial_context` | `gathered_context` |
|
||||
| --- | --- | --- |
|
||||
| Agent node prompts | `{{field_name}}` (referenced directly) | Not available |
|
||||
| Webhook Node payloads | `{{initial_context.field_name}}` | `{{gathered_context.field_name}}` |
|
||||
|
||||
#### Agent node prompts
|
||||
|
||||
In an Agent node prompt, reference each `initial_context` field **directly by name**. Nested values are supported with dot notation.
|
||||
|
||||
Example: if the initial context is
|
||||
|
||||
```json
|
||||
{
|
||||
"initial_context": {
|
||||
"user": {
|
||||
|
|
@ -20,14 +30,26 @@ Example: If the initial context is
|
|||
}
|
||||
```
|
||||
|
||||
You can write your prompt to access the user's name as below
|
||||
write your prompt to access the user's name as below:
|
||||
|
||||
Prompt: `You are Alice, who is talking to {{initial_context.user.name}}.`
|
||||
Prompt: `You are Alice, who is talking to {{user.name}}.`
|
||||
|
||||
<Note>
|
||||
Variables extracted during the call (`gathered_context`) are **not** available in Agent prompts — a prompt can only reference `initial_context` fields. To act on extracted data, send it to a [Webhook Node](/voice-agent/webhook).
|
||||
</Note>
|
||||
|
||||
#### Webhook Node payloads
|
||||
|
||||
When constructing a [Webhook Node](/voice-agent/webhook) payload, the context objects are nested under their names, so reference them with the `initial_context.` and `gathered_context.` prefixes:
|
||||
|
||||
Payload value: `{{initial_context.user.name}}` or `{{gathered_context.call_disposition}}`
|
||||
|
||||
### Using Template Variables for Testing
|
||||
|
||||
Template variables defined in your workflow **Settings > Context Variables** are included in test calls (both web and phone) made from the workflow editor. This is useful for simulating data that would normally come from telephony or an API trigger.
|
||||
|
||||
<img src="../images/template-variables.png" alt="Template Variables panel in workflow Settings, showing a customer_name variable and fields to add new key/value pairs" style={{border: "1px solid #d1d5db", borderRadius: "8px", maxWidth: "100%"}} />
|
||||
|
||||
For example, you can set `caller_number` and `called_number` as context variables to test [Pre-Call Data Fetch](/voice-agent/pre-call-data-fetch#testing-with-test-calls) without needing a real inbound call.
|
||||
|
||||
<Note>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue