Skip to content

Commit 82d517f

Browse files
committed
Update Calling API
1 parent 3c0deed commit 82d517f

File tree

20 files changed

+178
-2444
lines changed

20 files changed

+178
-2444
lines changed

specs/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"build:schema": "yarn build:swml",
1010
"build:swml": "cd ./swml && tsp compile . && cd ../",
1111
"build:calling-api": "cd ./signalwire-rest/calling-api && tsp compile . && cd ../../",
12-
"build:calling-api-docs": "cd ./signalwire-rest/calling-api/open-rpc/dial && tsp compile . && cd ../../../../ && cd ./signalwire-rest/calling-api/open-rpc/update && tsp compile . && cd ../../../../ && cd ./signalwire-rest/calling-api/open-rpc/calling-end && tsp compile . && cd ../../../../ && cd ./signalwire-rest/calling-api/open-rpc/calling-ai-hold && tsp compile . && cd ../../../../ && cd ./signalwire-rest/calling-api/open-rpc/calling-ai-unhold && tsp compile . && cd ../../../../ && cd ./signalwire-rest/calling-api/open-rpc/calling-ai-message && tsp compile . && cd ../../../../",
1312
"build:chat-api": "cd ./signalwire-rest/chat-api && tsp compile . && cd ../../",
1413
"build:datasphere-api": "cd ./signalwire-rest/datasphere-api && tsp compile . && cd ../../",
1514
"build:fabric-api": "cd ./signalwire-rest/fabric-api && tsp compile . && cd ../../",
Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
11
import "@typespec/http";
2+
import "@typespec/openapi";
23
import "../../types";
34
import "./models/requests.tsp";
45
import "./models/responses.tsp";
56
import "./models/examples.tsp";
67

78
using TypeSpec.Http;
9+
using TypeSpec.OpenAPI;
810
using Types.StatusCodes;
911

1012
@route("/calls")
1113
namespace CallingAPI.Calls {
1214
@tag("Calls")
1315
@friendlyName("Calls")
1416
interface Calls {
15-
@summary("Create a Call")
16-
@doc("To create a new call, you send a `POST` request to the Call resource with a payload including a `dial` command and additional nested `params`.")
17-
create(@body request: CallCreateRequest):
18-
| {
19-
@statusCode statusCode: 201;
20-
@body call: CallResponse;
21-
}
22-
| StatusCode401
23-
| StatusCode404
24-
| CallCreate422Error
25-
| StatusCode500;
26-
27-
@summary("Update a Call")
28-
@doc("To update an existing call, you send a `PUT` request to the Call resource with a payload including a `command` and additional nested `params`.")
17+
@summary("Send Call Commands")
18+
@doc("""
19+
Unified OpenRPC-style endpoint for executing call methods through command-based dispatch.
20+
Send a request with the appropriate `command` field to invoke the desired call operation.
21+
This endpoint provides a single interface for all call-related methods including creation, updates, termination, and AI conversation control.
22+
""")
23+
@opExample(
24+
#{ parameters: dialCallExample },
25+
#{
26+
title: "Create new call",
27+
description: "Initiate a new outbound call with the dial command",
28+
}
29+
)
30+
@opExample(
31+
#{ parameters: updateCallExample },
32+
#{
33+
title: "Update active call",
34+
description: "Modify an existing call's parameters in real-time",
35+
}
36+
)
37+
@opExample(
38+
#{ parameters: hangupCallExample },
39+
#{
40+
title: "End call",
41+
description: "Terminate an active call immediately",
42+
}
43+
)
2944
@opExample(
3045
#{ parameters: holdCallExample },
3146
#{
@@ -47,16 +62,16 @@ namespace CallingAPI.Calls {
4762
description: "Send a message to the AI conversation to modify behavior or add context",
4863
}
4964
)
50-
//@opExample(#{parameters: #{request: #{command: "update", params: #{id: "3fa85f64-5717-4562-b3fc-2c963f66afa6", url: "https://example.com/swml", fallback_url: "https://example.com/fallback"}}}}, #{title: "Update active call", description: "Modify an active call's behavior using new SWML instructions"})
51-
@put
52-
update(@body request: CallUpdateRequest):
65+
@post
66+
@operationId("call-commands")
67+
callCommand(@body request: CallRequest):
5368
| {
5469
@statusCode statusCode: 200;
5570
@body call: CallResponse;
5671
}
5772
| StatusCode401
5873
| StatusCode404
59-
| CallUpdate422Error
74+
| CallCreate422Error
6075
| StatusCode500;
6176
}
6277
}

