public async Task <IActionResult> Messages( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log) { var json = await new StreamReader(req.Body).ReadToEndAsync(); var activity = JsonConvert.DeserializeObject <Activity>(json); string authHeader = req.Headers.ContainsKey("Authorization") ? req.Headers["Authorization"].ToString() : null; if (activity.DeliveryMode == "expectReplies" || activity.Type == ActivityTypes.Invoke) { log.LogInformation($"Messages endpoint triggered [{activity.Type}]"); var result = await _adapter.ProcessActivityAsync(authHeader, activity, _bot.OnTurnAsync, default(CancellationToken)); return(new ObjectResult(result.Body) { StatusCode = result.Status }); } else { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed HttpClient client = new HttpClient(); if (authHeader != null) { client.DefaultRequestHeaders.Add("Authorization", authHeader); } client.PostAsJsonAsync(_internalMessageEndpoint, activity) .ContinueWith(t => log.LogError(t.Exception.Message), TaskContinuationOptions.OnlyOnFaulted); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(new AcceptedResult()); } }