Add AI-powered chatbot for media outlets
Integrate an AI chatbot feature allowing users to interact with media outlets, fetch chat history, and generate AI responses using OpenAI. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9a264234-c5d7-4dcc-adf3-a954b149b30d Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3df548ff-50ae-432f-9be4-25d34eccc983/9a264234-c5d7-4dcc-adf3-a954b149b30d/d35d7YU
This commit is contained in:
@ -10,6 +10,7 @@ import {
|
||||
predictionBets,
|
||||
communityPosts,
|
||||
communityReplies,
|
||||
chatMessages,
|
||||
type User,
|
||||
type UpsertUser,
|
||||
type MediaOutlet,
|
||||
@ -32,6 +33,8 @@ import {
|
||||
type InsertCommunityPost,
|
||||
type CommunityReply,
|
||||
type InsertCommunityReply,
|
||||
type ChatMessage,
|
||||
type InsertChatMessage,
|
||||
} from "@shared/schema";
|
||||
import { db } from "./db";
|
||||
import { eq, desc, asc, and, ilike, sql } from "drizzle-orm";
|
||||
@ -97,6 +100,10 @@ export interface IStorage {
|
||||
getRepliesByPost(postId: string): Promise<CommunityReply[]>;
|
||||
createCommunityReply(reply: InsertCommunityReply): Promise<CommunityReply>;
|
||||
|
||||
// Chatbot operations
|
||||
getChatMessages(mediaOutletId: string, userId: string): Promise<ChatMessage[]>;
|
||||
createChatMessage(message: InsertChatMessage): Promise<ChatMessage>;
|
||||
|
||||
// Analytics operations
|
||||
getAnalytics(): Promise<{
|
||||
totalArticles: number;
|
||||
@ -473,6 +480,20 @@ export class DatabaseStorage implements IStorage {
|
||||
return newReply;
|
||||
}
|
||||
|
||||
// Chatbot operations
|
||||
async getChatMessages(mediaOutletId: string, userId: string): Promise<ChatMessage[]> {
|
||||
return await db
|
||||
.select()
|
||||
.from(chatMessages)
|
||||
.where(and(eq(chatMessages.mediaOutletId, mediaOutletId), eq(chatMessages.userId, userId)))
|
||||
.orderBy(asc(chatMessages.createdAt));
|
||||
}
|
||||
|
||||
async createChatMessage(message: InsertChatMessage): Promise<ChatMessage> {
|
||||
const [newMessage] = await db.insert(chatMessages).values(message).returning();
|
||||
return newMessage;
|
||||
}
|
||||
|
||||
// Analytics operations
|
||||
async getAnalytics(): Promise<{
|
||||
totalArticles: number;
|
||||
|
||||
Reference in New Issue
Block a user