diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs
index 22fdd31..5c7b32a 100644
--- a/TelegramBotBase/BotBase.cs
+++ b/TelegramBotBase/BotBase.cs
@@ -33,7 +33,7 @@ namespace TelegramBotBase
///
/// List of all running/active sessions
///
- public SessionBase Sessions { get; set; }
+ public SessionBase Sessions { get; set; }
///
/// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start
@@ -79,7 +79,8 @@ namespace TelegramBotBase
this.BotCommands = new List();
- this.Sessions = new SessionBase();
+ this.Sessions = new SessionBase();
+ this.Sessions.BotBase = this;
}
///
@@ -193,10 +194,7 @@ namespace TelegramBotBase
this.Client.TelegramClient.StopReceiving();
- if (this.StateMachine != null)
- {
- this.Sessions.SaveSessionStates(this.StateMachine);
- }
+ this.Sessions.SaveSessionStates();
}
///
diff --git a/TelegramBotBase/SessionBase.cs b/TelegramBotBase/SessionBase.cs
index 9cf8da6..40f8e26 100644
--- a/TelegramBotBase/SessionBase.cs
+++ b/TelegramBotBase/SessionBase.cs
@@ -16,12 +16,15 @@ namespace TelegramBotBase
///
/// Base class for managing all active sessions
///
- public class SessionBase
+ public class SessionBase
+ where T : FormBase
{
public MessageClient Client { get; set; }
public Dictionary SessionList { get; set; }
+ public BotBase BotBase { get; set; }
+
public SessionBase()
{
@@ -295,5 +298,17 @@ namespace TelegramBotBase
statemachine.SaveFormStates(new SaveStatesEventArgs(sc));
}
+
+ ///
+ /// Saves all open states into the machine.
+ ///
+ public void SaveSessionStates()
+ {
+ if (this.BotBase.StateMachine == null)
+ return;
+
+
+ this.SaveSessionStates(this.BotBase.StateMachine);
+ }
}
}