Skip to main content
Glama
deploy-bots.ts3.24 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { ContentType } from '@medplum/core'; import type { Bundle, BundleEntry } from '@medplum/fhirtypes'; import { randomUUID } from 'crypto'; import fs from 'fs'; import path from 'path'; interface BotDescription { src: string; dist: string; criteria?: string; } const Bots: BotDescription[] = [ { src: 'src/bots/core/intake-form.ts', dist: 'dist/bots/core/intake-form.js', criteria: 'QuestionnaireResponse?questionnaire=https://medplum.com/Questionnaire/patient-intake-questionnaire-example', }, ]; async function main(): Promise<void> { const bundle: Bundle = { resourceType: 'Bundle', type: 'transaction', entry: Bots.flatMap((botDescription): BundleEntry[] => { const botName = path.parse(botDescription.src).name; const botUrlPlaceholder = `$bot-${botName}-reference`; const botIdPlaceholder = `$bot-${botName}-id`; const results: BundleEntry[] = []; const { srcEntry, distEntry } = readBotFiles(botDescription); results.push(srcEntry, distEntry); results.push({ request: { method: 'PUT', url: botUrlPlaceholder }, resource: { resourceType: 'Bot', id: botIdPlaceholder, name: botName, runtimeVersion: 'awslambda', sourceCode: { contentType: ContentType.TYPESCRIPT, url: srcEntry.fullUrl, }, executableCode: { contentType: ContentType.JAVASCRIPT, url: distEntry.fullUrl, }, }, }); if (botDescription.criteria) { results.push({ request: { url: `Subscription?url=${botUrlPlaceholder}`, method: 'PUT', }, resource: { resourceType: 'Subscription', status: 'active', reason: botName, channel: { endpoint: botUrlPlaceholder, type: 'rest-hook' }, criteria: botDescription.criteria, extension: [ { url: 'https://medplum.com/fhir/StructureDefinition/subscription-supported-interaction', valueCode: 'create', }, ], }, }); } return results; }), }; fs.writeFileSync('data/core/example-bots.json', JSON.stringify(bundle, null, 2)); } function readBotFiles(description: BotDescription): Record<string, BundleEntry> { const sourceFile = fs.readFileSync(description.src); const distFile = fs.readFileSync(description.dist); const srcEntry: BundleEntry = { fullUrl: 'urn:uuid:' + randomUUID(), request: { method: 'POST', url: 'Binary' }, resource: { resourceType: 'Binary', contentType: ContentType.TYPESCRIPT, data: sourceFile.toString('base64'), }, }; const distEntry: BundleEntry = { fullUrl: 'urn:uuid:' + randomUUID(), request: { method: 'POST', url: 'Binary' }, resource: { resourceType: 'Binary', contentType: ContentType.JAVASCRIPT, data: distFile.toString('base64'), }, }; return { srcEntry, distEntry }; } main().catch(console.error);

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