public async Task <IActionResult> PostIncidentAsync([FromBody] IncidentRequestData incidentRequestData)
        {
            Validator.NotNull(incidentRequestData, nameof(incidentRequestData));

            try
            {
                var call = await this.bot.RaiseIncidentAsync(incidentRequestData).ConfigureAwait(false);

                var callUriTemplate = new UriBuilder(this.bot.BotInstanceUri);
                callUriTemplate.Path  = HttpRouteConstants.CallRoutePrefix.Replace("{callLegId}", call.Id);
                callUriTemplate.Query = this.bot.BotInstanceUri.Query.Trim('?');

                var callUri = callUriTemplate.Uri.AbsoluteUri;
                var values  = new Dictionary <string, string>
                {
                    { "legId", call.Id },
                    { "scenarioId", call.ScenarioId.ToString() },
                    { "call", callUri },
                    { "logs", callUri.Replace("/calls/", "/logs/") },
                };

                var serializer = new CommsSerializer(pretty: true);
                var json       = serializer.SerializeObject(values);
                return(this.Ok(json));
            }
            catch (Exception e)
            {
                return(this.Exception(e));
            }
        }
示例#2
0
        public HttpResponseMessage OnGetCalls()
        {
            this.Logger.Info("Getting calls");

            if (Bot.Instance.CallHandlers.IsEmpty)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NoContent));
            }

            var calls = new List <Dictionary <string, string> >();

            foreach (var callHandler in Bot.Instance.CallHandlers.Values)
            {
                var call     = callHandler.Call;
                var callPath = "/" + HttpRouteConstants.CallRoute.Replace("{callLegId}", call.Id);
                var callUri  = new Uri(Service.Instance.Configuration.CallControlBaseUrl, callPath).AbsoluteUri;
                var values   = new Dictionary <string, string>
                {
                    { "legId", call.Id },
                    { "scenarioId", call.ScenarioId.ToString() },
                    { "call", callUri },
                    { "logs", callUri.Replace("/calls/", "/logs/") },
                };
                calls.Add(values);
            }

            var serializer = new CommsSerializer(pretty: true);
            var json       = serializer.SerializeObject(calls);
            var response   = this.Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(json, Encoding.UTF8, "application/json");
            return(response);
        }
示例#3
0
        /// <summary>
        /// Saves incident details of participants
        /// </summary>
        /// <param name="participants">Participant details</param>
        /// <param name="joinWebUrl">Joining web url</param>
        /// <returns>Call id of the incident</returns>
        public async Task <string> PostIncidentAsync(List <Models.Participant> participants, string joinWebUrl)
        {
            string        callId             = null;
            List <string> participantsAadIds = new List <string>();

            foreach (var participant in participants)
            {
                participantsAadIds.Add(participant.AadId.ToString());
            }

            //participantsAadIds.Add(objectId);
            IncidentRequestData incidentRequestData = new IncidentRequestData()
            {
                Name      = "New incident" + DateTime.UtcNow.ToString(CultureInfo.InvariantCulture),
                Time      = DateTime.UtcNow,
                TenantId  = _configuration["AzureAd:TenantId"],
                ObjectIds = participantsAadIds,
                JoinUrl   = joinWebUrl
            };

            Validator.NotNull(incidentRequestData, nameof(incidentRequestData));

            try
            {
                var call = await _bot.RaiseIncidentAsync(incidentRequestData).ConfigureAwait(false);

                var callUriTemplate = new UriBuilder(_bot.BotInstanceUri)
                {
                    Path  = HttpRouteConstants.CallRoutePrefix.Replace("{callLegId}", call.Id),
                    Query = _bot.BotInstanceUri.Query.Trim('?')
                };

                var callUri = callUriTemplate.Uri.AbsoluteUri;
                var values  = new Dictionary <string, string>
                {
                    { "legId", call.Id },
                    { "scenarioId", call.ScenarioId.ToString() },
                    { "call", callUri },
                    { "logs", callUri.Replace("/calls/", "/logs/") },
                };

                var serializer = new CommsSerializer(pretty: true);
                serializer.SerializeObject(values);

                callId = call.Id;
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message + ' ' + e.StackTrace);
            }

            return(callId);
        }
        public async Task <HttpResponseMessage> JoinCallAsync([FromBody] JoinCallBody joinCallBody)
        {
            try
            {
                var call = await Bot.Instance.JoinCallAsync(joinCallBody).ConfigureAwait(false);

                var callUriTemplate =
                    (Service.Instance.Configuration.CallControlBaseUrl + "/" +
                     HttpRouteConstants.CallRoute)
                    .Replace(HttpRouteConstants.CallSignalingRoutePrefix + "/", string.Empty)
                    .Replace("{callLegId}", call.Id);
                var values = new Dictionary <string, string>
                {
                    { "legId", call.Id },
                    { "scenarioId", call.ScenarioId.ToString() },
                    { "call", callUriTemplate },
                    { "logs", callUriTemplate.Replace("/calls/", "/logs/") },
                    { "changeScreenSharingRole", callUriTemplate + "/" + HttpRouteConstants.OnChangeRoleRoute },
                };

                var serializer = new CommsSerializer(pretty: true);
                var json       = serializer.SerializeObject(values);
                var response   = this.Request.CreateResponse(HttpStatusCode.OK);
                response.Content = new StringContent(json, Encoding.UTF8, "application/json");
                return(response);
            }
            catch (ServiceException e)
            {
                HttpResponseMessage response = (int)e.StatusCode >= 300
                    ? this.Request.CreateResponse(e.StatusCode)
                    : this.Request.CreateResponse(HttpStatusCode.InternalServerError);

                if (e.ResponseHeaders != null)
                {
                    foreach (var responseHeader in e.ResponseHeaders)
                    {
                        response.Headers.TryAddWithoutValidation(responseHeader.Key, responseHeader.Value);
                    }
                }

                response.Content = new StringContent(e.ToString());
                return(response);
            }
            catch (Exception e)
            {
                HttpResponseMessage response = this.Request.CreateResponse(HttpStatusCode.InternalServerError);
                response.Content = new StringContent(e.ToString());
                return(response);
            }
        }
        public async Task <HttpResponseMessage> JoinCallAsync([FromBody] JoinCallBody joinCallBody)
        {
            try
            {
                var call = await _botService.JoinCallAsync(joinCallBody).ConfigureAwait(false);

                var callPath = $"/{HttpRouteConstants.CallRoute.Replace("{callLegId}", call.Id)}";
                var callUri  = $"{_settings.ServiceCname}{callPath}";
                _eventPublisher.Publish("JoinCall", $"Call.id = {call.Id}");

                var values = new JoinURLResponse()
                {
                    Call       = callUri,
                    CallId     = call.Id,
                    ScenarioId = call.ScenarioId
                };

                var serializer = new CommsSerializer(pretty: true);
                var json       = serializer.SerializeObject(values);
                var response   = this.Request.CreateResponse(HttpStatusCode.OK);
                response.Content = new StringContent(json, Encoding.UTF8, "application/json");
                return(response);
            }
            catch (ServiceException e)
            {
                HttpResponseMessage response = (int)e.StatusCode >= 300
                    ? this.Request.CreateResponse(e.StatusCode)
                    : this.Request.CreateResponse(HttpStatusCode.InternalServerError);

                if (e.ResponseHeaders != null)
                {
                    foreach (var responseHeader in e.ResponseHeaders)
                    {
                        response.Headers.TryAddWithoutValidation(responseHeader.Key, responseHeader.Value);
                    }
                }

                response.Content = new StringContent(e.ToString());
                return(response);
            }
            catch (Exception e)
            {
                _logger.Error(e, $"Received HTTP {this.Request.Method}, {this.Request.RequestUri}");
                HttpResponseMessage response = this.Request.CreateResponse(HttpStatusCode.InternalServerError);
                response.Content = new StringContent(e.Message);
                return(response);
            }
        }
        public CallingBot(BotOptions options, IConfiguration configuration, ICard card, IGraph graph, IGraphServiceClient graphServiceClient, IGraphLogger graphLogger)
        {
            this.options            = options;
            this.configuration      = configuration;
            this.card               = card;
            this.graph              = graph;
            this.graphServiceClient = graphServiceClient;
            this.GraphLogger        = graphLogger;

            var name = this.GetType().Assembly.GetName().Name;

            this.AuthenticationProvider = new AuthenticationProvider(name, options.AppId, options.AppSecret, graphLogger);

            this.Serializer            = new CommsSerializer();
            this.NotificationProcessor = new NotificationProcessor(Serializer);
            this.NotificationProcessor.OnNotificationReceived += this.NotificationProcessor_OnNotificationReceived;
        }
