Warning
We've observed inconsistent behavior in the Azure Durable Functions state management due to a combination of high frequency events from <ConversationRelay> and the way Durable Functions leverages queues and tables for state management. It also lacks proper CancellationToken support which is critical to be able to appropriately handle interrupts and cancel active LLM runs. This forced us to build in unnatural patterns for Azure Durable Functions which likely compounded the state management problem. We're actively looking to migrate away from Azure Durable Functions into Azure App Service. You can get a simple demo up and working quickly with this pattern, but we cannot recommend it for production use.
- An Azure account with an active subscription. Create an account for free.
- A Twilio Account. Create an account for free.
- A phone number
- Navigate to the Voice section, select General under Settings, and turn on the Predictive and Generative AI/ML Features Addendum in order to use ConversationRelay.
- Development Environment for .NET 9 (one option below)
- .NET 9.0
- Visual Studio Code
- C# extension for Visual Studio Code.
- Azure Functions extension for Visual Studio Code.
- Azurite extension for Visual Studio Code.
- Azure Developer CLI
- ngrok
Create a new resource group for easy resource isolation
- Manual Step - Setup Web PubSub to properly authenticate to the Function
- Navigate to your new resource group and select the
Function App
type resource. - Select Functions, then select App Keys
- Create a system key and note the value
- Navigate back to your resource group and select the
Web PubSub Service
type resource. - Select Settings, the select Settings again
- Edit the
cr
hub, then edit the provided Event Handler URL - Append the system key to the end of the URL after
?code=
- Save
- Navigate to your new resource group and select the
-
Setup a local.settings.json file (cp local.settings.json.sample local.settings.json)
- Azure.OpenAI
- Navigate to the new resource group and select the resource ending in
-project
then click Launch Studio - Select 'Models + Endpoints' in My assets section, then select a model, then set language to C#
- Copy the
DeploymentName
,Endpoint
, andAPIKey
into your settings file
- Navigate to the new resource group and select the resource ending in
- Azure.WebPubSub
- Navigate back to the new resource group and select the resource ending in
-webpubsub
- Select Settings, then select Keys
- Copy the Primary >
Connection String
into your settings file - Set the
HubName
tocr
if not already set.
- Navigate back to the new resource group and select the resource ending in
- Azure.KeyVault
- Navigate back to the new resource group and select the resource ending in
-kv
- Copy the
Vault URI
from the top right of the page into you settings file
- Navigate back to the new resource group and select the resource ending in
- Twilio
- Copy your
Account SID
andAuth Token
into your settings file from the Twilio Account Dashboard
- Copy your
- Azure.OpenAI
-
Ensure SDKs are working
dotnet --version
- You should see 9.*. If you don't you may need to add dotnet to your path.
azd auth login
- You should be asked to login via the portal.
-
Start Azurite using the Azurite Extention from the Command Palette
>Azurite: Start
-
Run the app from the terminal
func start
-
Open a terminal and start ngrok
ngrok http 7071
- make note of the forwarding URL
-
Configure your phone number
- Open your Active Numbers on your Twilio Account
- Set the incoming call handler (A call comes in)
- webhook
- {ngrok_url}/api/calls
- HTTP POST
- Set the call status handler (Call status changes)
- {ngrok_url}/api/call-status-update
- HTTP POST
- Set the incoming call handler (A call comes in)
- Open your Active Numbers on your Twilio Account
-
Place a call to the number, and check out the Conversation Relay Docs