/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { if (activity.Type == ActivityTypes.Message) { //// The Configured IISExpressSSLPort property in this project file //const int ConfiguredHttpsPort = 44371; //var link = Url.Link("CheckOut", new { controller = "CheckOut", action = "Index" }); //var uriBuilder = new UriBuilder(link) //{ // Scheme = Uri.UriSchemeHttps, // Port = ConfiguredHttpsPort //}; //var checkOutRouteUri = uriBuilder.Uri.ToString(); //using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity)) //{ // var dialog = scope.Resolve<IDialog<object>>(TypedParameter.From(checkOutRouteUri)); // await Conversation.SendAsync(activity, () => dialog); //} var luisObj = new RootLuisDialog(); await Conversation.SendAsync(activity, () => luisObj); } else { await this.HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }
// GET api/<controller> public string Get() { var query = HttpUtility.ParseQueryString(this.Request.RequestUri.Query); string code = query.Get("code"); string dialogId = query.Get("state"); if (!String.IsNullOrEmpty(code)) { RootLuisDialog.UpdateCodeAsync(code, dialogId); return("You are Signed In!"); } return("Sign-in Failed!"); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { try { using (var scope = DialogModule.BeginLifetimeScope(this.scope, activity)) { _loggerService = scope.Resolve <ILoggerService <ILogger> >(); _checkShtrafDialog = scope.Resolve <CheckShtrafDialog>(); _rootLuisDialog = scope.Resolve <RootLuisDialog>(); _rootDialog = scope.Resolve <RootDialog>(); var connector = new ConnectorClient(new Uri(activity.ServiceUrl)); if (activity.Type == ActivityTypes.Message) { if (activity.Text.Trim() == "reset") { Activity rep; rep = activity.CreateReply("Временные данные успешно удалены"); await connector.Conversations.ReplyToActivityAsync(rep); activity.GetStateClient().BotState.DeleteStateForUser(activity.ChannelId, activity.From.Id); return(new HttpResponseMessage(HttpStatusCode.Accepted)); } if (MessagesCustom.Default.StartSearchFinesCommands.Contains(activity.Text)) { //reset stack first var botData = scope.Resolve <IBotData>(); await botData.LoadAsync(CancellationToken.None); var _task = scope.Resolve <IDialogTask>(); _task.Reset(); await Conversation.SendAsync(activity, () => new ExceptionHandlerDialog <object>(_rootDialog, true)); return(new HttpResponseMessage(HttpStatusCode.Accepted)); } if (MessagesCustom.Default.HelpCommands.Contains(activity.Text)) { var r = activity.CreateReply("Чтобы начать новый поиск штрафов введите **новый поиск** или нажмите кнопку"); var buttonNew = new CardAction { // Value = "test", Value = "новый поиск", Type = "imBack", Title = "новый поиск" }; var cardForButton = new ThumbnailCard { Buttons = new List <CardAction> { buttonNew } }; r.Attachments.Add(cardForButton.ToAttachment()); await connector.Conversations.ReplyToActivityAsync(r); return(new HttpResponseMessage(HttpStatusCode.Accepted)); } //tmp // return new HttpResponseMessage(HttpStatusCode.Accepted); //ignore luis now await Conversation.SendAsync(activity, () => new ExceptionHandlerDialog <object>(_rootDialog, true)); /* await Conversation.SendAsync(activity, * () => new ExceptionHandlerDialog<object>(_rootLuisDialog, true));*/ return(new HttpResponseMessage(HttpStatusCode.Accepted)); // await Conversation.SendAsync(activity, () => new Dialogs.RootLuisDialog()); } else if (activity.Type == ActivityTypes.ConversationUpdate) { //start if just joined if (activity.MembersAdded.Count == 1) { // var act = activity.AsMessageActivity(); /* using (var scope = DialogModule.BeginLifetimeScope(this.scope, act)) * { * var _rootDialog = scope.Resolve<RootDialog>();*/ await Conversation.SendAsync(activity, () => new ExceptionHandlerDialog <object>(_checkShtrafDialog, true)); return(new HttpResponseMessage(HttpStatusCode.Accepted)); /*}*/ } // Handle conversation state changes, like members being added and removed // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info // Not available in all channels } HandleSystemMessage(activity); var response = Request.CreateResponse(HttpStatusCode.OK); return(response); } } catch (Exception e) { _loggerService.Error(e); throw; } }