2025-10-25 15:59:06 -03:00
|
|
|
|
# SET_USER Keyword
|
|
|
|
|
|
|
2025-11-03 20:42:38 -03:00
|
|
|
|
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.
|
2025-10-25 15:59:06 -03:00
|
|
|
|
|
2025-11-03 20:42:38 -03:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## Syntax
|
|
|
|
|
|
|
|
|
|
|
|
```basic
|
2025-10-25 15:59:06 -03:00
|
|
|
|
SET_USER "user-id"
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-11-03 20:42:38 -03:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## Parameters
|
2025-10-25 15:59:06 -03:00
|
|
|
|
|
2025-11-03 20:42:38 -03:00
|
|
|
|
- `"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.
|
2025-10-25 15:59:06 -03:00
|
|
|
|
|
2025-11-03 20:42:38 -03:00
|
|
|
|
---
|
2025-10-25 15:59:06 -03:00
|
|
|
|
|
2025-11-03 20:42:38 -03:00
|
|
|
|
## Description
|
2025-10-25 15:59:06 -03:00
|
|
|
|
|
2025-11-03 20:42:38 -03:00
|
|
|
|
`SET_USER` updates the bot’s 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
|
2025-10-25 15:59:06 -03:00
|
|
|
|
|
|
|
|
|
|
```basic
|
2025-11-03 20:42:38 -03:00
|
|
|
|
' 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"
|
2025-10-25 15:59:06 -03:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-11-03 20:42:38 -03:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 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 Redis or database caching is enabled, the user ID is stored for persistence across sessions.
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## Related Keywords
|
|
|
|
|
|
|
|
|
|
|
|
- [`SET_CONTEXT`](keyword-set-context.md) — Defines the operational context for the session.
|
|
|
|
|
|
- [`SET_BOT_MEMORY`](keyword-set-bot-memory.md) — Stores persistent data for the bot or user.
|
|
|
|
|
|
- [`GET_BOT_MEMORY`](keyword-get-bot-memory.md) — Retrieves stored memory entries.
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 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.
|