Skip to main content
Glama
auto-responder-bot.ts1.7 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 /** * Auto-responder bot that generates automated responses to practitioner messages. * * Only responds to messages from practitioners in communication threads. * Prevents infinite loops by checking for "Auto-generated response" in the note field. * * @param medplum - The Medplum client instance * @param event - The bot event containing the Communication resource * @returns A new Communication resource with auto-response, or undefined */ import type { BotEvent, MedplumClient } from '@medplum/core'; import type { Communication, Patient, Reference } from '@medplum/fhirtypes'; export async function handler( medplum: MedplumClient, event: BotEvent<Communication> ): Promise<Communication | undefined> { const communication = event.input; if (!communication.sender?.reference?.startsWith('Practitioner/')) { return undefined; } if (!communication.partOf?.find((partOf) => partOf.reference?.startsWith('Communication/'))) { return undefined; } if (communication.note?.find((note) => note.text?.includes('Auto-generated response'))) { return undefined; } const autoResponse = await medplum.createResource<Communication>({ resourceType: 'Communication', status: 'in-progress', sender: communication.recipient?.[0] as Reference<Patient>, recipient: [communication.sender], payload: [ { contentString: 'This is an auto generated response', }, ], partOf: communication.partOf, sent: new Date().toISOString(), note: [{ text: 'Auto-generated response' }], }); return autoResponse; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/medplum/medplum'

If you have feedback or need assistance with the MCP directory API, please join our Discord server