protected override void Ready()
        {
            // Create a new phone call and dial it immediately, block until it's answered, times out,
            // busy, or another error occurs
            DialResult resultDial = Client.Calling.DialPhone("+19312989898", "+17742989898");

            // Prompt with TTS and collect the PIN, block until it's finished or an error occurs
            PromptResult resultPrompt = resultDial.Call.PromptTTS(
                "Welcome to SignalWire! Please enter your PIN",
                new CallCollect
            {
                InitialTimeout = 10,
                Digits         = new CallCollect.DigitsParams {
                    Max = 4, DigitTimeout = 5
                }
            });

            if (resultPrompt.Successful)
            {
                // Play back what was collected
                resultDial.Call.PlayTTS("You entered " + resultPrompt.Result + ". Thanks and good bye!");
            }

            // Hangup
            resultDial.Call.Hangup();
        }
示例#2
0
        private async void HandleDial(Command command, RemoteUser remoteUser)
        {
            var callerNumber = _commandBuilder.GetUnderlyingObject <string>(command);
            var opponent     = _connectionsManager.FindRemoteUserByNumber(callerNumber);

            var dialResult = new DialResult();

            if (opponent == null)
            {
                var opponentUser = _usersRepository.GetByNumber(callerNumber);
                if (opponentUser != null)
                {
                    _pushSender.SendVoipPush(opponentUser.PushUri, remoteUser.User.Number, remoteUser.User.Number);
                    var resultCommand = await _connectionsManager.PostWaiter(opponentUser.UserId, CommandName.IncomingCall);

                    var answerType = _commandBuilder.GetUnderlyingObject <AnswerResultType>(resultCommand);
                    if (answerType == AnswerResultType.Answered)
                    {
                        dialResult.Result       = DialResultType.Answered;
                        opponent.IsInCallWith   = remoteUser;
                        remoteUser.IsInCallWith = opponent;
                    }
                    else
                    {
                        dialResult.Result = DialResultType.Declined;
                    }
                }
                else
                {
                    dialResult.Result = DialResultType.NotFound;
                }
            }
            else
            {
                var incomingCallCommand = _commandBuilder.Create(CommandName.IncomingCall, callerNumber);
                var resultCommand       = await opponent.Peer.SendCommandAndWaitAnswer(incomingCallCommand);

                var answerType = _commandBuilder.GetUnderlyingObject <AnswerResultType>(resultCommand);
                if (answerType == AnswerResultType.Answered)
                {
                    dialResult.Result       = DialResultType.Answered;
                    opponent.IsInCallWith   = remoteUser;
                    remoteUser.IsInCallWith = opponent;
                }
                else
                {
                    dialResult.Result = DialResultType.Declined;
                }
            }
            _commandBuilder.ChangeUnderlyingObject(command, dialResult);
            remoteUser.Peer.SendCommand(command);
        }
示例#3
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void Ready()
        {
            DialResult resultDial = Client.Calling.DialPhone(ToNumber, FromNumber);

            if (!resultDial.Successful)
            {
                Logger.LogError("Call was not answered");
                Completed.Set();
                return;
            }

            Call call = resultDial.Call;
            TaskCompletionSource <bool> eventing = new TaskCompletionSource <bool>();

            call.OnFaxError += (a, c, e, p) =>
            {
                Logger.LogError("Actual fax send had an error");
                eventing.SetResult(true);
            };
            call.OnFaxFinished += (a, c, e, p) =>
            {
                var settings = p.Fax.ParametersAs <CallingEventParams.FaxParams.FaxSettings.FinishedSettings>();
                if (settings.Success)
                {
                    Successful = true;
                }
                else
                {
                    Logger.LogError("Actual fax delivery had an issue: {0}", settings.ResultText);
                }
                eventing.SetResult(true);
            };

            FaxResult sendResult = call.FaxSend(Document);

            if (!sendResult.Successful)
            {
                Successful = false;
                Logger.LogError("Send fax was unsuccessful");
            }
            else
            {
                eventing.Task.Wait();
                if (!Successful)
                {
                    Logger.LogError("Fax send did not give a successful finished event");
                }
            }

            Completed.Set();
        }
