de1pher
08/28/2025, 3:56 AMtypescript
export default class HistoryRetrievalHandler extends ToolHandler {
readonly functionName = SET_CUSTOMER_ID;
async handle(args: { [key: string]: unknown }, vapi: Vapi) {
const userName = useUserContextStore.getState().name;
const userCode = useUserContextStore.getState().code;
const { id } = args as unknown as HistoryRetrievalArgs;
const dataCollectors = {
events: `/api/events?customerId=${id}`,
complaints: `/api/complaints?userCode=${encodeURIComponent(userCode)}&customerId=${id}`,
opportunities: `/api/opportunities?customerId=${id}`,
};
let content = "";
content = await appendLatestVisitInfo(content, id, userName);
content = await aggregateData(content, dataCollectors);
content += "\n I must let the user know what I have found and ask for further instructions";
vapi.send({ type: "add-message", message: { role: "system", content } });
}
}Chiranjeet Mishra
08/30/2025, 3:06 AM