184 lines
5.2 KiB
TypeScript
184 lines
5.2 KiB
TypeScript
import { api } from './client';
|
|
|
|
export type ConciergeBotStatus = 'DRAFT' | 'ACTIVE' | 'ARCHIVED';
|
|
|
|
export interface ConciergeBotGreeting {
|
|
enabled?: boolean;
|
|
message?: string;
|
|
}
|
|
|
|
export interface ConciergeBotRegistration {
|
|
promptIfUnregistered?: boolean;
|
|
allowGuestSkip?: boolean;
|
|
}
|
|
|
|
export interface ConciergeBotKnowledge {
|
|
includeEventDetails?: boolean;
|
|
includeFoodRecommendations?: boolean;
|
|
includePlacesRecommendations?: boolean;
|
|
lastEventSnapshotAt?: string;
|
|
lastFoodSnapshotAt?: string;
|
|
lastPlacesSnapshotAt?: string;
|
|
}
|
|
|
|
export interface ConciergeBotRecord {
|
|
_id: string;
|
|
organization: string;
|
|
event: string | { _id: string; name?: string; startDate?: string; endDate?: string };
|
|
name?: string;
|
|
wabaPhoneNumberId: string;
|
|
enabled: boolean;
|
|
status: ConciergeBotStatus;
|
|
greeting?: ConciergeBotGreeting;
|
|
registration?: ConciergeBotRegistration;
|
|
knowledge?: ConciergeBotKnowledge;
|
|
lastKnowledgeClearedAt?: string;
|
|
createdAt?: string;
|
|
updatedAt?: string;
|
|
}
|
|
|
|
export type UrlCrawlScope = 'auto' | 'domain' | 'path';
|
|
|
|
export interface KnowledgeSourceCrawlStats {
|
|
pages?: number;
|
|
assets?: number;
|
|
skipped?: number;
|
|
failed?: number;
|
|
}
|
|
|
|
export interface KnowledgeSourceRecord {
|
|
_id: string;
|
|
eventId: string;
|
|
type: 'url' | 'pdf' | 'event' | 'food' | 'places';
|
|
sourcePath: string;
|
|
displayName: string;
|
|
status: 'PENDING' | 'PROCESSING' | 'READY' | 'FAILED';
|
|
errorMessage?: string | null;
|
|
lastSyncedAt?: string;
|
|
crawlScope?: 'domain' | 'path' | null;
|
|
crawlPathPrefix?: string | null;
|
|
lastCrawlStats?: KnowledgeSourceCrawlStats | null;
|
|
}
|
|
|
|
export interface ContextChunkRecord {
|
|
_id: string;
|
|
rawText: string;
|
|
isActive: boolean;
|
|
sourceId: string;
|
|
}
|
|
|
|
export interface Event {
|
|
_id: string;
|
|
name?: string;
|
|
[k: string]: any;
|
|
}
|
|
|
|
export const conciergeBotsApi = {
|
|
list(params?: { organization?: string }) {
|
|
const sp = new URLSearchParams();
|
|
if (params?.organization) sp.set('organization', params.organization);
|
|
const q = sp.toString();
|
|
return api.get<{ bots: ConciergeBotRecord[] }>(`/concierge-bots${q ? `?${q}` : ''}`);
|
|
},
|
|
|
|
get(botId: string) {
|
|
return api.get<{ bot: ConciergeBotRecord; aggregates: { sourceCount: number; stagingChunkCount: number; subscriberCount: number } }>(
|
|
`/concierge-bots/${botId}`,
|
|
);
|
|
},
|
|
|
|
getByEvent(eventId: string) {
|
|
return api.get<{ bot: ConciergeBotRecord; aggregates: { sourceCount: number; stagingChunkCount: number; subscriberCount: number } }>(
|
|
`/events/${eventId}/concierge-bot`,
|
|
);
|
|
},
|
|
|
|
create(payload: {
|
|
eventId: string;
|
|
name?: string;
|
|
wabaPhoneNumberId: string;
|
|
greeting?: ConciergeBotGreeting;
|
|
registration?: ConciergeBotRegistration;
|
|
knowledge?: ConciergeBotKnowledge;
|
|
enabled?: boolean;
|
|
}) {
|
|
return api.post<{ bot: ConciergeBotRecord; warning?: string }>('/concierge-bots', payload);
|
|
},
|
|
|
|
update(
|
|
botId: string,
|
|
payload: Partial<{
|
|
name: string;
|
|
wabaPhoneNumberId: string;
|
|
greeting: ConciergeBotGreeting;
|
|
registration: ConciergeBotRegistration;
|
|
knowledge: ConciergeBotKnowledge;
|
|
enabled: boolean;
|
|
}>,
|
|
) {
|
|
return api.put<{ bot: ConciergeBotRecord }>(`/concierge-bots/${botId}`, payload);
|
|
},
|
|
|
|
remove(botId: string) {
|
|
return api.delete<{ deleted: boolean }>(`/concierge-bots/${botId}`);
|
|
},
|
|
|
|
listSources(botId: string) {
|
|
return api.get<{ sources: KnowledgeSourceRecord[] }>(`/concierge-bots/${botId}/sources`);
|
|
},
|
|
|
|
createSource(
|
|
botId: string,
|
|
payload: {
|
|
type: 'url' | 'pdf';
|
|
sourcePath: string;
|
|
displayName: string;
|
|
crawlScope?: UrlCrawlScope;
|
|
},
|
|
) {
|
|
return api.post<KnowledgeSourceRecord>(`/concierge-bots/${botId}/sources`, payload);
|
|
},
|
|
|
|
deleteSource(botId: string, sourceId: string) {
|
|
return api.delete<{ deleted: boolean }>(`/concierge-bots/${botId}/sources/${sourceId}`);
|
|
},
|
|
|
|
syncSource(botId: string, sourceId: string) {
|
|
return api.post<KnowledgeSourceRecord>(`/concierge-bots/${botId}/sources/${sourceId}/sync`, {});
|
|
},
|
|
|
|
listChunks(botId: string, sourceId: string, staging = true) {
|
|
return api.get<{ chunks: ContextChunkRecord[] }>(
|
|
`/concierge-bots/${botId}/sources/${sourceId}/chunks?staging=${staging ? 'true' : 'false'}`,
|
|
);
|
|
},
|
|
|
|
patchChunk(botId: string, chunkId: string, rawText: string) {
|
|
return api.patch<ContextChunkRecord>(`/concierge-bots/${botId}/chunks/${chunkId}`, { rawText });
|
|
},
|
|
|
|
deleteChunk(botId: string, chunkId: string) {
|
|
return api.delete<{ deleted: boolean }>(`/concierge-bots/${botId}/chunks/${chunkId}`);
|
|
},
|
|
|
|
approveSource(botId: string, sourceId: string) {
|
|
return api.post<{ modified: number }>(`/concierge-bots/${botId}/sources/${sourceId}/approve`, {});
|
|
},
|
|
|
|
clearKnowledge(botId: string) {
|
|
return api.post<{ cleared: boolean }>(`/concierge-bots/${botId}/knowledge/clear`, {});
|
|
},
|
|
|
|
syncEventKnowledge(botId: string) {
|
|
return api.post<KnowledgeSourceRecord>(`/concierge-bots/${botId}/knowledge/sync-event`, {});
|
|
},
|
|
|
|
syncFoodKnowledge(botId: string) {
|
|
return api.post<KnowledgeSourceRecord>(`/concierge-bots/${botId}/knowledge/food-sync`, {});
|
|
},
|
|
|
|
syncPlacesKnowledge(botId: string) {
|
|
return api.post<KnowledgeSourceRecord>(`/concierge-bots/${botId}/knowledge/places-sync`, {});
|
|
},
|
|
};
|