public async Task Invoke(HttpContext context)
        {
            try
            {
                await nextDelegate(context);
            }
            catch (StreetwoodException exception)
            {
                var message = PrepareExceptionMessage(exception);

                if (exception.ErrorCode.StatusCode == HttpStatusCode.InternalServerError)
                {
                    if (!environment.IsDevelopment())
                    {
                        await queueManager.AddMessageAsync(message);
                    }

                    logger.LogError($"Streetwood exception with code '{exception.ErrorCode.ToString()}.\n{message}");
                }
                else
                {
                    logger.LogWarning($"Streetwood exception with code '{exception.ErrorCode.ToString()}.\n{message}");
                }

                await HandleException(context, exception);
            }
            catch (Exception exception)
            {
                var message = PrepareExceptionMessage(exception);
                logger.LogError(exception, message);
                if (!environment.IsDevelopment())
                {
                    await queueManager.AddMessageAsync(message);
                }

                await HandleException(context, exception);
            }
        }
Esempio n. 2
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            var msg = new MessageModel {
                Id   = turnContext.Activity.Recipient.Id,
                Role = turnContext.Activity.Recipient.Role,
                Text = turnContext.Activity.Text
            };

            await _queueManager.AddMessageAsync(msg, cancellationToken).ConfigureAwait(false);

            ResponseModel response = await _queueManager.GetMessage(turnContext.Activity.Recipient.Id).ConfigureAwait(false);

            string replyText = $"Echo: {turnContext.Activity.Text} Response: {response?.Text}";
            await turnContext.SendActivityAsync(MessageFactory.Text(replyText, replyText), cancellationToken);
        }