Skip to content

Commit

Permalink
#3133279 Direct routing GA - Quick Starts (#79)
Browse files Browse the repository at this point in the history
* #3133279 Direct routing GA - Quick Starts
Add Quick Start code for dotnet

* #3133279 Direct routing GA - Quick Starts
correction

* #3133279 Direct routing GA - Quick Starts
correction

* #3133279 Direct routing GA - Quick Starts
Remove VS installation dependency

* #3133279 Direct routing GA - Quick Starts
Remove white-space

---------

Co-authored-by: Nikita Kuklich <[email protected]>
  • Loading branch information
nikuklic and nikuklic authored Mar 27, 2023
1 parent 2fb8e26 commit c5733a9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
14 changes: 14 additions & 0 deletions DirectRouting/DirectRouting.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Communication.PhoneNumbers" Version="1.1.0-beta.3" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions DirectRouting/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Azure.Communication.PhoneNumbers.SipRouting;

var connectionString = "endpoint=https://<RESOURCE_NAME>.communication.azure.com/;accesskey=<ACCESS_KEY>";
var client = new SipRoutingClient(connectionString);

var usSbcFqdn = "sbc.us.contoso.com";
var euSbcFqdn = "sbc.eu.contoso.com";
var sbcPort = 1234;
var usTrunk = new SipTrunk(usSbcFqdn, sbcPort);
var euTrunk = new SipTrunk(euSbcFqdn, sbcPort);

var response = await client.SetTrunksAsync(new List<SipTrunk> { usTrunk, euTrunk });

Console.WriteLine($"SetTrunks operation result: { response.Status }.{Environment.NewLine}Trunks: { response.Content }");

var usRoute = new SipTrunkRoute("UsRoute", "^\\+1(\\d{10})$", trunks: new List<string> { usSbcFqdn });
var defaultRoute = new SipTrunkRoute("DefaultRoute", "^\\+\\d+$", trunks: new List<string> { usSbcFqdn, euSbcFqdn });

response = await client.SetRoutesAsync(new List<SipTrunkRoute> { usRoute, defaultRoute });

Console.WriteLine($"SetRoutes operation result: {response.Status}.{Environment.NewLine}Routes: {response.Content}");
39 changes: 39 additions & 0 deletions DirectRouting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
page_type: sample
languages:
- csharp
products:
- azure
- azure-communication-services
---


# Direct Routing Configuration

For full instructions on how to build this code sample from scratch, look at [Quickstart: Direct Routing](https://docs.microsoft.com/azure/communication-services/quickstarts/telephony-sms/voice-routing-sdk-config?pivots=programming-language-csharp)

## Prerequisites

- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
- The latest version [.NET Core client library](https://dotnet.microsoft.com/download/dotnet-core) for your operating system.
- An active Communication Services resource and connection string. [Create a Communication Services resource](https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-net).

## Code Structure

- **./DirectRouting/Program.cs:** Core application code with manage phone numbers implementation.
- **./DirectRouting/DirectRouting.csproj:** Project configuration file.

## Before running sample code

1. Open an instance of PowerShell, Windows Terminal, Command Prompt or equivalent and navigate to the directory that you'd like to clone the sample to.
2. `git clone https://github.com/Azure-Samples/Communication-Services-dotnet-quickstarts.git`
3. With the `Connection String` procured in pre-requisites, add it to the **DirectRouting/program.cs** file. Assign your connection string in line 3:
```csharp
var connectionString = "endpoint=https://<RESOURCE_NAME>.communication.azure.com/;accesskey=<ACCESS_KEY>";
```

## Run Locally

```console
dotnet run
```

0 comments on commit c5733a9

Please sign in to comment.