This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Retrieves or creates a Firestore document for the user and manages their session ID. | |
* @param from - The 'From' phone number from the Twilio request (e.g., 'whatsapp:+1234567890'). | |
* @returns An object containing the session ID, whether a session existed, and the customer data. | |
*/ | |
async function getUserSessionInfo(from: string) { | |
// Get the Firestore database instance using the Firebase Admin SDK app. | |
const db = getFirestore(getFirebaseAdminApp()); | |
// Fetch the customer document. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { z } from 'zod'; | |
import { ai } from '@/ai/genkit'; | |
import type { AgentSessionState } from '../types'; | |
import { FieldValue, getFirestore, Timestamp, type Firestore } from 'firebase-admin/firestore'; | |
import { getFirebaseAdminApp } from '../firebase-service'; | |
import { AppointmentItem } from '@/types'; | |
import { format } from 'date-fns'; | |
import moment, { } from 'moment-timezone'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use server'; | |
/** | |
* @fileOverview Defines a Firestore retriever for the 'services' collection. | |
*/ | |
import { defineFirestoreRetriever } from '@genkit-ai/firebase'; | |
import { getFirestore } from 'firebase-admin/firestore'; | |
import { ai } from '@/ai/genkit'; | |
import type { ServiceItem } from '@/types'; | |
import { getFirebaseAdminApp } from '../firebase-service'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ai } from '@/ai/genkit'; | |
import { checkAppointmentAvailability, lookupAppointments, appointmentConfirmation, modifyAppointment } from '../tools/appointment-tools'; | |
import { agentDescription } from '../util'; | |
import { z } from 'zod'; | |
const tools = [checkAppointmentAvailability, appointmentConfirmation, lookupAppointments, modifyAppointment, 'routingAgent']; | |
const specialization = 'appointment'; | |
const toolNames: string[] = tools.map((item) => { | |
if (typeof item === 'string') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ai } from '@/ai/genkit'; | |
import { appointmentAgent } from './appointment-agent'; | |
import { lookupServiceTool } from '../tools/lookup-tools'; | |
import { customerInfoTool } from '../tools/customer-tools'; | |
import { AgentSessionState } from '../types'; | |
import { endSessionTool } from '../tools/session-tools'; | |
export const routingAgent = ai.definePrompt( | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.scheduledFunctionCrontab = functions.pubsub.schedule('5 11 * * *') | |
.timeZone('America/New_York') // Users can choose timezone - default is America/Los_Angeles | |
.onRun((context) => { | |
console.log('Convert your Firestore collection to CSVs every day at 11:05 AM Eastern!'); | |
return null; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as functions from "firebase-functions"; | |
import * as firebase from "firebase-admin"; | |
import { parseAsync } from 'json2csv'; | |
import { v4 as uuidv4 } from 'uuid'; | |
import * as fs from "fs"; | |
import * as path from "path"; | |
import * as os from "os"; | |
firebase.initializeApp({ | |
storageBucket: 'storage-bucket-name', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i functions: Beginning execution of "calculateOrder" | |
i Your code does not appear to initialize the 'firebase-admin' module, so we've done it automatically. | |
- Learn more: https://firebase.google.com/docs/admin/setup | |
> begin trigger | |
⚠ Unknown network resource requested! | |
- URL: "http://metadata.google.internal./computeMetadata/v1/instance" | |
⚠ Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information. | |
at GoogleAuth.getApplicationDefaultAsync (/Users/shangyilim/Projects/emulator-test/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19) | |
at processTicksAndRejections (internal/process/task_queues.js:86:5) | |
⚠ Your function was killed because it raised an unhandled error. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Starting emulators: ["functions","firestore"] | |
⚠ Your requested "node" version "8" doesn't match your global version "11" | |
✔ functions: Emulator started at http://localhost:5001 | |
i firestore: Logging to firestore-debug.log | |
✔ firestore: Emulator started at http://localhost:8080 | |
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080 | |
i functions: Watching "/Users/shangyilim/Projects/emulator-test/functions" for Cloud Functions... | |
i functions: Setting up Cloud Firestore trigger "calculateOrder" | |
✔ functions: Trigger "calculateOrder" has been acknowledged by the Cloud Firestore emulator. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Firestore.instance.settings(host: "10.0.2.2:8080", sslEnabled: false ); |
NewerOlder