//todo: resolve issue with DI public ScheduledShtrafsCheckService(IShtrafBizClient shtrafiBizClient, CheckShtrafDialog dialogToStart) { _dialogToStart = dialogToStart; _shtrafiBizClient = shtrafiBizClient; // _globalSettingsService = new GlobalSettings.GlobalSettingsService(new FlowContext()); loggerService = new LoggerService <ILogger>(); }
/// <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; } }