The User API provides access to the current user’s profile information through a powerful UserDataInstance class with direct property access.
Copy
import { User } from 'lua-cli';// Get user instanceconst user = await User.get();// Access the new read-only user profileconsole.log(user._luaProfile.fullName);console.log(user._luaProfile.emailAddresses); // A simple array of strings// Continue to use the user object for your agent's custom datauser.lastProductViewed = 'SKU-123';await user.save();
A new, read-only property user._luaProfile is now available on the user object. This provides a secure and reliable way to access core user identity information.
_luaProfile (Read-Only): Contains essential user data like userId, fullName, mobileNumbers, and emailAddresses.
The _lua prefix indicates this is a special, system-provided property.
This data is immutable; any attempts to change it will be silently ignored.
user.* (Mutable): Continue to use the main user object to store and manage any custom data your agent needs, such as preferences, shopping carts, or game scores.
Core User Identity
Access read-only data like user._luaProfile.userId and user._luaProfile.fullName.
Custom Agent Data
Read and write your agent’s data directly, like user.cart or user.preferences.
To centralize core user information, user.userId is now deprecated. Please update your code to use user._luaProfile.userId. The old property will be removed in a future version.
User ID to retrieve a specific userRequired in: Webhooks, pre-defined LuaJob (no conversational context)Optional in: Tools, dynamic jobs (has conversational context)If not provided, retrieves the current user from the conversation context
Returns:UserDataInstance with proxy-based property access
Understanding when userId is required vs optional:
Context
Method
userId Required?
Why
Tools
User.get()
❌ Optional
Has conversational context
Webhooks
User.get(userId)
✅ REQUIRED
No conversational context
LuaJob
User.get(userId)
✅ REQUIRED
No conversational context
Jobs API
jobInstance.user()
❌ N/A
Automatic user context
Context Matters:
Tools: userId is optional - defaults to current user in conversation
Webhooks: userId is REQUIRED - webhooks execute outside conversations
LuaJob (pre-defined): userId is REQUIRED - jobs execute outside conversations
Jobs API (dynamic): Use jobInstance.user() instead - automatic context captured!
Examples:
Current User
Specific User (Webhooks/LuaJob)
Dynamic Jobs (Special Case)
Get the current user from conversation context:
Copy
import { User } from 'lua-cli';// In your toolasync execute(input: any) { const user = await User.get(); // Direct property access console.log(user.name); // "John Doe" console.log(user.email); // "[email protected]" console.log(user.phone); // "555-0123" return { userName: user.name };}
Get a specific user by ID (REQUIRED in webhooks and pre-defined jobs):
Copy
import { User } from 'lua-cli';// In a webhook (NO conversational context)execute: async (event) => { // ⚠️ MUST provide userId in webhooks const customerId = event.data.object.metadata?.customerId; if (!customerId) { return { error: 'No customer ID provided' }; } const user = await User.get(customerId); // Send message to that specific user await user.send([{ type: 'text', text: `✅ Payment received: $${event.data.object.amount/100}` }]); return { notified: true };}
Required in:
✅ Webhooks - No conversational context
✅ LuaJob (pre-defined) - No conversational context
✅ Admin tools - Managing other users
NOT needed in:
❌ Tools - Use User.get() without userId
❌ Jobs API (dynamic) - Use jobInstance.user() instead
Dynamic jobs have automatic user context:
Copy
import { Jobs } from 'lua-cli';// Creating a dynamic job from a toolawait Jobs.create({ name: 'user-reminder', execute: async (jobInstance) => { // ✅ Use jobInstance.user() - automatic context! const user = await jobInstance.user(); await user.send([{ type: 'text', text: 'Reminder: Your meeting starts in 5 minutes!' }]); }});
Why it works: Dynamic jobs created from tools automatically capture the user context, so you don’t need to provide a userId.
Save the current state of user data to the server. This is a convenience method that persists all changes made to the user instance.
Copy
user.save(): Promise<boolean>
Returns: Promise resolving to true if successfulExamples:
Copy
const user = await User.get();// Modify propertiesuser.name = "John Doe";user.email = "[email protected]";user.phone = "555-1234";// Save all changes at onceawait user.save();// Much cleaner than multiple update calls!
New in Latest Version: The save() method provides a simpler workflow - modify properties then save, rather than passing data to update().