//TODO: сделать init //public static T Create<T>() where T : BaseStateMachine //{ // var messageSender = ExpressBotService.Configuration.ServiceProvider.GetService<BotMessageSender>(); // var //} /// <summary> /// Загружает конечный автомат из ранее сериализованного в json состояния /// </summary> /// <param name="value">JSON-строка</param> /// <param name="messageSender">Отправщик сообщений Express</param> /// <returns></returns> public T FromJson <T>(string value, IBotMessageSender messageSender, UserMessage userMessage) where T : BaseStateMachine { var restoredObject = JsonConvert.DeserializeObject(value, serializerSettings); if (!(restoredObject is T restoredSm)) { return(null); } using var scope = ScopeFactory.CreateScope(); var diSm = scope.ServiceProvider.GetService <T>(); if (diSm != null) { diSm.firstStep = restoredSm.firstStep; diSm.isFinished = restoredSm.isFinished; diSm.MessageSender = messageSender; diSm.Model = restoredSm.Model; diSm.state = restoredSm.state; diSm.state.StateMachine = diSm; diSm.UserMessage = userMessage; return(diSm); } restoredSm.MessageSender = messageSender; restoredSm.UserMessage = userMessage; return(restoredSm); }
public async Task InvokeAsync(UserMessage message, IBotMessageSender sender) { if (message.Command.Body.ToLower() == "hello") { await sender.ReplyTextMessageAsync(message, "hi!"); } else { await next(message); } }
/// <summary> /// Создаёт конечный автомат с начальным состоянием, указанным в качестве аргументоа /// </summary> /// <param name="messageSender">Отправщик сообщений Express</param> protected BaseStateMachine(IBotMessageSender messageSender, IServiceScopeFactory scopeFactory) { MessageSender = messageSender; ScopeFactory = scopeFactory; }
public ChatMessageAction(IBotMessageSender messageSender) : base(messageSender) { }
public HelpAction(IBotMessageSender messageSender) : base(messageSender) { }
public StartAction(IBotMessageSender messageSender, DemoStateMachine stateMachine) : base(messageSender) { this.stateMachine = stateMachine; }
public SayHelloAction(IBotMessageSender messageSender) : base(messageSender) { }
public SayDateAction(IBotMessageSender messageSender) : base(messageSender) { }
public DemoStateMachine(IBotMessageSender messageSender, IServiceScopeFactory scopeFactory) : base(messageSender, scopeFactory) { }
#pragma warning disable CS1591 public BotAction(IBotMessageSender messageSender) #pragma warning restore CS1591 { MessageSender = messageSender; }