Beispiel #1
0
        /// <summary>
        /// Method responsible for processing the data sent with POST request to callback URL
        /// </summary>
        /// <param name="content">The content of request</param>
        /// <returns>Returns the response that should be sent to the sender of POST request</returns>
        public async Task <ResponseResult> ProcessCallbackAsync(string content)
        {
            ConversationResult conversationResult;

            if (content == null)
            {
                return(new ResponseResult(ResponseType.BadRequest));
            }
            try
            {
                conversationResult = RealTimeMediaSerializer.DeserializeFromJson <ConversationResult>(content);
                if (conversationResult == null)
                {
                    Trace.TraceWarning($"Could not deserialize the callback.. returning badrequest");
                    return(new ResponseResult(ResponseType.BadRequest));
                }

                conversationResult.Validate();
            }
            catch (Exception ex)
            {
                Trace.TraceWarning($"Exception in conversationResult validate {ex}");
                return(new ResponseResult(ResponseType.BadRequest));
            }

            RealTimeMediaCallService service;

            if (!_activeCalls.TryGetValue(conversationResult.Id, out service))
            {
                Trace.TraceWarning($"CallId {conversationResult.Id} not found");
                return(new ResponseResult(ResponseType.NotFound));
            }
            return(new ResponseResult(ResponseType.Accepted, await service.ProcessConversationResult(conversationResult).ConfigureAwait(false)));
        }
Beispiel #2
0
        /// <summary>
        /// Method responsible for processing the data sent with POST request to incoming call URL
        /// </summary>
        /// <param name="content">The content of request</param>
        /// <param name="skypeChainId">X-Microsoft-Skype-Chain-Id header value used to associate calls across different services</param>
        /// <returns>Returns the response that should be sent to the sender of POST request</returns>
        public async Task <ResponseResult> ProcessIncomingCallAsync(string content, string skypeChainId)
        {
            if (content == null)
            {
                return(new ResponseResult(ResponseType.BadRequest));
            }

            Conversation conversation;

            try
            {
                conversation = RealTimeMediaSerializer.DeserializeFromJson <Conversation>(content);
                if (conversation == null)
                {
                    Trace.TraceWarning($"Could not deserialize the incoming request.. returning badrequest");
                    return(new ResponseResult(ResponseType.BadRequest));
                }

                conversation.Validate();
            }
            catch (Exception ex)
            {
                Trace.TraceWarning($"Exception in conversation validate {ex}");
                return(new ResponseResult(ResponseType.BadRequest));
            }

            RealTimeMediaCallService service = new RealTimeMediaCallService(conversation.Id, skypeChainId, _makeBot, _settings);
            var workflow = await service.HandleIncomingCall(conversation).ConfigureAwait(false);

            if (workflow == null)
            {
                throw new BotCallingServiceException("Incoming call not handled. No workflow produced for incoming call.");
            }
            workflow.Validate();

            RealTimeMediaCallService prevService;

            if (_activeCalls.TryRemove(conversation.Id, out prevService))
            {
                Trace.TraceWarning($"Another call with the same Id {conversation.Id} exists. ending the old call");
                await prevService.LocalCleanup().ConfigureAwait(false);
            }

            _activeCalls[conversation.Id] = service;

            var serializedResponse = RealTimeMediaSerializer.SerializeToJson(workflow);

            return(new ResponseResult(ResponseType.Accepted, serializedResponse));
        }
Beispiel #3
0
        /// <summary>
        /// Method responsible for processing the data sent with POST request to notification URL
        /// </summary>
        /// <param name="content">The content of request</param>
        /// <returns>Returns the response that should be sent to the sender of POST request</returns>
        public async Task <ResponseResult> ProcessNotificationAsync(string content)
        {
            NotificationBase notification;

            if (content == null)
            {
                return(new ResponseResult(ResponseType.BadRequest));
            }
            try
            {
                Trace.TraceWarning($"Received notification {content}");
                notification = RealTimeMediaSerializer.DeserializeFromJson <NotificationBase>(content);
                if (notification == null)
                {
                    Trace.TraceWarning($"Could not deserialize the notification.. returning badrequest");
                    return(new ResponseResult(ResponseType.BadRequest));
                }

                notification.Validate();
            }
            catch (Exception ex)
            {
                Trace.TraceWarning($"Exception in notification validate {ex}");
                return(new ResponseResult(ResponseType.BadRequest));
            }

            RealTimeMediaCallService service;

            if (!_activeCalls.TryGetValue(notification.Id, out service))
            {
                return(new ResponseResult(ResponseType.NotFound, $"Call {notification.Id} not found"));
            }

            await service.ProcessNotificationResult(notification).ConfigureAwait(false);

            return(new ResponseResult(ResponseType.Accepted));
        }