-
Notifications
You must be signed in to change notification settings - Fork 4
Stages
Stages in Telesun offer a structured way to handle consecutive tasks or steps such as user registrations. This feature is particularly useful for creating a step-by-step interaction flow with your bot's users. Stages are maintained on a per-user basis, ensuring that each user has a unique, independent progression through the stages. This functionality is crucial for managing tasks like multiple registrations simultaneously without confusion.
Stages leverage temporary sessions that are automatically cleared after 10 minutes of inactivity. This temporary nature helps manage data efficiently and securely, ensuring that user information is not stored longer than necessary.
You can define stages using various identifiers such as numbers or strings, offering flexibility in how you structure the user interaction flow.
Imagine you want to register users by collecting their username
and password
. Here's how you can implement it using stages:
Start by prompting the user to enter their username. At this point, set the stage to username
to indicate that you're waiting for this piece of information.
const telesun = new Telesun.config({
telegram: '7172550832:AAEmrWIvLICZn-pAiIdNXbIr1s1P-GsLAVw',
tmemory: CacheService.getScriptCache()
});
telesun.text((ctx) => {
ctx.reply('Please type your username:');
ctx.setStage('username');
});
Once the user provides a username, move to the next stage by asking for their password. Change the stage to password
to reflect the new expectation.
telesun.stage('username', (ctx) => {
ctx.reply('Please type your password:');
ctx.setStage('password');
});
After receiving the password, finalize the registration process by acknowledging the completion.
telesun.stage('password', (ctx) => {
ctx.reply('Registration successfully completed.');
});
Stages can be implemented as follows:
/**
* Define a stage.
* @param {string | number} name - The name of the stage.
* @param {Function} function - The function to execute at this stage.
*/
telesun.Stage(name, (ctx) => {});
/**
* Save a stage with a name or identifier.
* @param {string | number} stageIdentifier - The stage name or identifier to set.
*/
ctx.setStage(stageIdentifier);
/**
* Retrieve the currently saved stage.
*/
ctx.getStage();
This framework for stages in Telesun simplifies the creation of multi-step interactions, making it easier to manage complex user flows such as registrations or data collection sequences. By structuring interactions into stages, developers can create more engaging and interactive bots.
- Telesun
- Getting Started - Apps script
- Getting Started with the Telesun Ready Template
- Import Telesun
- Telesun-Handlers
- Context Object
- Next Middleware
- Stages
- Manager Classes:
- Mail:
- Google Spreadsheet:
- Best Practice:
- Getting Updates:
- Example Types:
- Example Bots: