示例#1
0
        public void CreateCall()
        {
            CommunicationIdentityClient communicationIdentityClient = CreateInstrumentedCommunicationIdentityClient();
            var source           = communicationIdentityClient.CreateUser();
            var targets          = new[] { new PhoneNumberIdentifier(TestEnvironment.TargetPhoneNumber) };
            var createCallOption = new CreateCallOptions(
                new Uri(TestEnvironment.AppCallbackUrl),
                new[] { MediaType.Audio },
                new[] {
                EventSubscriptionType.ParticipantsUpdated,
                EventSubscriptionType.DtmfReceived
            });
            CallingServerClient callingServerClient = CreateInstrumentedCallingServerClient();

            Console.WriteLine("Performing CreateCallConnection operation");
            #region Snippet:Azure_Communication_Call_Tests_CreateCall
            var callConnection = callingServerClient.CreateCallConnection(
                //@@ source: new CommunicationUserIdentifier("<source-identifier>"), // Your Azure Communication Resource Guid Id used to make a Call
                //@@ targets: new List<CommunicationIdentifier>() { new PhoneNumberIdentifier("<targets-phone-number>") }, // E.164 formatted recipient phone number
                //@@ options: createCallOption // The options for creating a call.
                /*@@*/ source: source,
                /*@@*/ targets: targets,
                /*@@*/ options: createCallOption
                );
            Console.WriteLine($"Call connection id: {callConnection.Value.CallConnectionId}");
            #endregion Snippet:Azure_Communication_Call_Tests_CreateCall
        }
示例#2
0
        public static async Task CallServiceBusAsync(

            [ServiceBusTrigger("communication", "call", Connection = "AzureWebJobsServiceBus")]
            SmsMessage msg,
            [TwilioCall(AccountSidSetting = "TwilioSid", AuthTokenSetting = "TwilioToken", From = "+1 203-347-4577")] IAsyncCollector <CreateCallOptions> options,
            [Inject] IHostUriService hostUriService)
        {
            var from = new PhoneNumber("+1 203-347-4577");
            var to   = new PhoneNumber(msg.PhoneNumber);

            var hostName2 = hostUriService.GetHostUri();

            var uriBuilder = new UriBuilder(hostName2)
            {
                Path = "/api/twilio",
            };

            uriBuilder.AddQuery(new NameValueCollection()
            {
                ["code"]    = msg.Message,
                ["culture"] = msg.CultureInfo.ToString()
            });
            var call = new CreateCallOptions(to, from)
            {
                Url = uriBuilder.Uri,
                MachineDetection = "Enable"
            };
            await options.AddAsync(call);
        }
        private async Task <Response <CreateCallResponse> > CreateCallOperation(CallClient client)
        {
            CommunicationIdentityClient communicationIdentityClient = CreateInstrumentedCommunicationIdentityClient();
            var source = await CreateUserAsync(communicationIdentityClient).ConfigureAwait(false);

            var targets = new List <CommunicationIdentifier>()
            {
                new PhoneNumberIdentifier(TestEnvironment.TargetPhoneNumber)
            };
            var createCallOption = new CreateCallOptions(
                new Uri(TestEnvironment.AppCallbackUrl),
                new List <CallModality> {
                CallModality.Audio
            },
                new List <EventSubscriptionType> {
                EventSubscriptionType.ParticipantsUpdated, EventSubscriptionType.DtmfReceived
            });

            createCallOption.AlternateCallerId = new PhoneNumberIdentifier(TestEnvironment.SourcePhoneNumber);

            Console.WriteLine("Performing CreateCall operation");

            var createCallResponse = await client.CreateCallAsync(source : source, targets : targets, options : createCallOption).ConfigureAwait(false);

            Console.WriteLine("Call initiated with Call Leg id: {0}", createCallResponse.Value.CallLegId);

            Assert.IsFalse(string.IsNullOrWhiteSpace(createCallResponse.Value.CallLegId));
            return(createCallResponse);
        }
示例#4
0
        public void CommunicateCall(string phoneNumber, UserProfile profile, Call call)
        {
            if (profile == null)
            {
                return;
            }

            TwilioClient.Init(Config.NumberProviderConfig.TwilioAccountSid, Config.NumberProviderConfig.TwilioAuthToken);

            if (!profile.VoiceForCall)
            {
                return;
            }

            string number = phoneNumber;

            if (String.IsNullOrWhiteSpace(number) || NumberHelper.IsNexmoNumber(number))
            {
                number = Config.NumberProviderConfig.TwilioResgridNumber;
            }

            if (number.Length == 11 && number[0] != Char.Parse("1"))
            {
                number = "+" + number;
            }

            if (profile.VoiceCallMobile)
            {
                if (!String.IsNullOrWhiteSpace(profile.GetPhoneNumber()))
                {
                    var options = new CreateCallOptions(new PhoneNumber(profile.GetPhoneNumber()), new PhoneNumber(number));
                    options.Url       = new Uri(string.Format(Config.NumberProviderConfig.TwilioVoiceCallApiTurl, profile.UserId, call.CallId));
                    options.Method    = "GET";
                    options.IfMachine = "Continue";

                    var phoneCall = CallResource.Create(options);
                }
            }

            if (profile.VoiceCallHome)
            {
                if (!String.IsNullOrWhiteSpace(profile.GetHomePhoneNumber()))
                {
                    var options = new CreateCallOptions(new PhoneNumber(profile.GetHomePhoneNumber()), new PhoneNumber(number));
                    options.Url       = new Uri(string.Format(Config.NumberProviderConfig.TwilioVoiceCallApiTurl, profile.UserId, call.CallId));
                    options.Method    = "GET";
                    options.IfMachine = "Continue";

                    var phoneCall = CallResource.Create(options);
                }
            }
        }
        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;
            }
        }
