從你自己的程式收發通話音訊,例如你自己的電話系統或 App。先發起通話:
curl https://evasay.com/api/v1/voice/calls/websocket \
-X POST \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{ "agent_id": "AGENT_ID", "encoding": "pcm_s16le", "sample_rate": 16000 }'
回應中的 websocket_url 帶一次性權杖,15 分鐘內可開啟。encoding 為 pcm_s16le(16 位元小端序 PCM,sample_rate 8000、16000 或 24000)或 mulaw(8 kHz μ-law)。音訊以該格式的二進位影格雙向傳送,每影格最好 20 ms。文字影格為 JSON:
| 方向 | 訊息 |
|---|---|
| 你 → EvaSay | {"type":"dtmf","digits":"12#"} 按鍵;{"type":"end"} 掛斷;{"type":"text","text":"…"} 來電者打的字(點按鈕回覆時帶 "input":"button");{"type":"context","text":"…","key":"cart"} 你的 App 回報的情況(Agent 不會回答);{"type":"typing"} 客戶正在打字(打字時每秒左右送一次,Agent 2 秒內不開口);{"type":"tool_result","id":"…","result":{…}}(或 "error")頁面函式的結果 |
| EvaSay → 你 | start(帶 callId);clear(來電者打斷:丟掉還沒播放的 Agent 音訊);transcript(role、text、final,打字時帶 input);user_started_speaking、user_stopped_speaking、agent_started_speaking、agent_stopped_speaking;cards(cards、quick_replies);tool(id、name、arguments:執行你的頁面函式);notice(code:打字的 too_fast 或 limit);ended(帶 reason,之後關閉連線) |
一連上 Agent 就會打招呼。請求裡可以加上 user_id 和 page_tools(你的 App 回答的頁面函式,見下文)。通話和其他通話一樣按分鐘計費,也有相同的通話紀錄、分析和 Webhook。