NodeJS Bambu Library (and a discord bot)

Hello everyone!

I’ve been working on a library to integrate with the Bambu printers. Right now, it only integrates with the MQTT service and FTP, but I’m adding things as I figure out how they work.

I’ve also got a discord bot in here that allows you to get the status information of your printer directly in discord.

Check it out, and please give comments and suggestions. Let me know if you have any questions or want to help!

1 Like

Recently released v4.1 of @node-bambu/core and @node-bambu/discord

Please check it out, and provide feedback and requested features!

Do you have a docker-compose file for that? :smiley:

Theres a docker image for the app that runs it. If you run this with the environment variables specified in .env.dist (minus twitch, if you don’t want to set that up), it’ll get you what you want

didn’t work.

docker pull ghcr.io/aequasi/node-bambu/bot:sha256-8a64902ab0a2892803ea027040ab8ca1317020d2987246d81949ac67a334132e.sig
sha256-8a64902ab0a2892803ea027040ab8ca1317020d2987246d81949ac67a334132e.sig: Pulling from aequasi/node-bambu/bot
unsupported media type application/vnd.dev.cosign.simplesigning.v1+json

Sounds like you might be on an old version of docker

Is there a bit of a guide on setting this up?

[root@portainer ~]# docker pull Package node-bambu/bot · GitHub
sha256-c5ec14b96ed29a11a8ceb80cd3a3fa6e1ec982e37e4a19f55f8521975214acea.sig: Pulling from aequasi/node-bambu/bot
unsupported media type application/vnd.dev.cosign.simplesigning.v1+json
[root@portainer ~]# docker --version
Docker version 24.0.0, build 98fdcd7
[root@portainer ~]#

@aequasi I think this is related to some limitations with ghcr.io, it seems to create the cosign signatures as tags and not OCI Artifacts and therefore does not recognise the content-type which is included in the header by default.

Maybe do a test push to Dockerhub and see if the behaviour persists, else, and I know this is highly suboptimal (I would prefer to help you fix it), disable cosign.

Quite odd. I’ve not had any issues cloning it (I’m also using portainer). I’ll try to get it pushed to dockerhub as well though.

Works for me in podman using podman-docker…

❯ docker pull ghcr.io/aequasi/node-bambu/bot:main
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Trying to pull ghcr.io/aequasi/node-bambu/bot:main...
Getting image source signatures
Copying blob 921f89f677ce done  
Copying blob f56be85fc22e done  
Copying blob 60542df8b663 done  
Copying blob 931b0e865bc2 done  
Copying blob 19175ef93cd9 done  
Copying blob 062e26bc2446 done  
Copying blob c5c99beadfbc done  
Copying config 581d269d93 done  
Writing manifest to image destination
Storing signatures
581d269d93d64eb69fbb90dc2f61fc42b53b12e51caf94b3513639ee7c5db51b

Alright, its been published to docker hub as well, nodebambu/bot

1 Like

Does the container work?

I have an error when i start it, i provided the enviroment variables as requested, bit it prints an error in the logs:

