You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/communication-services/how-tos/call-automation-sdk/includes/redirect-inbound-telephony-calls-csharp.md
+40-11Lines changed: 40 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,30 +14,42 @@ ms.author: askaur
14
14
## Prerequisites
15
15
16
16
- An Azure account with an active subscription.
17
-
- A deployed [Communication Service resource](../../../quickstarts/create-communication-resource.md) and valid Connection String
18
-
-[Acquire a PSTN phone number from the Communication Service resource](../../../quickstarts/telephony/get-phone-number.md).
17
+
- A deployed [Communication Service resource](../../../quickstarts/create-communication-resource.md) and valid connection string found by selecting Keys in left side menu on Azure portal.
18
+
-[Acquire a PSTN phone number from the Communication Service resource](../../../quickstarts/telephony/get-phone-number.md). Note the phone number you acquired to use in this quickstart.
19
19
- The latest [.NET library](https://dotnet.microsoft.com/download/dotnet-core) for your operating system.
20
-
- A [web service application](/aspnet/core/web-api) to handle web hook callback events.
21
-
- Optional: [NGROK application](https://ngrok.com/) to proxy HTTP/S requests to a local development machine.
22
-
- The [ARMClient application](https://github.com/projectkudu/ARMClient), used to configure the Event Grid subscription.
23
-
- Obtain the NuGet package from the [Azure SDK Dev Feed](https://github.com/Azure/azure-sdk-for-net/blob/main/CONTRIBUTING.md#nuget-package-dev-feed)
24
-
-[An Event Grid subscription for Incoming Call](../../../how-tos/call-automation-sdk/subscribe-to-incoming-call.md)
25
20
26
21
## Create a new C# application
27
22
28
23
In the console window of your operating system, use the `dotnet` command to create a new web application with the name 'IncomingCallRedirect':
29
24
30
25
```console
31
-
dotnet new web -n IncomingCallSample
26
+
dotnet new web -n IncomingCallRedirect
32
27
```
33
28
34
29
## Install the NuGet package
35
30
36
31
During the preview phase, the NuGet package can be obtained by configuring your package manager to use the [Azure SDK Dev Feed](https://github.com/Azure/azure-sdk-for-net/blob/main/CONTRIBUTING.md#nuget-package-dev-feed)
37
32
33
+
Install the NuGet packages: [Azure.Communication.CallAutomation](https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-net/NuGet/Azure.Communication.CallAutomation/versions/) and [Azure.Messaging.EventGrid](https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-net/NuGet/Azure.Messaging.EventGrid/versions/) to your project.
In this quick-start, you'll use Ngrok tool to project a public URI to the local port so that your local application can be visited by the internet. The public URI is needed to receive the Event Grid IncomingCall event and Call Automation events using webhooks.
41
+
42
+
First, determine the port of the .NET application. Minimal API dynamically allocates a port for the project at the time of creation. Find out the http port in <PROJECT_ROOT>\Properties\launchSettings.json.
43
+

44
+
45
+
Then, install Ngrok and run Ngrok with the following command: ngrok http <replace_with_port>. This command will create a public URI like https://ff2f-75-155-253-232.ngrok.io/, and it is your Ngrok Fully Qualified Domain Name(Ngrok_FQDN). Keep Ngrok running while following the rest of this quick-start.
46
+
38
47
## Configure Program.cs to redirect the call
39
48
40
49
Using the minimal API feature in .NET 6, we can easily add an HTTP POST map and redirect the call.
50
+
51
+
In this code snippet, /api/incomingCall is the default route that will be used to listen for incoming calls. At a later step, you'll register this url with Event Grid. Since Event Grid requires you to prove ownership of your Webhook endpoint before it starts delivering events to that endpoint, the code sample also handles this one time validation by processing SubscriptionValidationEvent. This requirement prevents a malicious user from flooding your endpoint with events. For more information, see this [guide](../../../../event-grid/webhook-event-delivery.md).
awaitclient.RedirectCallAsync(incomingCallContext, newPhoneNumberIdentifier("<phone_number_to_redirect_call_to"));//this can be any phone number you have access to and should be provided in format +(countrycode)(phonenumber)
63
87
}
64
88
65
89
returnResults.Ok();
66
90
});
67
91
68
92
app.Run();
69
93
```
94
+
Update the placeholders in the code above for connection string and phone number to redirect to.
95
+
96
+
## Run the app
97
+
Open Your_Project_Name.csproj file in your project with Visual Studio, and then select Run button or press F5 on your keyboard.
Copy file name to clipboardExpand all lines: articles/communication-services/how-tos/call-automation-sdk/includes/redirect-inbound-telephony-calls-java.md
- A deployed [Communication Service resource](../../../quickstarts/create-communication-resource.md) and valid Connection String
18
-
-[Acquire a PSTN phone number from the Communication Service resource](../../../quickstarts/telephony/get-phone-number.md).
19
-
- Optional: [NGROK application](https://ngrok.com/) to proxy HTTP/S requests to a local development machine.
17
+
- A deployed [Communication Service resource](../../../quickstarts/create-communication-resource.md) and valid connection string found by selecting Keys in left side menu on Azure portal.
18
+
-[Acquire a PSTN phone number from the Communication Service resource](../../../quickstarts/telephony/get-phone-number.md). Note the phone number you acquired to use in this quickstart.
20
19
-[Java Development Kit (JDK)](/java/azure/jdk/?preserve-view=true&view=azure-java-stable) version 8 or above.
-[An Event Grid subscription for Incoming Call](../../../how-tos/call-automation-sdk/subscribe-to-incoming-call.md)
23
21
24
-
## Create a new Java application
22
+
## Create a new Java Spring application
25
23
26
-
Open your terminal or command window and navigate to the directory where you would like to create your Java application. Run the command below to generate the Java project from the maven-archetype-quickstart template.
Configure the [Spring Initializr](https://start.spring.io/) to create a new Java Spring application.
30
25
31
-
The command above creates a directory with the same name as `artifactId` argument. Under this directory, `src/main/java` directory contains the project source code, `src/test/java` directory contains the test source.
26
+
1. Set the Project to be a Maven Project.
27
+
2. Leave the rest as default unless you want to have your own customization.
28
+
3. Add Spring Web to Dependencies section.
29
+
4. Generate the application and it will be downloaded as a zip file. Unzip the file and start coding.
32
30
33
-
You'll notice that the 'generate' step created a directory with the same name as the artifactId. Under this directory, `src/main/java` directory contains source code, `src/test/java` directory contains tests, and `pom.xml` file is the project's Project Object Model, or POM.
31
+
## Install the Maven package
34
32
35
-
Update your application's POM file to use Java 8 or higher.
Since the Call Automation SDK version used in this QuickStart isn't yet available in Maven Central Repository, we need to configure an Azure Artifacts development feed, which contains the latest version of the Call Automation SDK.
45
36
46
-
Since the Call Automation SDK version used in this quick start isn't yet available in Maven Central Repository, we need to add an Azure Artifacts development feed, which contains the latest version of the Call Automation SDK.
37
+
Follow the instruction [here](https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-java/connect/maven) for adding [azure-sdk-for-java](https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-java) feed to your POM file.
47
38
48
-
Add the [azure-sdk-for-java feed](https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-java) to your `pom.xml`. Follow the instructions after clicking the “Connect to Feed” button.
39
+
**Add Call Automation package references:**
49
40
50
-
## Add package references
41
+
*azure-communication-callautomation* - Azure Communication Services Call Automation SDK package is retrieved from the Azure SDK Dev Feed configured above.
51
42
52
-
In your POM file, add the following dependencies for the project.
43
+
Look for the recently published version from [here](https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-java/maven/com.azure%2Fazure-communication-callautomation/versions)
53
44
54
-
**azure-communication-callautomation**
45
+
And then add it to your POM file like this (using version 1.0.0-alpha.20221101.1 as example)
55
46
56
-
Azure Communication Services Call Automation SDK package is retrieved from the Azure SDK Dev Feed configured above.
*azure-messaging-eventgrid* - Azure Event Grid SDK package: [com.azure : azure-messaging-eventgrid](https://search.maven.org/artifact/com.azure/azure-messaging-eventgrid). Data types from this package are used to handle Call Automation IncomingCall event received from the Event Grid.
66
58
67
-
Azure Event Grid SDK package: [com.azure : azure-messaging-eventgrid](https://search.maven.org/artifact/com.azure/azure-messaging-eventgrid). Data types from this package are used to handle Call Automation IncomingCall event received from the Event Grid.
Spark framework: com.sparkjava : spark-core. We’ll use this micro-framework to create a webhook (web api endpoint) to handle Event Grid events. You can use any framework to create a web api.
79
-
```xml
80
-
<dependency>
81
-
<groupId>com.sparkjava</groupId>
82
-
<artifactId>spark-core</artifactId>
83
-
<version>2.9.4</version>
84
-
</dependency>
85
-
```
86
-
87
-
**gson**
67
+
*gson* - Google Gson package: [com.google.code.gson : gson](https://search.maven.org/artifact/com.google.code.gson/gson) is a serialization/deserialization library to handle conversion between Java Objects and JSON.
88
68
89
-
Google Gson package: [com.google.code.gson : gson](https://search.maven.org/artifact/com.sparkjava/spark-core). A serialization/deserialization library to handle conversion between Java Objects and JSON.
90
69
```xml
91
70
<dependency>
92
71
<groupId>com.google.code.gson</groupId>
@@ -95,44 +74,91 @@ Google Gson package: [com.google.code.gson : gson](https://search.maven.org/arti
95
74
</dependency>
96
75
```
97
76
77
+
## Set up a public URI for the local application
78
+
79
+
In this quick-start, you'll use [Ngrok tool](https://ngrok.com/) to project a public URI to the local port so that your local application can be visited by the internet. The public URI is needed to receive the Event Grid `IncomingCall` event and Call Automation events using webhooks.
80
+
81
+
First, determine the port of your java application. `8080` is the default endpoint of a spring boot application.
82
+
83
+
Then, [install Ngrok](https://ngrok.com/download) and run Ngrok with the following command: `ngrok http <port>`. This command will create a public URI like `https://ff2f-75-155-253-232.ngrok.io/`, and it is your Ngrok Fully Qualified Domain Name(Ngrok_FQDN). Keep Ngrok running while following the rest of this quick-start.
84
+
98
85
## Redirect incoming call
99
86
100
-
In your editor of choice, open App.java file and update it with the following code to create an endpoint to receive IncomingCall events and redirect calls to another user.
101
-
```java
102
-
packagecom.communication.quickstart;
87
+
In your project folder, create a Controller.java file and update it to handle incoming calls.
In this code snippet, /api/incomingCall is the default route that will be used to listen for incoming calls. At a later step, we'll register this url with Event Grid. Since Event Grid requires you to prove ownership of your Webhook endpoint before it starts delivering events to that endpoint, the code sample also handles this one time validation by processing SubscriptionValidationEvent. This requirement prevents a malicious user from flooding your endpoint with events. For more information, see this [guide](../../../../event-grid/webhook-event-delivery.md).
Update the placeholders in the code above for connection string and phone number to redirect to.
135
155
136
-
## Run the code
156
+
## Run the app
137
157
138
-
To run your Java application, run maven compile, package, and execute commands. By default, SparkJava runs on port 4567, so the endpoint will be available at `http://localhost:4567/api/incomingCall`.
158
+
To run your Java application, run maven compile, package, and execute commands.
0 commit comments