Reputation: 4940
I have a .NET console app that is generating calls and I need to take action based on whether or not the call was answered. The call is successful, I answer it on my test cellphone and I hear the speech from my xml file. The status of the CallResource object, however, is always "queued". What is the proper way to get the final status of the call?
Code:
Dim phonecall = CallResource.Create([to]:=New Types.PhoneNumber(oncallnumber), from:=New Types.PhoneNumber(twilionumber), url:=New Uri(oncallmessagefile), method:="get")
Dim OnCallStatus As CallResource.StatusEnum
'' wait until the call is successful, not answered, or fails
Do
OnCallStatus = phonecall.Status
Debug.WriteLine(OnCallStatus.ToString)
System.Threading.Thread.Sleep(5000)
Loop Until OnCallStatus = CallResource.StatusEnum.NoAnswer Or OnCallStatus = CallResource.StatusEnum.Completed Or OnCallStatus = CallResource.StatusEnum.Failed
Upvotes: 1
Views: 80
Reputation: 4940
I have found an approach that works:
Dim phonecall = CallResource.Create([to]:=New Types.PhoneNumber(oncallnumber), from:=New Types.PhoneNumber(twilionumber), url:=New Uri(oncallmessagefile), method:="get")
Dim sid As String = phonecall.Sid
Dim OnCallStatus As CallResource.StatusEnum
'' wait until the call is successful, not answered, or fails
Do
OnCallStatus = CallResource.Fetch(sid).Status
Debug.WriteLine(Now() & " - " & OnCallStatus.ToString)
System.Threading.Thread.Sleep(1000)
Loop Until OnCallStatus = CallResource.StatusEnum.NoAnswer Or OnCallStatus = CallResource.StatusEnum.Completed Or OnCallStatus = CallResource.StatusEnum.Failed
Upvotes: 1