public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req,
            [Queue(QueueNameConstants.TextModelForDatabase)] ICollector <TextMoodModel> textModelForDatabaseCollection,
            [Queue(QueueNameConstants.SendUpdate)] ICollector <TextMoodModel> sendUpdateCollection, ILogger log)
        {
            try
            {
                log.LogInformation("Text Message Received");

                log.LogInformation("Parsing Request Body");
                var httpRequestBody = await HttpRequestServices.GetContentAsString(req).ConfigureAwait(false);

                log.LogInformation("Creating New Text Model");
                var textMessageBody = TwilioServices.GetTextMessageBody(httpRequestBody, log) ?? throw new NullReferenceException("Text Message Body Null");
                var textMoodModel   = new TextMoodModel(textMessageBody);

                log.LogInformation("Retrieving Sentiment Score");
                textMoodModel.SentimentScore = await TextAnalysisServices.GetSentiment(textMoodModel.Text).ConfigureAwait(false) ?? -1;

                log.LogInformation("Adding TextMoodModel to Storage Queue");
                textModelForDatabaseCollection.Add(textMoodModel);
                sendUpdateCollection.Add(textMoodModel);

                var response = $"Text Sentiment: {EmojiServices.GetEmoji(textMoodModel.SentimentScore)}";

                log.LogInformation($"Sending OK Response: {response}");

                return(new ContentResult
                {
                    StatusCode = (int)HttpStatusCode.OK,
                    Content = TwilioServices.CreateTwilioResponse(response),
                    ContentType = "application/xml"
                });
            }
            catch (Exception e)
            {
                log.LogError(e, e.Message);
                throw;
            }
        }
Beispiel #2
0
        public static HttpResponseMessage Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage httpRequest,
            [Queue(QueueNameConstants.TextModelForDatabase)] out TextMoodModel textModelForDatabase, TraceWriter log)
        {
            log.Info("Text Message Received");

            log.Info("Parsing Request Message");
            var httpRequestBody = httpRequest.Content.ReadAsStringAsync().GetAwaiter().GetResult();

            log.Info("Creating New Text Model");
            textModelForDatabase = new TextMoodModel(TwilioServices.GetTextMessageBody(httpRequestBody, log));

            log.Info("Retrieving Sentiment Score");
            textModelForDatabase.SentimentScore = TextAnalysisServices.GetSentiment(textModelForDatabase.Text).GetAwaiter().GetResult() ?? -1;

            var response = $"Text Sentiment: {EmojiServices.GetEmoji(textModelForDatabase.SentimentScore)}";

            log.Info($"Sending OK Response: {response}");
            return(new HttpResponseMessage {
                Content = new StringContent(TwilioServices.CreateTwilioResponse(response), Encoding.UTF8, "application/xml")
            });
        }
 public AnalyzeTextSentiment(TwilioServices twilioServices, TextAnalysisServices textAnalysisServices) =>
 (_twilioServices, _textAnalysisServices) = (twilioServices, textAnalysisServices);