feat: add default telephony variables

This commit is contained in:
Abhishek Kumar 2026-04-02 14:48:13 +05:30
parent 96c90376c3
commit e7adbc7bad
10 changed files with 38 additions and 4 deletions

View file

@ -187,6 +187,7 @@ async def initiate_call(
call_type=CallType.OUTBOUND,
initial_context={
"phone_number": phone_number,
"called_number": phone_number,
"provider": provider.PROVIDER_NAME,
},
)
@ -220,13 +221,22 @@ async def initiate_call(
**keywords,
)
# Store provider type and any provider-specific metadata in workflow run context
# Store provider metadata and caller_number in workflow run context
gathered_context = {
"provider": provider.PROVIDER_NAME,
**(result.provider_metadata or {}),
}
# Merge caller_number into initial_context now that we know which number was used
updated_initial_context = {
**(workflow_run.initial_context or {}),
"called_number": phone_number,
}
if result.caller_number:
updated_initial_context["caller_number"] = result.caller_number
await db_client.update_workflow_run(
run_id=workflow_run_id, gathered_context=gathered_context
run_id=workflow_run_id,
gathered_context=gathered_context,
initial_context=updated_initial_context,
)
return {"message": f"Call initiated successfully with run name {workflow_run_name}"}

View file

@ -205,6 +205,8 @@ class CampaignCallDispatcher:
"campaign_id": campaign.id,
"provider": provider.PROVIDER_NAME,
"source_uuid": queued_run.source_uuid,
"caller_number": from_number,
"called_number": phone_number,
}
logger.info(f"Final initial_context: {initial_context}")

View file

@ -18,6 +18,7 @@ class CallInitiationResult:
call_id: str # Provider's call identifier (SID for Twilio, UUID for Vonage)
status: str # Initial status (e.g., "queued", "initiated", "started")
caller_number: Optional[str] = None # Caller ID used for the outbound call
provider_metadata: Dict[str, Any] = field(
default_factory=dict
) # Data that needs to be persisted

View file

@ -143,6 +143,7 @@ class ARIProvider(TelephonyProvider):
return CallInitiationResult(
call_id=channel_id,
status=response_data.get("state", "created"),
caller_number=from_number,
provider_metadata={
"call_id": channel_id,
"channel_name": response_data.get("name", ""),

View file

@ -189,6 +189,7 @@ class CloudonixProvider(TelephonyProvider):
return CallInitiationResult(
call_id=session_token,
status="initiated",
caller_number=from_number,
provider_metadata={
"call_id": session_token,
"domain_id": domain_id,

View file

@ -124,6 +124,7 @@ class TelnyxProvider(TelephonyProvider):
return CallInitiationResult(
call_id=call_control_id,
status="initiated",
caller_number=from_number,
provider_metadata={
"call_control_id": call_control_id,
"call_leg_id": call_leg_id,

View file

@ -111,6 +111,7 @@ class TwilioProvider(TelephonyProvider):
return CallInitiationResult(
call_id=response_data["sid"],
status=response_data.get("status", "queued"),
caller_number=from_number,
provider_metadata={"call_id": response_data["sid"]},
raw_response=response_data,
)

View file

@ -150,6 +150,7 @@ class VobizProvider(TelephonyProvider):
return CallInitiationResult(
call_id=call_id,
status="queued", # Vobiz returns "message": "call fired"
caller_number=from_number,
provider_metadata={"call_id": call_id},
raw_response=response_data,
)

View file

@ -137,6 +137,7 @@ class VonageProvider(TelephonyProvider):
return CallInitiationResult(
call_id=response_data["uuid"],
status=response_data.get("status", "started"),
caller_number=from_number,
provider_metadata={
"call_uuid": response_data["uuid"]
}, # Vonage needs UUID persisted for WebSocket

View file

@ -45,9 +45,9 @@ whether they'd like to continue.
When the call starts, Dograh substitutes the values before sending the prompt to the LLM — so the agent speaks naturally as if it already knows the contact.
### Built-in template variables
### Default variables
Dograh provides built-in variables for current time and weekday that you can use in any prompt without setting up `initial_context`.
Built-in variables for current time and weekday, available in any prompt without setting up `initial_context`.
| Variable | Description | Example output |
|---|---|---|
@ -66,6 +66,21 @@ Today is {{current_weekday}} and the current time is {{current_time_America/New_
When you use a timezone suffix on **either** `current_time` or `current_weekday`, the other variable without a suffix will automatically use the same timezone instead of UTC. For example, if your prompt contains both `{{current_time_Asia/Kolkata}}` and `{{current_weekday}}`, the weekday will also be resolved in `Asia/Kolkata`.
</Note>
### Telephony variables
For telephony calls (inbound and outbound), Dograh automatically adds these variables to `initial_context`:
| Variable | Description | Example |
|---|---|---|
| `{{caller_number}}` | The phone number that initiated the call | `+14155550100` |
| `{{called_number}}` | The phone number that received the call | `+18005550199` |
For **inbound** calls, `caller_number` is the customer's number and `called_number` is your Dograh number. For **outbound** calls, it's the reverse — `caller_number` is your Dograh number and `called_number` is the customer's number.
```
You are speaking with the caller at {{caller_number}}.
```
### gathered_context
Data the agent collects *during* the call. You configure what to extract in the agent node's extraction settings — each variable has a name, type, and a prompt that tells the LLM what to look for.