Back to page
Asynchronous ARI Stasis Services
Raw Markdown & AI/RAG Chunks
Raw Markdown Source
2868 chars
# Asynchronous ARI Stasis Services
To take programmatic control over live telephone calls, **Asterisk 2** configures continuous **Asterisk REST Interface (ARI)** message links. The C# runtime intercepts active audio sessions directly to run advanced voice workflow scripts asynchronously.
---
## Stasis Application Interception Map
The flowchart below traces how incoming channel contexts transfer from low-level PBX applications into C# background management services:
```mermaid
graph TD
%% Inbound Route
subgraph TelecomCore["Asterisk PBX Kernel"]
StasisDialplan["stasis Application Trigger<br/>(Dialplan Function Execution)"]
end
%% API Adapter Bus
subgraph InterceptionBus["ARI Engine Adapter"]
AriSocket["res_ari WebSocket Channel<br/>(Exposes /ari/events Stream)"]
end
%% Application Domain
subgraph DotNetServices["C# Runtime Environment"]
StasisWorker["StasisConsumerWorker.cs<br/>(Hosted BackgroundService loop)"]
EventHandler["CallLifecycleRouter.cs<br/>(Parses Raw JSON Actions)"]
end
%% Execution Targets
subgraph AutomationTarget["Executed Media Instructions"]
CmdPlayback["POST /ari/channels/play<br/>(Stream Digital Audio files)"]
CmdHangup["DELETE /ari/channels<br/>(Purge Physical Connection)"]
end
%% Links
StasisDialplan ==>|"Handover Execution Control"| AriSocket
AriSocket <-->|"Persistent WS Connection"| StasisWorker
StasisWorker ==>|"Push Event string"| EventHandler
EventHandler ==>|"Trigger Voice Workflow"| CmdPlayback
EventHandler -->|"End Session Context"| CmdHangup
%% High-Contrast Style System
classDef coreToken fill:#0f172a,stroke:#38bdf8,stroke-width:2px,color:#fff,rx:6px,ry:6px;
classDef adapterToken fill:#1e293b,stroke:#a855f7,stroke-width:2px,color:#fff,rx:6px,ry:6px;
classDef svcToken fill:#312e81,stroke:#ec4899,stroke-width:2px,color:#fff,rx:6px,ry:6px;
classDef cmdToken fill:#065f46,stroke:#10b981,stroke-width:2px,color:#fff,rx:6px,ry:6px;
class TelecomCore,StasisDialplan coreToken;
class InterceptionBus,AriSocket adapterToken;
class DotNetServices,StasisWorker,EventHandler svcToken;
class AutomationTarget,CmdPlayback,CmdHangup cmdToken;
```
---
## Architectural Directives
### 1. Persistent Thread Safeties
Because live ARI event streams write thousands of multi-node JSON events every minute, background services configure dedicated multithreading boundaries. Background consumer workers read incoming socket blocks cleanly using asynchronous loop wrappers (`await foreach`).
### 2. High-Speed API Command Authorization
Outbound commands targeting active ARI REST endpoints append cryptographically signed credentials (`api_key=username:secret`) directly inside base parameter strings to completely prevent unauthorized instruction injections.
AI Chunks (RAG)
3 chunks
Chunk #1
Asynchronous ARI Stasis Services
# Asynchronous ARI Stasis Services To take programmatic control over live telephone calls, **Asterisk 2** configures continuous **Asterisk REST Interface (ARI)** message links. The C# runtime intercepts active audio sessions directly to run advanced voice workflow scripts asynchronously. ---
Chunk #2
Stasis Application Interception Map
## Stasis Application Interception Map
The flowchart below traces how incoming channel contexts transfer from low-level PBX applications into C# background management services:
```mermaid
graph TD
%% Inbound Route
subgraph TelecomCore["Asterisk PBX Kernel"]
StasisDialplan["stasis Application Trigger<br/>(Dialplan Function Execution)"]
end
%% API Adapter Bus
subgraph InterceptionBus["ARI Engine Adapter"]
AriSocket["res_ari WebSocket Channel<br/>(Exposes /ari/events Stream)"]
end
%% Application Domain
subgraph DotNetServices["C# Runtime Environment"]
StasisWorker["StasisConsumerWorker.cs<br/>(Hosted BackgroundService loop)"]
EventHandler["CallLifecycleRouter.cs<br/>(Parses Raw JSON Actions)"]
end
%% Execution Targets
subgraph AutomationTarget["Executed Media Instructions"]
CmdPlayback["POST /ari/channels/play<br/>(Stream Digital Audio files)"]
CmdHangup["DELETE /ari/channels<br/>(Purge Physical Connection)"]
end
%% Links
StasisDialplan ==>|"Handover Execution Control"| AriSocket
AriSocket <-->|"Persistent WS Connection"| StasisWorker
StasisWorker ==>|"Push Event string"| EventHandler
EventHandler ==>|"Trigger Voice Workflow"| CmdPlayback
EventHandler -->|"End Session Context"| CmdHangup
%% High-Contrast Style System
classDef coreToken fill:#0f172a,stroke:#38bdf8,stroke-width:2px,color:#fff,rx:6px,ry:6px;
classDef adapterToken fill:#1e293b,stroke:#a855f7,stroke-width:2px,color:#fff,rx:6px,ry:6px;
classDef svcToken fill:#312e81,stroke:#ec4899,stroke-width:2px,color:#fff,rx:6px,ry:6px;
classDef cmdToken fill:#065f46,stroke:#10b981,stroke-width:2px,color:#fff,rx:6px,ry:6px;
class TelecomCore,StasisDialplan coreToken;
class InterceptionBus,AriSocket adapterToken;
class DotNetServices,StasisWorker,EventHandler svcToken;
class AutomationTarget,CmdPlayback,CmdHangup cmdToken;
```
---
Chunk #3
Architectural Directives
## Architectural Directives ### 1. Persistent Thread Safeties Because live ARI event streams write thousands of multi-node JSON events every minute, background services configure dedicated multithreading boundaries. Background consumer workers read incoming socket blocks cleanly using asynchronous loop wrappers (`await foreach`). ### 2. High-Speed API Command Authorization Outbound commands targeting active ARI REST endpoints append cryptographically signed credentials (`api_key=username:secret`) directly inside base parameter strings to completely prevent unauthorized instruction injections.