1

Is it possible to receive a PSTN telephone call with Azure Communication Services?

All the docs and the demos talk about initiating a call to a known number.

My use case is that somebody rings a phone number from their mobile phone (PSTN) and I want to be able to handle the call.

I cant find any documentation that discusses this or how to do routing! For example, which route the call to a particular agent.

Have I missed something? Any thoughts?

iasksillyquestions
  • 5,558
  • 12
  • 53
  • 75

2 Answers2

1

For anybody looking.... you cant as of 18/03/2022

This came directly from a conversation with Microsoft.

You can initiate a call via the API, but you cannot receive a call made from a telephone on a PSTN or manage routing etc.

enter image description here

iasksillyquestions
  • 5,558
  • 12
  • 53
  • 75
0

This is now possible - I have implemented in my own application and it works well.

To allow incoming calls you have to purchase a Toll Free number in ACS - it is not supported with Local numbers. You then configure an Azure Event Grid service to subscribe to Incoming Call events on your ACS instance, and configure a webhook URL for it that points to your own API. Azure Event Grid then posts some data to your API when an incoming call is received which contains the "Incoming Call Context". A member of the ACS team called Jason Shave has created some useful Nugets to help with parsing the Azure Event Grid event data, see here.

Your API can then perform some logic, e.g. check your database to fetch the ACS unique identifier for connected user you want to forward the specific incoming call to, e.g. based on lookup of incoming call telephone number to check for assigned agent, you can then use the CallAutomation client SDK for .Net to redirect the Incoming Call Context to this identifier, and return an empty 200 response to Azure Event Grid so it knows the response has been handled and not to resend.

See full documentation on concepts involved here.

I would also add your endpoint for Azure Event Grid will need to pass validation from Azure - I've added support for that like so:

using Azure.Messaging.EventGrid;
using Azure.Messaging.EventGrid.SystemEvents;
...

        [AllowAnonymous]
        [HttpPost("~/api/call-automation/event")]
        public async Task<IActionResult> Event([FromBody] EventGridEvent[] events)
        {
            int eventCount = 0;

            foreach (var eventGridEvent in events)
            {
                try
                {
                    logger.LogWarning($"EventGridData[{eventCount++}] data is: {JsonConvert.SerializeObject(eventGridEvent)}");

                    // Validate whether EventType is of "Microsoft.EventGrid.SubscriptionValidationEvent"
                    switch (eventGridEvent.EventType)
                    {
                        case SystemEventNames.EventGridSubscriptionValidation:
                            {
                                var eventData = eventGridEvent.Data.ToObjectFromJson<SubscriptionValidationEventData>();

                                var responseData = new SubscriptionValidationResponse
                                {
                                    ValidationResponse = eventData.ValidationCode
                                };

                                if (responseData.ValidationResponse != null)
                                {
                                    return Ok(responseData);
                                }
                            }
                            break;

                            // Now you can handle incoming call 
Breeno
  • 3,007
  • 2
  • 31
  • 30