示例#4
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void Ready()
        {
            // Create the first outbound call leg to the inbound DID associated to the context this client is receiving
            // This will block until the call is answered, times out, busy, or an error occurred
            DialResult resultDial = Client.Calling.DialPhone(ToNumber, FromNumber);

            if (!resultDial.Successful)
            {
                Logger.LogError("Call1 was not answered");
                Completed.Set();
                return;
            }

            // The call was answered, try to connect another outbound call to it
            // The top level list of the devices represents entries that will be called in serial,
            // one at a time.  The inner list of devices represents a set of devices to call in
            // parallel with each other.  Ultimately only one device wins by answering first.
            ConnectResult resultConnect = resultDial.Call.Connect(new List <List <CallDevice> >
            {
                new List <CallDevice>
                {
                    new CallDevice
                    {
                        Type       = CallDevice.DeviceType.phone,
                        Parameters = new CallDevice.PhoneParams
                        {
                            ToNumber   = ToNumber,
                            FromNumber = FromNumber,
                        }
                    }
                }
            });

            if (!resultConnect.Successful)
            {
                Logger.LogError("Call2 was not connected");
            }

            // Hangup both calls
            resultConnect.Call?.Hangup();
            resultDial.Call.Hangup();

            // Mark the test successful and terminate
            Successful = resultConnect.Successful;
            Completed.Set();
        }
示例#5
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void Ready()
        {
            // Create the first outbound call leg to the inbound DID associated to the context this client is receiving
            // This will block until the call is answered, times out, busy, or an error occurred
            DialResult resultDial = Client.Calling.DialPhone(ToNumber, FromNumber, maxDuration: 15);

            if (!resultDial.Successful)
            {
                Logger.LogError("Call was not answered");
                Completed.Set();
                return;
            }

            Successful = resultDial.Call.WaitForEnded(TimeSpan.FromSeconds(20));

            // Mark the test successful and terminate
            Completed.Set();
        }
示例#6
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void Ready()
        {
            DialResult resultDial = Client.Calling.DialPhone(ToNumber, FromNumber);

            if (!resultDial.Successful)
            {
                Logger.LogError("Call was not answered");
                return;
            }

            Call call = resultDial.Call;

            FaxResult sendResult = call.FaxSend(Document);

            if (!sendResult.Successful)
            {
                Successful = false;
                Logger.LogError("Send fax was unsuccessful");
            }
        }
示例#7
0
        protected override void Ready()
        {
            // Create a new phone call and dial it immediately, block until it's answered, times out, busy, or another error occurs
            DialResult resultDial = Client.Calling.DialPhone("+1XXXXXXXXXX", "+1YYYYYYYYYY");

            if (!resultDial.Successful)
            {
                // The call was not answered successfully, stop the consumer and bail out
                Stop();
                return;
            }

            // Play an audio file, block until it's finished or an error occurs
            resultDial.Call.PlayAudio("https://cdn.signalwire.com/default-music/welcome.mp3");

            // Hangup
            resultDial.Call.Hangup();

            // Stop the consumer
            Stop();
        }
示例#8
0
        public static void Main()
        {
            using (Client client = new Client("YOU_PROJECT_ID", "YOU_PROJECT_ID"))
            {
                // Assign callbacks
                client.OnReady += c =>
                {
                    // This callback cannot block, so create a threaded task
                    Task.Run(() =>
                    {
                        /*
                         *  SendResult resultSend = client.Messaging.Send("joshebosh", "+1XXXYYYZZZZ", "+1XXXYYYZZZZ");
                         *
                         *  if (resultSend.Successful)
                         *  {
                         *          // Message has been queued, you can subscribe to MessagingAPI.OnMessageStateChange to receive further updates
                         *
                         *  }
                         */
                        DialResult resultDial = client.Calling.DialPhone("+1XXXYYYZZZZ", "+1XXXYYYZZZZ");

                        if (resultDial.Successful)
                        {
                            // Your call has been answered, use resultDial.Call to access it
                            Console.Write(resultDial.Call);
                            // Play an audio file, block until it's finished or an error occurs
                            resultDial.Call.PlayAudio("https://cdn.signalwire.com/default-music/welcome.mp3");
                        }
                    });
                };

                // Connect the client
                client.Connect();

                // Prevent exit until a key is pressed
                Console.Write("Press any key to exit...");
                Console.ReadKey(true);
            }
        }
示例#9
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void Ready()
        {
            DialResult resultDial = Client.Calling.DialPhone(ToNumber, FromNumber);

            if (!resultDial.Successful)
            {
                Logger.LogError("Call was not answered");
                Completed.Set();
                return;
            }

            Call call = resultDial.Call;
            TaskCompletionSource <bool> eventing = new TaskCompletionSource <bool>();

            call.OnSendDigitsFinished += (a, c, e, p) =>
            {
                Successful = true;
                eventing.SetResult(true);
            };

            SendDigitsResult sendResult = call.SendDigits(DigitString);

            if (!sendResult.Successful)
            {
                Successful = false;
                Logger.LogError("Send digits was unsuccessful");
            }
            else
            {
                eventing.Task.Wait();
                if (!Successful)
                {
                    Logger.LogError("Send digits did not give a successful finished event");
                }
            }

            call.Hangup();
            Completed.Set();
        }
