AsteriskAri.Service 1.1.1

dotnet add package AsteriskAri.Service --version 1.1.1
                    
NuGet\Install-Package AsteriskAri.Service -Version 1.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AsteriskAri.Service" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AsteriskAri.Service" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="AsteriskAri.Service" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AsteriskAri.Service --version 1.1.1
                    
#r "nuget: AsteriskAri.Service, 1.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AsteriskAri.Service@1.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AsteriskAri.Service&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=AsteriskAri.Service&version=1.1.1
                    
Install as a Cake Tool

AsterAri.Service

REST + WebSocket client for working with Asterisk ARI (Stasis)

The library is designed to develop applications based on Stasis ARI using Dependency Injection and architecture approaches ASP.NET Core (.NET 8).

It allows you to conveniently manage Asterisk entities and build a full-fledged call processing logic.

Opportunities

  • Working via REST + WebSocket
  • Integration with DI (ASP.NET Core)
  • Management:
    • Channels
    • Bridges
    • Playbacks
    • Recordings
    • endpoints
    • Apps
  • Call processing pipeline support
  • Lifecycle management via scope sessions
  • Parsing Asterisk events only if someone is subscribed to this event
  • Using the http connection pool

Session Lifecycle

  • During the Stasis Start event:
    • a scope (DI scope) is being created, a separate call session
    • passing through the specified middlewares
  • During the session:
    • events are being processed
    • resources (channels, bridges, etc.) are managed.
  • At the end of the session:
    • all resources are being released
    • all channels connected to the bridge are terminated
Stasis Enter
    ↓
Create Scope (DI)
    ↓
Middlewares
    ↓
Stasis Handler / Call Logic
    ↓
Bridges

Redirect

When redirecting from stasis to stasis:

  • the current session is ending
  • a new session is being created
  • shared data is saved between sessions

⚠️ The last session may NOT be completed if your logic does not handle the client shutdown event. You may need this behavior, but then you should avoid using shared session resources.

Usage example

appsettings.json:

{
  "Asterisk": {
    "Hostname": "192.168.1.230",
    "Port": 8088,
    "AppName": "TestARI",
    "UserName": "asterisk",
    "Password": "asterisk",
    "UseSsl": false
  }
}

program.cs:


builder.Services.AddServerAri(option =>
{
    option.ConnectOptions = new AriConnectOptions(config.GetSection("Asterisk"));
    
    option.AddStasisHandler<DefaultStasis>("Call");
    option.AddStasisHandler<ExternalStasis>("ExternalStasis"); 
    option.AddStasisHandler<TestDtmfStasis>("TestDtmf");

    option.AddDtmfHandler<TalkDtmfHandler>();
    
    //the order of addition is important
    option.AddMiddleware<ExceptionAriMiddleware>();
});

call processing logic for ExternalStasis:


public override async Task Handler()
{
    ClientChannel = clientSessionAri.Initiator;
    logger.LogInformation("A new call from a client {Number} {ChannelId}", ClientChannel.PhoneNumber, ClientChannel.Id);
    
    await IntroStep();
    AnswerChannel = await CallStep();
    await TalkStep();
}

/// <summary>
/// Playing the intro to the client
/// </summary>
private async Task IntroStep()
{
    var clientHelloSound = "sound:en/hello";
    var soundState = await bridgeFactory.CreateBridgeAsync<BridgeSound>();
    await soundState.Handler(clientHelloSound);
}

/// <summary>
/// We are calling all managers.
/// </summary>
/// <returns>Returns the responding manager</returns>
private async Task<ChannelAri> CallStep()
{
    var number1 = new PjsipNumber("3333");
    var number2 = new PjsipNumber("3334");
    var ringState = await bridgeFactory.CreateBridgeAsync<BridgeRing>();
    var ringModel = new BridgeRingModel(ClientChannel,[number1, number2]);
    return await ringState.Handler(ringModel);
}

/// <summary>
/// The client's conversation with the manager
/// </summary>
/// <returns>Returns when the conversation is over</returns>
private async Task TalkStep()
{
    TalkState = await bridgeFactory.CreateBridgeAsync<BridgeTalk>();
    var model = new BridgeTalkModel(ClientChannel, AnswerChannel!, true);
    await TalkState.Handler(model);
}

See the full example in the DemoApp

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 123 6/7/2026
1.1.0 121 5/31/2026
1.0.6 115 5/8/2026