Ejemplo n.º 1
0
        public APIGatewayProxyResponse Log(APIGatewayProxyRequest request, ILambdaContext context)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var items = _helper.ExtractValues(request.Body).ToList();

            var text       = items.FirstOrDefault(x => x.Key.ToLower() == "text").Value;
            var token      = items.FirstOrDefault(x => x.Key.ToLower() == "token").Value;
            var checkToken = _config.GetParameter("al-slack-verification-token");

            if (token != checkToken)
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = 403
                });
            }

            try
            {
                _messagHandler.BufferRawMessage(text);
            }
            catch (Exception e)
            {
                _logger.Log(e.ToString());
                return(new APIGatewayProxyResponse
                {
                    StatusCode = 500,
                    Body = $"Exception Occurred: {e}"
                });
            }

            stopwatch.Stop();

            return(new APIGatewayProxyResponse
            {
                StatusCode = 200,
                Body = $"recorded successfully in {stopwatch.ElapsedMilliseconds} miliseconds"
            });
        }