Skip to main content

Bot Deploy

Medplum Bots can be deployed using the $deploy operation.

If you're not familiar with Medplum Bots, you may want to review the Bot Basics documentation first.

Invoke $deploy Operation

To use the $deploy operation, you will need to make a POST request with the Bot's id. Additionally, the $deploy operation takes two body parameters:

  1. filename: The name of the file the bot is stored in. If left blank, it will default to index.js.
  2. code: The bot's code that will be executed when it is run.
await medplum.post(medplum.fhirUrl('Bot', '[id]', '$deploy').toString(), {
filename: 'hello-patient.js',
// eslint-disable-next-line no-template-curly-in-string
code: "import { BotEvent, MedplumClient } from '@medplum/core';\nimport { Patient } from '@medplum/fhirtypes';\n\nexport async function handler(medplum: MedplumClient, event: BotEvent): Promise<any> {\n const patient = event.input as Patient;\n const firstName = patient.name?.[0]?.given?.[0];\n const lastName = patient.name?.[0]?.family;\n console.log(`Hello ${firstName} ${lastName}!`);\n return true;\n}\n",
});

To learn more about more about Bots and deploying them, see the Bots In Production docs.