UNPKG

@gameon/web

Version:
17 lines 957 B
import { initializeApp } from 'firebase/app'; import { collection, getFirestore, limit, onSnapshot, orderBy, query as firestoreQuery, } from 'firebase/firestore'; export class FirebaseInstance { constructor(firebaseConfig) { this.app = initializeApp(firebaseConfig, 'on-chat-bot-client'); this.store = getFirestore(this.app); } getFirestoreConvoPath(conversationData) { return `channel:${conversationData.channel}:app:${conversationData.app}:conversations/conversation:${conversationData.conversationId}/events`; } listenToConvo(conversationData, messageHistoryLimit, onSuccess, onError) { const messagesRef = collection(this.store, this.getFirestoreConvoPath(conversationData)); const messagesQuery = firestoreQuery(messagesRef, orderBy('timestamp', 'desc'), limit(messageHistoryLimit)); onSnapshot(messagesQuery, onSuccess, onError); } } //# sourceMappingURL=firebase-instance.js.map