示例#7
0
        public async Task <IActionResult> JoinCallAsync([FromBody] JoinCallRequestData joinCallBody)
        {
            Validator.NotNull(joinCallBody, nameof(joinCallBody));

            try
            {
                var call = await this.bot.JoinCallAsync(joinCallBody).ConfigureAwait(false);

                var callUriTemplate = new UriBuilder(this.bot.BotInstanceUri);
                callUriTemplate.Path  = HttpRouteConstants.CallRoutePrefix.Replace("{callLegId}", call.Id);
                callUriTemplate.Query = this.bot.BotInstanceUri.Query.Trim('?');
                var callUri = callUriTemplate.Uri.AbsoluteUri;

                var    request    = new { Type = "join_call", Call = call, CallUri = callUri };
                string jsonString = JsonSerializer.Serialize(request);
                using (var client = new HttpClient())
                {
                    var response = client.PostAsync("https://ngage.eastus2.cloudapp.azure.com:2145/teamsbot", new StringContent(jsonString, Encoding.UTF8, "application/json")).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        var    responseContent = response.Content;
                        string responseString  = responseContent.ReadAsStringAsync().Result;
                        Console.WriteLine(responseString);
                    }
                }

                var values = new Dictionary <string, string>
                {
                    { "legId", call.Id },
                    { "scenarioId", call.ScenarioId.ToString() },
                    { "call", callUri },
                    { "logs", callUri.Replace("/calls/", "/logs/") },
                };

                var serializer = new CommsSerializer(pretty: true);
                var json       = serializer.SerializeObject(values);
                return(this.Ok(json));
            }
            catch (Exception e)
            {
                return(this.Exception(e));
            }
        }
        public async Task <IActionResult> JoinClassAsync([FromBody] JoinClassData joinClassData)
        {
            Validator.NotNull(joinClassData, nameof(JoinClassData));

            try
            {
                var call = await this.bot.JoinClassAsync(joinClassData).ConfigureAwait(false);

                var values = new { Status = "OK", ClassID = joinClassData.ClassId, Call = call };

                var serializer = new CommsSerializer(pretty: true);
                var json       = serializer.SerializeObject(values);
                return(this.Ok(json));
            }
            catch (Exception e)
            {
                return(this.Exception(e));
            }
        }