specs/signalwire-rest/calling-api/calls/models/examples.tsp

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,63 @@
55
*/
66
const callId = "3fa85f64-5717-4562-b3fc-2c963f66afa6";
77

8-
// Hangup Call Examples
8+
// Call command examples
9+
const dialCallExample = #{
10+
request: #{
11+
command: "dial",
12+
params: #{
13+
from: "+15551234567",
14+
to: "+15559876543",
15+
url: "https://example.com/swml",
16+
caller_id: "+15551234567",
17+
status_url: "https://example.com/status_callback",
18+
status_events: #["answered", "ended"],
19+
},
20+
},
21+
};
22+
23+
const updateCallExample = #{
24+
request: #{
25+
command: "update",
26+
params: #{
27+
id: callId,
28+
url: "https://example.com/swml",
29+
fallback_url: "https://example.com/fallback",
30+
},
31+
},
32+
};
33+
934
const hangupCallExample = #{
1035
request: #{
11-
id: callId,
1236
command: "calling.end",
37+
id: callId,
1338
params: #{ reason: "hangup" },
1439
},
1540
};
1641

1742
const holdCallExample = #{
18-
request: #{ id: callId, command: "calling.ai_hold", params: #{} },
43+
request: #{
44+
command: "calling.ai_hold",
45+
id: callId,
46+
params: #{},
47+
},
1948
};
2049

2150
const unholdCallExample = #{
22-
request: #{ id: callId, command: "calling.ai_unhold", params: #{} },
51+
request: #{
52+
command: "calling.ai_unhold",
53+
id: callId,
54+
params: #{},
55+
},
2356
};
2457

2558
const aiMessageExample = #{
2659
request: #{
27-
id: callId,
2860
command: "calling.ai_message",
61+
id: callId,
2962
params: #{
3063
role: "system",
3164
message_text: "You are now in expert mode. Provide detailed technical responses and use industry terminology.",
3265
},
3366
},
3467
};
35-
36-
const updateCallExample = #{
37-
request: #{
38-
command: "update",
39-
params: #{
40-
id: callId,
41-
url: "https://example.com/swml",
42-
fallback_url: "https://example.com/fallback",
43-
},
44-
},
45-
};

specs/signalwire-rest/calling-api/calls/models/requests.tsp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,27 @@ model CallUpdateCurrentCallRequest {
200200
params: CallUpdateParamsAlias;
201201
}
202202

203-
union CallUpdateRequest {
204-
CallUpdateCurrentCallRequest,
205-
CallHangupRequest,
206-
CallHoldRequest,
207-
CallUnholdRequest,
208-
CallAIMessageRequest,
203+
@discriminated(#{discriminatorPropertyName: "command", envelope: "none"})
204+
@doc("""
205+
Call request union for OpenRPC-style method dispatch. Use the `command` field to specify which call method to invoke:
206+
207+
- **`dial`** - Create and initiate a new outbound call to a destination. Returns immediately with call details while the call is being established in the background.
208+
209+
- **`update`** - Modify an active call's properties in real-time. Update call parameters such as routing, recording settings, or other call-specific configurations.
210+
211+
- **`calling.end`** - Terminate an active call immediately. Disconnects all parties and ends the call session. Cannot be reversed once executed.
212+
213+
- **`calling.ai_hold`** - Place an AI-powered call on hold. Pauses the AI conversation and typically plays hold music or a message to the caller. The AI agent becomes inactive until unhold.
214+
215+
- **`calling.ai_unhold`** - Resume an AI call from hold state. Reactivates the AI agent and continues the conversation from where it was paused.
216+
217+
- **`calling.ai_message`** - Inject a message into an active AI conversation. Allows you to dynamically add context, instructions, or system messages to guide the AI agent's behavior during the call.
218+
""")
219+
union CallRequest {
220+
dial: CallCreateRequest,
221+
update: CallUpdateCurrentCallRequest,
222+
`calling.end`: CallHangupRequest,
223+
`calling.ai_hold`: CallHoldRequest,
224+
`calling.ai_unhold`: CallUnholdRequest,
225+
`calling.ai_message`: CallAIMessageRequest,
209226
}

specs/signalwire-rest/calling-api/open-rpc/calling-ai-hold/main.tsp

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)