
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@aivue/chatbot-server
Advanced tools
Backend utilities and database integration for @aivue/chatbot.
Note: This is an optional package that provides server-side functionality for storing and managing chatbot conversations. It is not required for using the @aivue/chatbot package, but it provides additional features for applications that need to store conversation history.
npm install @aivue/chatbot-server
You'll also need to install the ORM of your choice:
# For Sequelize
npm install sequelize
# For Mongoose
npm install mongoose
# For Drizzle
npm install drizzle-orm
# For Prisma
npm install prisma @prisma/client
const express = require('express');
const { createChatbotServer } = require('@aivue/chatbot-server');
async function start() {
// Create Express app
const app = express();
// Create chatbot server
const chatbotServer = await createChatbotServer({
database: {
type: 'postgres',
orm: 'sequelize',
connectionString: process.env.DATABASE_URL
},
auth: {
adminApiKey: process.env.ADMIN_API_KEY
}
});
// Mount chatbot server middleware
app.use('/api', chatbotServer.middleware);
// Start server
app.listen(3000, () => {
console.log('Server running on port 3000');
});
}
start().catch(console.error);
The createChatbotServer
function accepts a configuration object with the following options:
interface ChatbotServerConfig {
// Required: Database configuration
database: {
type: 'postgres' | 'mysql' | 'sqlite' | 'mongodb';
orm: 'sequelize' | 'mongoose' | 'drizzle' | 'prisma';
connectionString?: string;
host?: string;
port?: number;
username?: string;
password?: string;
database?: string;
file?: string; // For SQLite
options?: Record<string, any>;
};
// Optional: Authentication configuration
auth?: {
adminApiKey?: string;
apiKeyHeader?: string;
jwtSecret?: string;
jwtExpiresIn?: string;
};
// Optional: API configuration
api?: {
basePath?: string;
adminPath?: string;
enableCors?: boolean;
corsOptions?: Record<string, any>;
};
// Optional: Storage configuration
storage?: {
messageLimit?: number;
enableArchiving?: boolean;
archiveAfterDays?: number;
deleteAfterDays?: number;
};
// Optional: Logging configuration
logging?: {
level?: 'error' | 'warn' | 'info' | 'debug';
format?: 'json' | 'text';
file?: string;
};
}
POST /api/chat
- Process a chat message and store it in the databaseGET /api/user/:userId/conversations
- Get conversations for a specific userAll admin endpoints require authentication using the X-Admin-API-Key
header.
GET /api/admin/conversations
- List all conversations with pagination and filteringGET /api/admin/conversations/:id
- Get a specific conversation with all messagesPOST /api/admin/conversations/:id/status
- Update a conversation's statusGET /api/admin/stats
- Get conversation statisticsThis package is designed to work seamlessly with the @aivue/chatbot package. The @aivue/chatbot package has been enhanced to support server-side persistence through the serverPersistence
option.
To use this server with the @aivue/chatbot package, configure the chatbot to use the server for persistence:
import { useChatEngine } from '@aivue/chatbot';
const {
messages,
isLoading,
error,
conversationId,
sendMessage
} = useChatEngine({
provider: 'openai',
apiKey: process.env.OPENAI_API_KEY,
// Enable server persistence
serverPersistence: true,
userId: 123, // Optional user ID
useProxy: true,
proxyUrl: '/api/chat'
});
This allows you to:
You can run the chatbot server as a standalone Express application:
const { createChatbotServer } = require('@aivue/chatbot-server');
async function start() {
const server = await createChatbotServer({
database: {
type: 'postgres',
orm: 'sequelize',
connectionString: process.env.DATABASE_URL
}
});
// Start the server on port 3000
await server.start(3000);
}
start().catch(console.error);
You can also use the individual components of the package:
const express = require('express');
const {
createDatabaseConnection,
getModels,
createChatRoutes,
createAdminRoutes,
adminAuthMiddleware
} = require('@aivue/chatbot-server');
async function start() {
// Create database connection
const db = await createDatabaseConnection({
type: 'postgres',
orm: 'sequelize',
connectionString: process.env.DATABASE_URL
});
// Get models
const models = await getModels('sequelize', db);
// Create Express app
const app = express();
app.use(express.json());
// Create chat routes
const chatRoutes = createChatRoutes({
db,
orm: 'sequelize',
models
});
// Create admin routes
const adminRoutes = createAdminRoutes({
db,
orm: 'sequelize',
models,
auth: {
adminApiKey: process.env.ADMIN_API_KEY
}
});
// Mount routes
app.use('/api', chatRoutes);
app.use('/api/admin', adminRoutes);
// Start server
app.listen(3000, () => {
console.log('Server running on port 3000');
});
}
start().catch(console.error);
MIT
FAQs
Backend utilities and database integration for @aivue/chatbot
We found that @aivue/chatbot-server demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.