[25/05/23 02:08:35 PM][error]:    Failed to initialize { services: [ 'database', 'interactionHandler' ], error: DataTypeNotSupportedError: Data type "timestamptz" in "QueueItem.printedAt" is not supported by "better-sqlite3" database.
       at /app/src/metadata-builder/EntityMetadataValidator.ts:136:31
       at Array.forEach (<anonymous>)
       at EntityMetadataValidator.validate (/app/src/metadata-builder/EntityMetadataValidator.ts:128:18)
       at /app/src/metadata-builder/EntityMetadataValidator.ts:43:18
       at Array.forEach (<anonymous>)
       at EntityMetadataValidator.validateMany (/app/src/metadata-builder/EntityMetadataValidator.ts:42:25)
       at DataSource.buildMetadatas (/app/src/data-source/DataSource.ts:724:33)
       at DataSource.initialize (/app/src/data-source/DataSource.ts:259:13)
       at async Promise.all (index 0)
       at BambuBot.start (file:///packages/discord/src/BambuBot.ts:59:5) }
[25/05/23 02:08:35 PM][error]:    Data type "timestamptz" in "QueueItem.printedAt" is not supported by "better-sqlite3" database. { stack: 'DataTypeNotSupportedError: Data type "timestamptz" in "QueueItem.printedAt" is not supported by "better-sqlite3" database.\n    at /app/src/metadata-builder/EntityMetadataValidator.ts:136:31\n    at Array.forEach (<anonymous>)\n    at EntityMetadataValidator.validate (/app/src/metadata-builder/EntityMetadataValidator.ts:128:18)\n    at /app/src/metadata-builder/EntityMetadataValidator.ts:43:18\n    at Array.forEach (<anonymous>)\n    at EntityMetadataValidator.validateMany (/app/src/metadata-builder/EntityMetadataValidator.ts:42:25)\n    at DataSource.buildMetadatas (/app/src/data-source/DataSource.ts:724:33)\n    at DataSource.initialize (/app/src/data-source/DataSource.ts:259:13)\n    at async Promise.all (index 0)\n    at BambuBot.start (file:///packages/discord/src/BambuBot.ts:59:5)' }
[25/05/23 02:08:35 PM][error]:    uncaughtException: Data type "timestamptz" in "QueueItem.printedAt" is not supported by "better-sqlite3" database.
DataTypeNotSupportedError: Data type "timestamptz" in "QueueItem.printedAt" is not supported by "better-sqlite3" database.
    at /app/src/metadata-builder/EntityMetadataValidator.ts:136:31
    at Array.forEach (<anonymous>)
    at EntityMetadataValidator.validate (/app/src/metadata-builder/EntityMetadataValidator.ts:128:18)
    at /app/src/metadata-builder/EntityMetadataValidator.ts:43:18
    at Array.forEach (<anonymous>)
    at EntityMetadataValidator.validateMany (/app/src/metadata-builder/EntityMetadataValidator.ts:42:25)
    at DataSource.buildMetadatas (/app/src/data-source/DataSource.ts:724:33)
    at DataSource.initialize (/app/src/data-source/DataSource.ts:259:13)
    at async Promise.all (index 0)
    at BambuBot.start (file:///packages/discord/src/BambuBot.ts:59:5) { error: { DataTypeNotSupportedError: Data type "timestamptz" in "QueueItem.printedAt" is not supported by "better-sqlite3" database.
       at /app/src/metadata-builder/EntityMetadataValidator.ts:136:31
       at Array.forEach (<anonymous>)
       at EntityMetadataValidator.validate (/app/src/metadata-builder/EntityMetadataValidator.ts:128:18)
       at /app/src/metadata-builder/EntityMetadataValidator.ts:43:18
       at Array.forEach (<anonymous>)
       at EntityMetadataValidator.validateMany (/app/src/metadata-builder/EntityMetadataValidator.ts:42:25)
       at DataSource.buildMetadatas (/app/src/data-source/DataSource.ts:724:33)
       at DataSource.initialize (/app/src/data-source/DataSource.ts:259:13)
       at async Promise.all (index 0)
       at BambuBot.start (file:///packages/discord/src/BambuBot.ts:59:5)
     level: 'error',
     [Symbol(level)]: 'error' }, stack: 'DataTypeNotSupportedError: Data type "timestamptz" in "QueueItem.printedAt" is not supported by "better-sqlite3" database.\n    at /app/src/metadata-builder/EntityMetadataValidator.ts:136:31\n    at Array.forEach (<anonymous>)\n    at EntityMetadataValidator.validate (/app/src/metadata-builder/EntityMetadataValidator.ts:128:18)\n    at /app/src/metadata-builder/EntityMetadataValidator.ts:43:18\n    at Array.forEach (<anonymous>)\n    at EntityMetadataValidator.validateMany (/app/src/metadata-builder/EntityMetadataValidator.ts:42:25)\n    at DataSource.buildMetadatas (/app/src/data-source/DataSource.ts:724:33)\n    at DataSource.initialize (/app/src/data-source/DataSource.ts:259:13)\n    at async Promise.all (index 0)\n    at BambuBot.start (file:///packages/discord/src/BambuBot.ts:59:5)', exception: true, date: 'Thu May 25 2023 14:08:35 GMT+0000 (Coordinated Universal Time)', process: { pid: 1, uid: 0, gid: 0, cwd: '/app', execPath: '/usr/local/bin/node', version: 'v18.16.0', argv: [ '/usr/local/bin/node', '/app/index.js' ], memoryUsage: { rss: 116518912, heapTotal: 85786624, heapUsed: 47348688, external: 1536453, arrayBuffers: 261998 } }, os: { loadavg: [ 0.39, 0.39, 0.42 ], uptime: 108115.83 }, trace: [ { column: 31, file: '/app/src/metadata-builder/EntityMetadataValidator.ts', function: null, line: 136, method: null, native: false }, { column: null, file: null, function: 'Array.forEach', line: null, method: 'forEach', native: false }, { column: 18, file: '/app/src/metadata-builder/EntityMetadataValidator.ts', function: 'EntityMetadataValidator.validate', line: 128, method: 'validate', native: false }, { column: 18, file: '/app/src/metadata-builder/EntityMetadataValidator.ts', function: null, line: 43, method: null, native: false }, { column: null, file: null, function: 'Array.forEach', line: null, method: 'forEach', native: false }, { column: 25, file: '/app/src/metadata-builder/EntityMetadataValidator.ts', function: 'EntityMetadataValidator.validateMany', line: 42, method: 'validateMany', native: false }, { column: 33, file: '/app/src/data-source/DataSource.ts', function: 'DataSource.buildMetadatas', line: 724, method: 'buildMetadatas', native: false }, { column: 13, file: '/app/src/data-source/DataSource.ts', function: 'DataSource.initialize', line: 259, method: 'initialize', native: false }, { column: null, file: null, function: 'async Promise.all', line: null, method: 'all', native: false }, { column: 5, file: 'file:///packages/discord/src/BambuBot.ts', function: 'BambuBot.start', line: 59, method: 'start', native: false } ] }

I don’t know, I didn’t try to validate if it works or not. I implement my own solution for this using MQTT, Prometheus, and Grafana using mqtt-exporter and the dashboard from bambulabs-exporter.

I don’t really like noisy bots in things like Discord, I’d rather just have alertmanager centrally manage all my alerting as I do with all my other stuff so this project isn’t something I am interested in using.

I only tried to pull the image on podman on Fedora because it was a funky edge case and to validate the image was pushed correctly and was in a valid format.

Anything else should be directed to @aequasi

1 Like

I have plans to improve this, but ive been rather busy. I’m hoping to get back to it in the next few weeks

Definitely needs better documentation, I have the bot running at this point but have no clue how to get it to join my discord or what commands it uses. Or if it can post periodic status updates to a specific channel.

Your install instructions need to be way clearer.

Missing npx portion of the start command which took me a minute to realize. Please dedicate some time to documentation!

1 Like

I have the same problem!

I would do ANYTHING to have someone give instructions on how to set this up/video or whatever for a NOOB. I had Octoprint for my prusa and loved the discord bot. But this one is a whole different thing. The one that I used for my prusa was octoprint everywhere. It was simple to do just click add bot lol. This is something that is a bit beyond my lvl. But I WOULD KILL to have this running. I know that it would have to run on a local computer. Could I do that on my PI that has octoprint on it? I only ask due to i still have my prusa and use the pi for it, just would love to use it to run this for my BRAND NEW X1C lol

Can anyone advise on how to get the information to fill out the .env file? specifically, where to find the following variables:

BAMBU_PRINTER_HOST= (is this just the ip?)
BAMBU_PRINTER_PORT=8883
//BAMBU_PRINTER_SERIAL=// i have this one
BAMBU_PRINTER_TOKEN= (the lan password thing?)
DISCORD_CLIENT_ID=
DISCORD_PUBLIC_KEY=
DISCORD_TOKEN=

i think i’ve got the discord stuff figured out, though i’d like to double check that i was on the right track. But i’m at a loss for where to find the printer host and token.

Okay. I did some digging into the code. looks like a few levels deep there’s comments about how to find stuff.
in “node-bambu/packages/core/” we find a readme that has the folowing information:

const client = new BambuClient({
host: ‘10.10.20.101’, // Found inside the Bambu Network Settings on the Bambu printer itself (Click the Cog > Network > IP)
port: 8883,
token: ‘’, // Found inside the Bambu Network Settings on the Bambu printer itself (Click the Cog > Network > Access Code)
serial: ‘’, // Found inside the Bambu System Settings on the Bambu printer itself (Click the Cog > General > Device Info)
});

This information translates to the printer stuff mentioned in my earlier post.

within the directory “node-bambu/packages/discord” we find another readme that, while not as detailed, does provide some explination:

const bot = new BambuBot({
discord: {
clientId: ‘discord bot application id’,
publicKey: ‘discord bot public key’,
token: ‘discord bot token’,

i haven’t had the opportunity to implement this, but hopefully it helps someone.