Update README.md
This commit is contained in:
parent
ab0ae5cda4
commit
b1c518cbd3
124
README.md
124
README.md
@ -904,131 +904,131 @@ Below you find all possiblities.
|
||||
|
||||
### Statemachines
|
||||
|
||||
There are actually 3 types of example state machines you could use. A state machine is a kind of serializer which saves the important session data in a reusable structure like JSON or XML.
|
||||
There are actually 3 types of example state machines you could use. A state machine is a kind of serializer which saves the important session data in a reusable structure like JSON or XML.
|
||||
|
||||
You could use one of the following state machines:
|
||||
You could use one of the following state machines:
|
||||
|
||||
- SimpleJSONStateMachine
|
||||
Is easy to use and useful for simple structures like basic datatypes. Did not work for complex ones like generics. Use the JSONStateMachine for them.
|
||||
In general you didn't need to do more then, to keep the actual form:
|
||||
#### SimpleJSONStateMachine
|
||||
Is easy to use and useful for simple structures like basic datatypes. Did not work for complex ones like generics. Use the JSONStateMachine for them.
|
||||
In general you didn't need to do more then, to keep the actual form:
|
||||
|
||||
```
|
||||
//Prepare the System
|
||||
BotBase<StartForm> bb = new BotBase<StartForm>("{YOUR API KEY}");
|
||||
//Prepare the System
|
||||
BotBase<StartForm> bb = new BotBase<StartForm>("{YOUR API KEY}");
|
||||
|
||||
//Add Systemcommands if you like, you could catch them later
|
||||
bb.SystemCalls.Add("/start");
|
||||
//Add Systemcommands if you like, you could catch them later
|
||||
bb.SystemCalls.Add("/start");
|
||||
|
||||
//Set the statemachine and enable it
|
||||
bb.StateMachine = new TelegramBotBase.States.SimpleJSONStateMachine(AppContext.BaseDirectory + "config\\states.json");
|
||||
//Set the statemachine and enable it
|
||||
bb.StateMachine = new TelegramBotBase.States.SimpleJSONStateMachine(AppContext.BaseDirectory + "config\\states.json");
|
||||
|
||||
//Start your Bot
|
||||
bb.Start();
|
||||
//Start your Bot
|
||||
bb.Start();
|
||||
|
||||
```
|
||||
|
||||
- JSONStateMachine
|
||||
Is easy to use too, but works for complex datatypes cause it saves there namespaces and additional type informations into the JSON file too.
|
||||
In general you didn't need to do more then, to keep the actual form:
|
||||
#### JSONStateMachine
|
||||
Is easy to use too, but works for complex datatypes cause it saves there namespaces and additional type informations into the JSON file too.
|
||||
In general you didn't need to do more then, to keep the actual form:
|
||||
|
||||
```
|
||||
//Prepare the System
|
||||
BotBase<StartForm> bb = new BotBase<StartForm>("{YOUR API KEY}");
|
||||
//Prepare the System
|
||||
BotBase<StartForm> bb = new BotBase<StartForm>("{YOUR API KEY}");
|
||||
|
||||
//Add Systemcommands if you like, you could catch them later
|
||||
bb.SystemCalls.Add("/start");
|
||||
//Add Systemcommands if you like, you could catch them later
|
||||
bb.SystemCalls.Add("/start");
|
||||
|
||||
//Set the statemachine and enable it
|
||||
bb.StateMachine = new TelegramBotBase.States.JSONStateMachine(AppContext.BaseDirectory + "config\\states.json");
|
||||
//Set the statemachine and enable it
|
||||
bb.StateMachine = new TelegramBotBase.States.JSONStateMachine(AppContext.BaseDirectory + "config\\states.json");
|
||||
|
||||
//Start your Bot
|
||||
bb.Start();
|
||||
//Start your Bot
|
||||
bb.Start();
|
||||
|
||||
```
|
||||
|
||||
- XMLStateMachine
|
||||
#### XMLStateMachine
|
||||
|
||||
The last one, should work like the others.
|
||||
In general you didn't need to do more then, to keep the actual form:
|
||||
The last one, should work like the others.
|
||||
In general you didn't need to do more then, to keep the actual form:
|
||||
|
||||
```
|
||||
//Prepare the System
|
||||
BotBase<StartForm> bb = new BotBase<StartForm>("{YOUR API KEY}");
|
||||
//Prepare the System
|
||||
BotBase<StartForm> bb = new BotBase<StartForm>("{YOUR API KEY}");
|
||||
|
||||
//Add Systemcommands if you like, you could catch them later
|
||||
bb.SystemCalls.Add("/start");
|
||||
//Add Systemcommands if you like, you could catch them later
|
||||
bb.SystemCalls.Add("/start");
|
||||
|
||||
//Set the statemachine and enable it
|
||||
bb.StateMachine = new TelegramBotBase.States.XMLStateMachine(AppContext.BaseDirectory + "config\\states.json");
|
||||
//Set the statemachine and enable it
|
||||
bb.StateMachine = new TelegramBotBase.States.XMLStateMachine(AppContext.BaseDirectory + "config\\states.json");
|
||||
|
||||
//Start your Bot
|
||||
bb.Start();
|
||||
//Start your Bot
|
||||
bb.Start();
|
||||
|
||||
```
|
||||
|
||||
### Interfaces
|
||||
|
||||
There are two interfaces, one for the StateMachine itself, which is useful to build a custom one for a different datatype and one for implementing into a form which should be invoked with events.
|
||||
There are two interfaces, one for the StateMachine itself, which is useful to build a custom one for a different datatype and one for implementing into a form which should be invoked with events.
|
||||
|
||||
- IStateMachine
|
||||
#### IStateMachine
|
||||
|
||||
Is the basic StateMachine interface, it has two methods SaveFormStates(SaveStatesEventArgs e) and StateContainer LoadFormStates(), nothing fancy, just simple calls. Implement into both methods your own serialization process.
|
||||
Is the basic StateMachine interface, it has two methods SaveFormStates(SaveStatesEventArgs e) and StateContainer LoadFormStates(), nothing fancy, just simple calls. Implement into both methods your own serialization process.
|
||||
|
||||
```
|
||||
|
||||
public interface IStateMachine
|
||||
{
|
||||
void SaveFormStates(SaveStatesEventArgs e);
|
||||
public interface IStateMachine
|
||||
{
|
||||
void SaveFormStates(SaveStatesEventArgs e);
|
||||
|
||||
StateContainer LoadFormStates();
|
||||
}
|
||||
StateContainer LoadFormStates();
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
- IStateForm
|
||||
#### IStateForm
|
||||
|
||||
When implemented, this will invoke one of these two methods: LoadState(LoadStateEventArgs e) or SaveState(SaveStateEventArgs e).
|
||||
They have methods to load or save data from the statemachine of the current form.
|
||||
When implemented, this will invoke one of these two methods: LoadState(LoadStateEventArgs e) or SaveState(SaveStateEventArgs e).
|
||||
They have methods to load or save data from the statemachine of the current form.
|
||||
|
||||
```
|
||||
|
||||
public interface IStateForm
|
||||
{
|
||||
void LoadState(LoadStateEventArgs e);
|
||||
public interface IStateForm
|
||||
{
|
||||
void LoadState(LoadStateEventArgs e);
|
||||
|
||||
void SaveState(SaveStateEventArgs e);
|
||||
}
|
||||
void SaveState(SaveStateEventArgs e);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Attributes
|
||||
|
||||
If you don't want to implement the IStateForm interface, cause there are maybe "just" one or two properties you want to keep and restore, use the following attribute:
|
||||
If you don't want to implement the IStateForm interface, cause there are maybe "just" one or two properties you want to keep and restore, use the following attribute:
|
||||
|
||||
- SaveState
|
||||
#### SaveState
|
||||
|
||||
This will let the engine know, that you want too keep and restore the field automatically. Unlike the IStateForm methods, you have no option to manipulate data.
|
||||
This will let the engine know, that you want too keep and restore the field automatically. Unlike the IStateForm methods, you have no option to manipulate data.
|
||||
|
||||
```
|
||||
|
||||
[SaveState]
|
||||
public long UserId { get; set; }
|
||||
[SaveState]
|
||||
public long UserId { get; set; }
|
||||
|
||||
|
||||
```
|
||||
|
||||
- IgnoreState
|
||||
#### IgnoreState
|
||||
|
||||
Due to the fact that Attribute implementation and interace is optional, you want to let the engine maybe know, that you dont want to keep a specific form. So it should get "lost". This attribute will help you here, add it to the form class and it will not get serialized, even if it implements IStateForm or the SaveState attributes.
|
||||
Due to the fact that Attribute implementation and interace is optional, you want to let the engine maybe know, that you dont want to keep a specific form. So it should get "lost". This attribute will help you here, add it to the form class and it will not get serialized, even if it implements IStateForm or the SaveState attributes.
|
||||
|
||||
```
|
||||
|
||||
[IgnoreState]
|
||||
public class Registration : STForm
|
||||
{
|
||||
[IgnoreState]
|
||||
public class Registration : STForm
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user