Answer the question
In order to leave comments, you need to log in
How to pass a variable from one scene to another?
How can I transfer a variable from one scene to another? I have a transition that happens when you click on the Keyboard button - the one that prints the text in the chat when you click it. Duck that there won't be any kind of callback?
There is a vario to lay down in a session in 1 scene and take it in the second. But I think there is a better way?
Answer the question
In order to leave comments, you need to log in
Session and its abstract concept.
I recently wrote a universal bot, although I had no experience in building bots.
And so, just there there is a session.
The session allows you to change the behavior of the dialogue as the play progresses.
Let me give you an example of my bike.
Session Interface
export interface SessionInterface {
bot: BotInterface;
state: SessionStateInterface;
initialState: SessionStateInterface;
SID: string;
isNew: boolean;
inDialog: boolean;
user: UserInterface;
send(message: any, options?: any): Promise<any>;
resetState(): void;
setState(state: SessionStateInterface): void;
}
export interface SessionStateInterface {
[key: string]: any;
}
interface SessionConstructorPropsInterface {
bot: BotInterface;
initialState?: SessionStateInterface;
}
export class Session implements SessionInterface {
bot: BotInterface;
user: UserInterface;
state: SessionStateInterface;
initialState: SessionStateInterface;
SID: string;
isNew: boolean;
inDialog: boolean;
constructor({ bot, initialState }: SessionConstructorPropsInterface) {
this.isNew = true;
this.bot = bot;
this.initialState = initialState || {};
this.state = Object.assign({}, initialState);
}
send(message: any, options: any): Promise<void> {
this.isNew = false;
return this.bot.adapter.send(message, options);
}
resetState(): void {
this.state = Object.assign({}, this.initialState);
}
setState(state: SessionStateInterface): void {
Object.keys(state).forEach((key) => {
this.state[key] = state[key];
});
}
}
main.use(/\/login/i, async ({message, session}: BotContextInterface, next) => {
// Здесь я сохраняю состояние
session.setState({
processLogin: true,
processLoginStep: 'login'
})
// Если мне нужно получить состояние
console.log(session.state.processLogin)
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question