示例#6
0
        public async Task CreateCallAsync()
        {
            CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClient(TestEnvironment.LiveTestDynamicConnectionString);
            var source = await communicationIdentityClient.CreateUserAsync();

            var targets = new List <CommunicationIdentifier>()
            {
                new PhoneNumberIdentifier(TestEnvironment.SourcePhoneNumber)
            };

            #region Snippet:Azure_Communication_Call_Tests_CreateCallOptions
            var createCallOption = new CreateCallOptions(
                new Uri(TestEnvironment.AppCallbackUrl),
                new List <CallModality> {
                CallModality.Audio
            },
                new List <EventSubscriptionType>
            {
                EventSubscriptionType.ParticipantsUpdated,
                EventSubscriptionType.DtmfReceived
            });
            #endregion Snippet:Azure_Communication_Call_Tests_CreateCallOptions
            CallClient callClient = CreateInstrumentedCallingServerClient();
            Console.WriteLine("Performing CreateCall operation");
            #region Snippet:Azure_Communication_Call_Tests_CreateCallAsync
            CreateCallResponse createCallResponse = await callClient.CreateCallAsync(
                //@@ source: new CommunicationUserIdentifier("<source-identifier>"), // Your Azure Communication Resource Guid Id used to make a Call
                //@@ targets: new List<CommunicationIdentifier>() { new PhoneNumberIdentifier("<targets-phone-number>") }, // E.164 formatted recipient phone number
                //@@ options: createCallOption // The options for creating a call.
                /*@@*/ source : source,
                /*@@*/ targets : targets,
                /*@@*/ options : createCallOption
                );

            Console.WriteLine($"Call Leg id: {createCallResponse.CallLegId}");
            #endregion Snippet:Azure_Communication_Call_Tests_CreateCallAsync
        }
示例#7
0
        public async Task CreateCallAsyncOverload_Passes(CommunicationIdentifier expectedSource, IEnumerable <CommunicationIdentifier> expectedTargets, CreateCallOptions expectedOptions)
        {
            Mock <CallClient> mockClient = new Mock <CallClient>()
            {
                CallBase = true
            };
            Response <CreateCallResponse>?expectedResponse  = default;
            CancellationToken             cancellationToken = new CancellationTokenSource().Token;
            var callExpression = BuildExpression(x => x.CreateCallAsync(It.IsAny <CommunicationIdentifier>(), It.IsAny <IEnumerable <CommunicationIdentifier> >(), It.IsAny <CreateCallOptions>(), It.IsAny <CancellationToken>()));

            mockClient
            .Setup(callExpression)
            .ReturnsAsync((CommunicationIdentifier source, IEnumerable <CommunicationIdentifier> targets, CreateCallOptions options, CancellationToken token) =>
            {
                Assert.AreEqual(expectedSource, source);
                Assert.AreEqual(expectedTargets, targets);
                Assert.AreEqual(expectedOptions, options);
                Assert.AreEqual(cancellationToken, token);
                return(expectedResponse = new Mock <Response <CreateCallResponse> >().Object);
            });

            Response <CreateCallResponse> actualResponse = await mockClient.Object.CreateCallAsync(expectedSource, expectedTargets, expectedOptions, cancellationToken);

            mockClient.Verify(callExpression, Times.Once());
            Assert.AreEqual(expectedResponse, actualResponse);
        }
        public void CreateCall_Returns404NotFound(CommunicationIdentifier source, IEnumerable <CommunicationIdentifier> targets, CreateCallOptions createCallOptions)
        {
            CallingServerClient callingServerClient = CreateMockCallingServerClient(404);

            RequestFailedException?ex = Assert.Throws <RequestFailedException>(() => callingServerClient.CreateCallConnection(source, targets, createCallOptions));

            Assert.NotNull(ex);
            Assert.AreEqual(ex?.Status, 404);
        }
        public void CreateCall_Returns201Created(CommunicationIdentifier source, IEnumerable <CommunicationIdentifier> targets, CreateCallOptions createCallOptions)
        {
            CallingServerClient callingServerClient = CreateMockCallingServerClient(201, CreateOrJoinCallPayload);

            var response = callingServerClient.CreateCallConnection(source, targets, createCallOptions);

            Assert.AreEqual((int)HttpStatusCode.Created, response.GetRawResponse().Status);
            Assert.AreEqual("cad9df7b-f3ac-4c53-96f7-c76e7437b3c1", response.Value.CallConnectionId);
        }