public async Task <HttpStatusCode> RecieveAsync() { // var xt = graph.GetPageProfileAsync(PSID).Result; string request = ""; // GraphApi graph = new GraphApi(); using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8, true, 1024, true)) { request = await reader.ReadToEndAsync(); } var messengerEvent = MessengerEvent.FromJson(request); var PSID = messengerEvent.Entry[0].Messaging[0].Sender.Id; if (messengerEvent.Entry[0].Messaging[0].Postback != null) { if (messengerEvent.Entry[0].Messaging[0].Postback.Payload == "GET_STARTED" || messengerEvent.Entry[0].Messaging[0].Postback.Payload == "RESTART_BOT") { try { this._queue.QueueAsyncTask(() => graph.SendHelloAsync(PSID)); } catch (Exception e) { Console.WriteLine(e); } } else if (messengerEvent.Entry[0].Messaging[0].Postback.Payload == "RESTART_QUIZ") { this._queue.QueueAsyncTask(() => graph.ProfileInfoHandler(PSID)); this._queue.QueueTask(() => graph.FinishScorecard(PSID)); //this._queue.QueueTask(() => graph.Typing(PSID)); this._queue.QueueTask(() => graph.CreateScorecard(PSID)); this._queue.QueueTask(() => graph.SetState(PSID, 0, Startup.BotContext.Quiz.ToString())); this._queue.QueueTask(() => graph.SendMessage((GenericMessage($"Alright.\nThere will be {Startup.quiz.Questions.Count} questions.\nSome questions have multiple answers.", PSID).ToJson()))); this._queue.QueueTask(() => Thread.Sleep(300)); this._queue.QueueTask(() => graph.SendMessage((GenericMessage("You may either tap or type in your answers. When typing in answers, options should be separated by a space or a comma, such as \"A, B\" or \"A B\", but not \"AB\".", PSID).ToJson()))); this._queue.QueueTask(() => Thread.Sleep(300)); this._queue.QueueTask(() => graph.SendMessage((GenericMessage("First Question for you", PSID).ToJson()))); this._queue.QueueTask(() => Thread.Sleep(300)); this._queue.QueueTask(() => NextQuestionAsync(PSID, 0, Startup.BotContext.Quiz.ToString())); } } else if (messengerEvent.Entry[0].Messaging[0].Message.Text == null) { this._queue.QueueTask(() => new Dialogflow().DetectIntentFromTexts(PSID, Startup.Force_Wrong)); } else { //this._queue.QueueTask(() =>graph.Typing(PSID)); this._queue.QueueTask(() => new Dialogflow().DetectIntentFromTexts(PSID, messengerEvent.Entry[0].Messaging[0].Message.Text)); } return(HttpStatusCode.OK); }