UCMA 3 How-To: Decline A Call

In Speech Server we had an activity for declining a call. Typically this was used when you wanted to pull your application "off-line" for some reason. UCMA 3.0 doesn't have this activity, but the Core API still has support for it. Rather than declining the call within the Workflow, we'll be declining the call prior to the Workflow starting. I'll show how to do this using the out-of-the-box code you get when creating a new CommunicationWorkflow. If you look inside Program.cs you'll find the StartWorkflow() method. When we reach this point in the application we already have a "call" object which makes it trivial to Decline the call. The default code looks like this:

   1: private static void StartWorkflow(Call call, SipRequestData requestData)
   2: {
   3:   Debug.Assert(call != null, "call != null");
   4:   Debug.Assert(call is AudioVideoCall || call is InstantMessagingCall,
   5:       "Only AudioVideoCall and InstantMessagingCall are subscribed to above.");
   6:
   7:   WorkflowInstance workflowInstance = _workflowRuntime.CreateWorkflow(typeof(Workflow1));

We'll insert our code starting at line 6, we'll also add some intelligence so that it allows me to call from my developer line while rejecting everyone else.

   1: private static void StartWorkflow(Call call, SipRequestData requestData)
   2: {
   3:     Debug.Assert(call != null, "call != null");
   4:     Debug.Assert(call is AudioVideoCall || call is InstantMessagingCall,
   5:      "Only AudioVideoCall and InstantMessagingCall are subscribed to above.");
   6:
   7:     if (!call.RemoteEndpoint.Participant.UserAtHost.StartsWith("1234@"))
   8:     {
   9:      call.Decline(new CallDeclineOptions(503));
  10:      return;
  11:     }
  12:
  13:     WorkflowInstance workflowInstance = _workflowRuntime.CreateWorkflow(typeof(Workflow1));
  14: ...

A couple of tips:

  1. Take a look at the call object. It has a lot of interesting properties that let you make intelligent decisions about the call before your workflow has started.
  2. Make sure you use a SIP code (CallDeclineOptions) that your gateways understand and make sense. You don't want to toss a BUSY HERE if it isn't in fact BUSY.

No Comments