|
| 1 | +--- |
| 2 | +title: Building Answer Machine Detection |
| 3 | +titleSuffix: An Azure Communication Services concept document |
| 4 | +description: Learn how to |
| 5 | +author: Kunaal |
| 6 | +ms.service: azure-communication-services |
| 7 | +ms.subservice: call-automation |
| 8 | +ms.topic: conceptual |
| 9 | +ms.date: 03/07/2025 |
| 10 | +ms.author: kpunjabi |
| 11 | +ms.custom: public_preview |
| 12 | +--- |
| 13 | + |
| 14 | +# Implementing Answer Machine Detection with Call Automation |
| 15 | + |
| 16 | +Answer Machine Detection (AMD) helps contact centers identify whether a call is answered by a human or an answering machine. This article describes how to implement an AMD solution using Dual-Tone Multi-Frequency (DTMF) tones with Azure Communication Services existing play and recognize APIs. |
| 17 | + |
| 18 | +To achieve this goal, developers can implement logic that uses the call connected event and plays an automated message. This message requests the callee to press a specific key to verify they're human before connecting them to an agent or playing a more specific message. |
| 19 | + |
| 20 | +## Step-by-step guide |
| 21 | +1. Create an outbound call. For more information about creating outbound calls, see [Make an outbound call using Call Automation](../../quickstarts/call-automation/quickstart-make-an-outbound-call.md). |
| 22 | +2. Once the call is answered, you get a `CallConnected` event. This event lets your application know that the call is answered. At this stage, it could be a human or an answer machine. |
| 23 | +3. After receiving the `CallConnected` event your application should use the [recognize API](./recognize-action.md) and play a message to the callee requesting them to press a number on their dial pad to validate they're human, for example, your application might say "This is a call from [your company name] regarding [reason for call]. Press 1 to be connected to an agent." |
| 24 | +4. If the user presses a key on the dialpad, Azure Communication Services sends a `RecognizeCompleted` event to your application. This indicates that a human answered the call and you should continue with your regular workflow. |
| 25 | +5. If no DTMF input is received, Azure Communication Services sends a `RecognizeFailed` event to your application. This indicates that this call went to voicemail and you should follow your voicemail flow for this call. |
| 26 | + |
| 27 | +## Example code |
| 28 | + |
| 29 | +```csharp |
| 30 | +//... rest of your code |
| 31 | +
|
| 32 | +var ttsMessage = "This is a call from [your company name] regarding [reason for call]. Please press 1 to be connected to an agent."; |
| 33 | +var playSource = new TextSource(ttsMessage) |
| 34 | +{ |
| 35 | + PlaySourceId = "playSourceId" |
| 36 | +}; |
| 37 | + |
| 38 | +var playOptions = new PlayOptions |
| 39 | +{ |
| 40 | + Loop = false |
| 41 | +}; |
| 42 | + |
| 43 | +callConnection.Play(playSource, playOptions); |
| 44 | + |
| 45 | +var recognizeOptions = new RecognizeOptions(new DtmfOptions(new[] { DtmfTone.One })) |
| 46 | +{ |
| 47 | + InterruptPrompt = false, |
| 48 | + InitialSilenceTimeout = TimeSpan.FromSeconds(5), |
| 49 | + PlayPrompt = playSource |
| 50 | +}; |
| 51 | + |
| 52 | +var recognizeResult = callConnection.Recognize(recognizeOptions); |
| 53 | + |
| 54 | +// Handle the recognition result |
| 55 | +if (recognizeResult.Status == RecognizeResultStatus.Recognized && recognizeResult.RecognizedTone == DtmfTone.One) |
| 56 | +{ |
| 57 | + // Connect the call to an agent |
| 58 | + Console.WriteLine("Human detected. Connecting to an agent..."); |
| 59 | + // Add your logic to connect the call to an agent |
| 60 | +} |
| 61 | +else |
| 62 | +{ |
| 63 | + // Classify the call as an answering machine |
| 64 | + Console.WriteLine("No response detected. Classifying as an answering machine..."); |
| 65 | + // Add your logic to handle answering machine |
| 66 | +} |
| 67 | + |
| 68 | +//... rest of your code |
| 69 | +``` |
| 70 | + |
| 71 | +## Next steps |
| 72 | +- Learn more about [Call Automation](../../concepts/call-automation/call-automation.md) and its features. |
| 73 | +- Learn more about [Play action](../../concepts/call-automation/play-action.md). |
| 74 | +- Learn more about [Recognize action](../../concepts/call-automation/recognize-action.md). |
0 commit comments