Exemplo n.º 1
0
        /// <summary>
        /// Raise an incident.
        /// </summary>
        /// <param name="incidentRequestData">The incident data.</param>
        /// <returns>The task for await.</returns>
        public async Task <ICall> RaiseIncidentAsync(IncidentRequestData incidentRequestData)
        {
            // A tracking id for logging purposes. Helps identify this call in logs.
            var scenarioId = string.IsNullOrEmpty(incidentRequestData.ScenarioId) ? Guid.NewGuid() : new Guid(incidentRequestData.ScenarioId);

            string incidentId = Guid.NewGuid().ToString();

            var incidentStatusData = new IncidentStatusData(incidentId, incidentRequestData);

            var incident = this.IncidentStatusManager.AddIncident(incidentId, incidentStatusData);

            var botMeetingCall = await this.JoinCallAsync(incidentRequestData, incidentId).ConfigureAwait(false);

            // Rehydrates and validates the group call.
            botMeetingCall = await this.RehydrateAndValidateGroupCallAsync(this.Client, botMeetingCall).ConfigureAwait(false);

            foreach (var objectId in incidentRequestData.ObjectIds)
            {
                var makeCallRequestData =
                    new MakeCallRequestData(
                        incidentRequestData.TenantId,
                        objectId,
                        "Application".Equals(incidentRequestData.ResponderType, StringComparison.OrdinalIgnoreCase));
                var responderCall = await this.MakeCallAsync(makeCallRequestData, scenarioId).ConfigureAwait(false);

                this.AddCallToHandlers(responderCall, new IncidentCallContext(IncidentCallType.ResponderNotification, incidentId));
            }

            return(botMeetingCall);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Subsequent call.
        /// </summary>
        private void SubsequentCall()
        {
            if (this.statusData.Count <= this.statusData.ObjectIds.Count() - 1)
            {
                var scenarioId = Guid.NewGuid();
                var objectId   = this.statusData.ObjectIds.ToList()[this.statusData.Count];
                Task.Run(async() =>
                {
                    try
                    {
                        var makeCallRequestData =
                            new MakeCallRequestData(
                                this.statusData.TenantId,
                                objectId,
                                "Application".Equals("User", StringComparison.OrdinalIgnoreCase));
                        var responderCall = await this.Bot.MakeCallAsync(makeCallRequestData, scenarioId).ConfigureAwait(false);

                        CallHandler callHandler;
                        var callee  = responderCall.Resource.Targets.First();
                        callHandler = new ResponderCallHandler(this.Bot, responderCall, callee.Identity.User.Id, this.statusData);
                        this.Bot.CallHandlers[responderCall.Id] = callHandler;
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                });
            }
        }
        public async Task <IActionResult> MakeOutgoingCallAsync([FromBody] MakeCallRequestData makeCallBody)
        {
            Validator.NotNull(makeCallBody, nameof(makeCallBody));

            try
            {
                await this.bot.MakeCallAsync(makeCallBody, Guid.NewGuid()).ConfigureAwait(false);

                return(this.Ok());
            }
            catch (Exception e)
            {
                return(this.Exception(e));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Makes outgoing call asynchronously.
        /// </summary>
        /// <param name="makeCallBody">The outgoing call request body.</param>
        /// <param name="scenarioId">The scenario identifier.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        public async Task <ICall> MakeCallAsync(MakeCallRequestData makeCallBody, Guid scenarioId)
        {
            if (makeCallBody == null)
            {
                throw new ArgumentNullException(nameof(makeCallBody));
            }

            if (makeCallBody.TenantId == null)
            {
                throw new ArgumentNullException(nameof(makeCallBody.TenantId));
            }

            if (makeCallBody.ObjectId == null)
            {
                throw new ArgumentNullException(nameof(makeCallBody.ObjectId));
            }

            var target =
                makeCallBody.IsApplication ?
                new InvitationParticipantInfo
            {
                Identity = new IdentitySet
                {
                    Application = new Identity
                    {
                        Id          = makeCallBody.ObjectId,
                        DisplayName = $"Responder {makeCallBody.ObjectId}",
                    },
                },
            }
                :
            new InvitationParticipantInfo
            {
                Identity = new IdentitySet
                {
                    User = new Identity
                    {
                        Id = makeCallBody.ObjectId,
                    },
                },
            };

            var mediaToPrefetch = new List <MediaInfo>();

            foreach (var m in this.MediaMap)
            {
                mediaToPrefetch.Add(m.Value.MediaInfo);
            }

            var call = new Call
            {
                Targets     = new[] { target },
                MediaConfig = new ServiceHostedMediaConfig {
                    PreFetchMedia = mediaToPrefetch
                },
                RequestedModalities = new List <Modality> {
                    Modality.Audio
                },
                TenantId = makeCallBody.TenantId,
            };

            var statefulCall = await this.Client.Calls().AddAsync(call, scenarioId: scenarioId).ConfigureAwait(false);

            this.graphLogger.Info($"Call creation complete: {statefulCall.Id}");

            return(statefulCall);
        }