示例#10
0
 public void Dial(CiscoTelePresenceCodec codec, DialResult callback)
 {
     try
     {
         var calls = _bookingData.Element("DialInfo").Element("Calls").Elements("Call");
         foreach (
             var number in
             calls.Select(call => call.Element("Number")).Where(number => number != null && !number.IsEmpty))
         {
             codec.Calls.Dial(number.Value, new[]
             {
                 new CodecCommandArg("BookingId", Id),
             }, callback);
             return;
         }
         callback.Invoke(500, "No calls to dial for this booking", 0);
     }
     catch (Exception e)
     {
         CloudLog.Error("Error trying to dial booking, {0}", e.Message);
         callback.Invoke(500, string.Format("Error: {0}", e.Message), 0);
     }
 }
示例#11
0
        internal void Dial(string number, CodecCommandArg[] args, DialResult callback)
        {
#if DEBUG
            Debug.WriteInfo("Codec Dial", "Checking Capabilities");
            Debug.WriteInfo("  MaxCalls", "{0}", _codec.Capabilities.Conference.MaxCalls);
            Debug.WriteInfo("  MaxActiveCalls", "{0}", _codec.Capabilities.Conference.MaxActiveCalls);
            Debug.WriteInfo("  MaxAudioCalls", "{0}", _codec.Capabilities.Conference.MaxAudioCalls);
            Debug.WriteInfo("  MaxVideoCalls", "{0}", _codec.Capabilities.Conference.MaxVideoCalls);
            Debug.WriteInfo("  NumberOfActiveCalls", "{0}", _codec.SystemUnit.State.NumberOfActiveCalls);
            Debug.WriteInfo("  NumberOfSuspendedCalls", "{0}", _codec.SystemUnit.State.NumberOfSuspendedCalls);
            Debug.WriteInfo("  TotalNumberOfCalls", "{0}", _codec.SystemUnit.State.TotalNumberOfCalls);
#endif
            var numberOfConnectedVideoCalls = this.Count(c => c.Connected && c.CallType == CallType.Video);
            var shouldHoldACall             = (_codec.SystemUnit.State.NumberOfActiveCalls > 0 &&
                                               _codec.SystemUnit.State.NumberOfActiveCalls ==
                                               _codec.Capabilities.Conference.MaxActiveCalls) ||
                                              (numberOfConnectedVideoCalls > 0 && numberOfConnectedVideoCalls ==
                                               _codec.Capabilities.Conference.MaxVideoCalls);

            if (shouldHoldACall)
            {
#if DEBUG
                Debug.WriteWarn("Codec needs to hold another call before calling!");
#endif
                try
                {
                    var lastConnectedCall = _codec.Calls.LastOrDefault(c => c.Connected);
                    if (lastConnectedCall != null)
                    {
                        lastConnectedCall.Hold();
                    }
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e);
                }
            }

            var cmd = new CodecCommand("", "Dial");
            cmd.Args.Add("Number", number);
            cmd.Args.Add(args);
            var requestId = _codec.SendCommandAsync(cmd, (id, ok, result) =>
            {
                var callBackInfo = _dialCallbacks[id];

                _dialCallbacksLock.Enter();
                _dialCallbacks.Remove(id);
                _dialCallbacksLock.Leave();

                Debug.WriteInfo("Dial Result Callback", "Request {0}, OK = {1}\r\n{2}", id, ok, result);

                if (ok)
                {
                    var callId = int.Parse(result.Element("CallId").Value);
                    Debug.WriteSuccess("Dial Result OK, call {0}", callId);
                    callBackInfo.CallBack(0, "OK", callId);
                    return;
                }

                try
                {
                    var cause   = int.Parse(result.Element("Cause").Value);
                    var message = result.Element("Description").Value;
                    Debug.WriteError("Dial Failed, Error {0} - {1}", cause, message);
                    callBackInfo.CallBack(cause, message, 0);
                }
                catch
                {
                    Debug.WriteError("Dial Result",
                                     result != null ? result.ToString(SaveOptions.DisableFormatting) : "Unknown Error");
                }
            });

            var info = new DialCallBackInfo()
            {
                NumberDialed = number,
                CallBack     = callback
            };

            _dialCallbacksLock.Enter();
            _dialCallbacks[requestId] = info;
            _dialCallbacksLock.Leave();
        }
示例#12
0
 public void DialNumber(string number, DialResult callback)
 {
     Dial(number, new CodecCommandArg[] {}, callback);
 }
示例#13
0
 public void Dial(DialResult callback)
 {
     Contact.Codec.Calls.DialNumber(Number, callback);
 }
示例#14
0
 public void Redial(DialResult callback)
 {
     _codec.Calls.DialNumber(CallbackNumber, callback);
 }