-
Notifications
You must be signed in to change notification settings - Fork 4
Stages
Stages in Telesun make it easy to guide users through a series of steps, like gathering registration information. Each user has their own independent stages, so multiple users can interact with the bot without interfering with each other.
- Structured Interactions: Useful for step-by-step processes like forms or registrations.
- User-Based Stages: Each user’s stage is tracked separately.
- Temporary Data: Stages are stored in temporary sessions, automatically clearing after 10 minutes of inactivity to keep things simple and secure.
Let’s say you want to create a registration flow to collect a username
and password
from the user. Here’s how to do it with stages:
First, prompt the user for their username and set the stage to username
to indicate that’s what we’re waiting for.
const telesun = new Telesun({
telegram: "7172550832:AAEmrWIvLICZn-pAiIdNXbIr1s1P-GsLAVw",
tmemory: CacheService.getScriptCache(),
});
telesun.text((ctx) => {
ctx.reply("Please enter your username:");
ctx.setStage("username"); // Set stage to "username"
});
When the user provides a username, move to the next step by asking for their password. Set the stage to password
to update the bot’s expectation.
telesun.stage("username", (ctx) => {
ctx.reply("Great! Now, please enter your password:");
ctx.setStage("password"); // Set stage to "password"
});
After receiving the password, complete the registration and thank the user.
telesun.stage("password", (ctx) => {
ctx.reply("Thank you! Your registration is now complete.");
ctx.clearStage(); // Optional: Clear the stage after finishing
});
Here’s a quick overview of the main stage-related methods:
-
setStage(stageIdentifier)
: Sets a stage for the user, marking what information or action you’re expecting. -
getStage()
: Retrieves the current stage. -
clearStage()
: Clears the current stage, helpful once the process is complete.
With stages, you can easily create organized and interactive bot flows like registration forms, quizzes, or any step-by-step interaction. By tracking the user’s current stage, Telesun keeps these flows smooth and user-friendly.
- Manager Classes:
- Mail:
- Google Spreadsheet:
- Best Practice:
- Getting Updates:
- Example Types:
- Example Bots: