コード例 #1
0
        public void SendSmsOverload_PassesToGeneratedOne(PhoneNumberIdentifier expectedFrom, PhoneNumberIdentifier expectedTo, string expectedMessage, SendSmsOptions expectedOptions)
        {
            Mock <SmsClient> mockClient = new Mock <SmsClient>()
            {
                CallBase = true
            };
            Response <SendSmsResponse>?expectedResponse  = default;
            CancellationToken          cancellationToken = new CancellationTokenSource().Token;
            var callExpression = BuildExpression(x => x.Send(It.IsAny <PhoneNumberIdentifier>(), It.IsAny <IEnumerable <PhoneNumberIdentifier> >(), It.IsAny <string>(), It.IsAny <SendSmsOptions>(), It.IsAny <CancellationToken>()));

            mockClient
            .Setup(callExpression)
            .Returns((PhoneNumberIdentifier from, IEnumerable <PhoneNumberIdentifier> to, string message, SendSmsOptions options, CancellationToken token) =>
            {
                Assert.AreEqual(expectedFrom, from);
                Assert.AreEqual(expectedTo, to.Single());
                Assert.AreEqual(expectedMessage, message);
                Assert.AreEqual(cancellationToken, token);
                Assert.AreEqual(expectedOptions, options);
                return(expectedResponse = new Mock <Response <SendSmsResponse> >().Object);
            });

            Response <SendSmsResponse> actualResponse = mockClient.Object.Send(expectedFrom, expectedTo, expectedMessage, expectedOptions, cancellationToken);

            mockClient.Verify(callExpression, Times.Once());
            Assert.AreEqual(expectedResponse, actualResponse);
        }
コード例 #2
0
 public void CallPhone(string phoneNumber)
 {
     var acsNumber = new PhoneNumberIdentifier(phoneNumber, phoneNumber);
     var receivers = new CommunicationIdentifier[] { acsNumber };
     var callOptions = new ACSStartCallOptions
     {
         AudioOptions = new ACSAudioOptions()
     };
     _call = _callAgent.StartCall(receivers, callOptions);
 }
コード例 #3
0
 /// <summary> Starts a release for the given phone number. </summary>
 /// <param name="phoneNumber"> The phone number in the release request. </param>
 /// <param name="cancellationToken"> The cancellation token to use. </param>
 /// <returns> A <see cref="ReleasePhoneNumberOperation"/>. </returns>
 public virtual ReleasePhoneNumberOperation StartReleasePhoneNumber(PhoneNumberIdentifier phoneNumber, CancellationToken cancellationToken = default)
 {
     using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(PhoneNumberAdministrationClient)}.{nameof(StartReleasePhoneNumber)}");
     scope.Start();
     try
     {
         return(StartReleasePhoneNumbers(new[] { phoneNumber }, cancellationToken));
     }
     catch (Exception ex)
     {
         scope.Failed(ex);
         throw;
     }
 }
コード例 #4
0
 /// <summary> Endpoint for unconfiguring a pstn number by removing the configuration. </summary>
 /// <param name="phoneNumber"> The phone number in the E.164 format. </param>
 /// <param name="cancellationToken"> The cancellation token to use. </param>
 /// <returns> A <see cref="Response"/>. </returns>
 public virtual Response UnconfigureNumber(PhoneNumberIdentifier phoneNumber, CancellationToken cancellationToken = default)
 {
     using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(PhoneNumberAdministrationClient)}.{nameof(UnconfigureNumber)}");
     scope.Start();
     try
     {
         return(RestClient.UnconfigureNumber(phoneNumber.Value, cancellationToken));
     }
     catch (Exception ex)
     {
         scope.Failed(ex);
         throw;
     }
 }
コード例 #5
0
 /// <summary> Sends an SMS message from a phone number that belongs to the authenticated account. </summary>
 /// <param name="from"> The sender&apos;s phone number in E.164 format that is owned by the authenticated account. </param>
 /// <param name="to"> The recipient&apos;s phone number in E.164 format. In this version, only one recipient in the list is supported. </param>
 /// <param name="message"> The contents of the message that will be sent to the recipient. The allowable content is defined by RFC 5724. </param>
 /// <param name="sendSmsOptions"> Optional configuration for sending SMS messages. </param>
 /// <param name="cancellationToken"> The cancellation token to use. </param>
 /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="from"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="to"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
 public virtual Response <SendSmsResponse> Send(PhoneNumberIdentifier from, IEnumerable <PhoneNumberIdentifier> to, string message, SendSmsOptions sendSmsOptions = null, CancellationToken cancellationToken = default)
 {
     using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SmsClient)}.{nameof(Send)}");
     scope.Start();
     try
     {
         Argument.AssertNotNullOrEmpty(from.PhoneNumber, nameof(from));
         return(RestClient.Send(from.PhoneNumber, to.Select(x => AssertNotNullOrEmpty(x.PhoneNumber, nameof(to))), message, sendSmsOptions, cancellationToken));
     }
     catch (Exception ex)
     {
         scope.Failed(ex);
         throw;
     }
 }
        private async Task CreateCallAsync(string sourcePhoneNumber, string targetPhoneNumber)
        {
            try
            {
                string appCallbackUrl = $"{this.appCallbackUrl}outboundcall/callback?{EventAuthHandler.GetSecretQuerystring}";

                //Preparing request data
                var source = await CreateUser();

                var target = new PhoneNumberIdentifier(targetPhoneNumber);
                CreateCallOptions createCallOption = new CreateCallOptions(
                    new Uri(appCallbackUrl),
                    new List <MediaType> {
                    MediaType.Audio
                },
                    new List <EventSubscriptionType> {
                    EventSubscriptionType.ParticipantsUpdated, EventSubscriptionType.DtmfReceived
                }
                    );
                createCallOption.AlternateCallerId = new PhoneNumberIdentifier(sourcePhoneNumber);

                Logger.LogMessage(Logger.MessageType.INFORMATION, "Performing CreateCall operation");

                callConnection = await callClient.CreateCallConnectionAsync(source,
                                                                            new List <CommunicationIdentifier>() { target },
                                                                            createCallOption, reportCancellationToken)
                                 .ConfigureAwait(false);

                Logger.LogMessage(Logger.MessageType.INFORMATION, $"CreateCallConnectionAsync response --> {callConnection.ToString()}, Call Connection Id: { callConnection.CallConnectionId}");
                Logger.LogMessage(Logger.MessageType.INFORMATION, $"Call initiated with Call Connection id: { callConnection.CallConnectionId}");

                RegisterToCallStateChangeEvent(callConnection.CallConnectionId);

                //Wait for operation to complete
                await callEstablishedTask.Task.ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.LogMessage(Logger.MessageType.ERROR, string.Format("Failure occured while creating/establishing the call. Exception: {0}", ex.Message));
                throw ex;
            }
        }
コード例 #7
0
 /// <summary> Starts a release for the given phone numbers. </summary>
 /// <param name="phoneNumber"> The phone number in the release request. </param>
 /// <param name="cancellationToken"> The cancellation token to use. </param>
 /// <returns> A <see cref="ReleasePhoneNumberOperation"/>. </returns>
 public virtual async Task <ReleasePhoneNumberOperation> StartReleasePhoneNumberAsync(PhoneNumberIdentifier phoneNumber, CancellationToken cancellationToken = default)
 {
     using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(PhoneNumberAdministrationClient)}.{nameof(StartReleasePhoneNumber)}");
     scope.Start();
     try
     {
         return(await StartReleasePhoneNumbersAsync(new[] { phoneNumber }, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception ex)
     {
         scope.Failed(ex);
         throw;
     }
 }
コード例 #8
0
 /// <summary> Endpoint for configuring a pstn number. </summary>
 /// <param name="pstnConfiguration"> Definition for pstn number configuration. </param>
 /// <param name="phoneNumber"> The phone number to configure. </param>
 /// <param name="cancellationToken"> The cancellation token to use. </param>
 /// <returns> A <see cref="Response"/>. </returns>
 public virtual async Task <Response> ConfigureNumberAsync(PstnConfiguration pstnConfiguration, PhoneNumberIdentifier phoneNumber, CancellationToken cancellationToken = default)
 {
     using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(PhoneNumberAdministrationClient)}.{nameof(ConfigureNumber)}");
     scope.Start();
     try
     {
         return(await RestClient.ConfigureNumberAsync(pstnConfiguration, phoneNumber.Value, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception ex)
     {
         scope.Failed(ex);
         throw;
     }
 }
コード例 #9
0
 /// <summary>
 /// Sends a SMS <paramref name="from"/> a phone number that is acquired by the authenticated account, <paramref name="to"/> another phone number.
 /// </summary>
 /// <param name="from">The sender's phone number that is owned by the authenticated account.</param>
 /// <param name="to">The recipient's phone number.</param>
 /// <param name="message">The contents of the message that will be sent to the recipient. The allowable content is defined by RFC 5724. If the message has more than 160 characters, the server will split it into multiple SMSs automatically.</param>
 /// <param name="sendSmsOptions">Optional configuration for sending SMS messages.</param>
 /// <param name="cancellationToken">The cancellation token for the underlying request.</param>
 /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="from"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="to"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
 public virtual Response <SendSmsResponse> Send(PhoneNumberIdentifier from, PhoneNumberIdentifier to, string message, SendSmsOptions sendSmsOptions = null, CancellationToken cancellationToken = default)
 {
     Argument.AssertNotNullOrEmpty(from.PhoneNumber, nameof(from));
     Argument.AssertNotNullOrEmpty(to.PhoneNumber, nameof(to));
     return(Send(from, new[] { to }, message, sendSmsOptions, cancellationToken));
 }
コード例 #10
0
 /// <summary>
 /// Sends a SMS <paramref name="from"/> a phone number that is acquired by the authenticated account, <paramref name="to"/> another phone number.
 /// </summary>
 /// <param name="from">The sender's phone number that is owned by the authenticated account.</param>
 /// <param name="to">The recipient's phone number.</param>
 /// <param name="message">The contents of the message that will be sent to the recipient. The allowable content is defined by RFC 5724. If the message has more than 160 characters, the server will split it into multiple SMSs automatically.</param>
 /// <param name="sendSmsOptions">Optional configuration for sending SMS messages.</param>
 /// <param name="cancellationToken">The cancellation token for the task.</param>
 /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="from"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="to"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
 public virtual async Task <Response <SendSmsResponse> > SendAsync(PhoneNumberIdentifier from, PhoneNumberIdentifier to, string message, SendSmsOptions sendSmsOptions = null, CancellationToken cancellationToken = default)
 {
     Argument.AssertNotNullOrEmpty(from.PhoneNumber, nameof(from));
     Argument.AssertNotNullOrEmpty(to.PhoneNumber, nameof(to));
     return(await SendAsync(from, new[] { to }, message, sendSmsOptions, cancellationToken).ConfigureAwait(false));
 }