Question about imports in `Bot` resources
# support
a
Hi Medplum team. I'm trying to use local imports in a
Bot
resource, but can't figure it out. For example, in
medplum/examples/medplum-photon-integration/src/bots/sync-formulary.ts
, there are imports like:
Copy code
import { NEUTRON_HEALTH, NEUTRON_HEALTH_TREATMENTS } from './constants';
import { handlePhotonAuth, photonGraphqlFetch } from './utils';
Source: https://github.com/medplum/medplum/blob/2f74aa79ae29b638be476ad0ba029fb75d5e0d61/examples/medplum-photon-integration/src/bots/sync-formulary.ts#L3-L4 However, when I try something similar in my
Bot
, it doesn't work. For now, I have to paste all imported code directly into the
Bot
, which makes things messy. How can I properly structure local imports for
Bot
resources? Any guidance would be greatly appreciated. Thanks!
a
Hi there @alex_empallo I don't have an answer, but I'm running into the same challenge also. The following threads might be helpful. https://discord.com/channels/905144809105260605/1153427340567789670/1153427340567789670 I think the gist of it is that you have to "flatten" your bot imports by using a "builder" like esbuilder, prior to deploying.
r
how are you compiling/deploying your bot? If you use the instruction here (command line) it will compile/convert the dependencies https://www.medplum.com/docs/bots/bots-in-production#compiling-your-bot This will not work if you just cut and paste into the editor.
a
Thanks so much for the lead, Reshma! @reshma I've been deploying the bots the good ol' fashioned, but slightly clunky in-web browser -- but this looks like a great more sophisticated way of doing things. I'll give that a spin! Thanks so much, as always! 🙂
r
@albert_wong you can check out our Medplum Demo Bots repo for an example (https://github.com/medplum/medplum-demo-bots/tree/main/src)
We use JS bundlers to "compile" mulitple files down to a single JS file for deployment
In this case, we use
esbuild
as our bundler, so you can refer to the
esbuild-script.mjs
for reference on our configuration
a
Awesome, thanks so much, @rahul1 ! Appreciate the lead and I will definitely check that out! I can start to see how it all seems to work together. Great stuff. 🙂
178 Views