cameroncros / OctoPrint-DiscordRemote

Discord plugin for OctoPrint
MIT License
66 stars 34 forks source link

Send message to discord on arbitrary gcode? #165

Closed mtw3d closed 3 years ago

mtw3d commented 3 years ago

This may be possible already, but the documentation is a bit vague.

I want to be send a message to discord when I specific gcode is sent. For example, M600 triggers a filament change routine, and I want to be notified that a change is required via discord. I have a couple places where I would like to send similar alerts.

The docs refer to the Send Message API, but there is no information on how to actually implement such a feature. Can you expand on how to make this work?

cameroncros commented 3 years ago

The send message API allows a 3rd party plugin to send messages via DiscordRemote. To do this, you create a POST request to [octoprint_url]/api/plugin/discordremote, with the body of the request being a JSON string similar to:

{
    "command": "sendMessage",
    "title": "TITLE GOES HERE",
    "description": "DESCRIPTION GOES HERE",
    "color": 0x123456,
    "image": "BASE64 ENCODED FILE DATA HERE",
    "imagename": "IMAGE NAME GOES HERE"
}

Using this hook: https://docs.octoprint.org/en/master/plugins/hooks.html#octoprint-comm-protocol-gcode-received You should be able to extend DiscordRemote to send a message when an M600 is received. Unfortunately, I do not have the time to make that change, but I am happy to provide any further guidance you need.