Base class you extend to create your app server. Handles webhook registration and session lifecycle.
AppSession
Manages the connection to a specific user session. Created automatically when users start your app.
Important: Apps should extend AppServer and override the onSession method. The sessionId parameter follows the format "userId-packageName" (e.g., "user@example.com-com.example.app").
import { AppServer, AppSession } from '@mentraos/sdk';// Extend AppServer to create your appclass MyAppServer extends AppServer { // Override onSession to handle new user sessions protected async onSession( session: AppSession, sessionId: string, // Format: "userId-packageName" userId: string // User's email address ): Promise<void> { // Your app logic goes here console.log(`New session ${sessionId} for user ${userId}`); }}// Create instance with configurationconst server = new MyAppServer({ packageName: 'com.yourcompany.yourapp', // Your app's unique identifier apiKey: process.env.MENTRAOS_API_KEY!, // Your API key from dev portal port: 3000, // Port to listen on (default: 7010) publicDir: './public' // Optional: static files directory});
The SDK is written in TypeScript and provides full type definitions:
Copy
import { AppServer, AppSession, TranscriptionData, ButtonPress, PhotoData, LocationUpdate} from '@mentraos/sdk';// All types are available for your use