botserver/docs/src/chapter-05/keyword-set-user.md

2 KiB
Raw Blame History

SET_USER Keyword

The SET_USER keyword defines the active user context for the current bot session.
It associates all subsequent actions, memory entries, and responses with a specific user identity.


Syntax

SET_USER "user-id"

Parameters

  • "user-id" — A unique identifier (UUID or username) representing the user.
    This value is used to link session data, memory, and logs to the correct user record.

Description

SET_USER updates the bots internal session to reflect the specified user identity.
This is typically used after authentication or when switching between users in multi-user environments.
Once set, all commands such as SET_CONTEXT, SET_BOT_MEMORY, and FIND operate within the scope of that user.

If the user ID does not exist in the database, the system automatically creates a new user record.
The command ensures that the session token and memory cache are properly synchronized.


Example

' Set the active user for the session
SET_USER "john_doe"

' Store personalized memory
SET_BOT_MEMORY "preferred_language" "English"

' Retrieve user-specific data
FIND "recent orders"

Implementation Notes

  • Implemented in Rust under src/session/mod.rs and src/org/mod.rs.
  • The keyword interacts with the session manager to update the active user ID.
  • It ensures that all subsequent operations are scoped to the correct user context.
  • If cache component or database caching is enabled, the user ID is stored for persistence across sessions.


Summary

SET_USER is essential for maintaining user-specific state and personalization in GeneralBots.
It ensures that each session operates independently and securely under the correct user identity.