Skip to main content

Discord Gateway for MQTT

I have created a new organisation on Github today as a place to add automation scripts and the first one I will add is a gateway for Discord.

This core of this script was originally created when I needed to send crash alerts from an application I had written to my phone so that could act upon them quickly. This proved useful and I added it to additional scripts and applications, but found that it was a bit limited if I wanted the alert to be logged elsewhere so I updated my apps and scripts to send to MQTT.

Once my alerts were in MQTT I could pick them up from NodeRed and perform various actions; but I missed having them arrive in Discord, so last night I created an MQTT-2-DISCORD module that includes  support for multiple discord channels.

Installation is fairly simple and I have documented the process in the README.md file associated with the repository.

After installation, visit Discord and obtain a webhook for the channel you want to recieve messages into. You can name the webhook anything you like (mine is called "Home Alerts"). You then edit ~/modules/mqtt-2-discord/config.ini and add a section that contains a unique topic and your webhook:

[HomeAlerts]
topic=messages/alerts        webhook=https://discord.com/api/webhooks/AAAAAAAAAAAAAAAAAA/AAAAAAAAAAAAAAAAAA

Restart the daemon and simply publish to your topic (messages/alerts in this case) to receive a message in Discord.

sudo systemctl stop mqtt2discord
sudo systemctl start mqtt2discord



Comments

Popular posts from this blog

LSP and JSON

I've taken on the challenge of writing an LSP for BlitzMax NG to help with the integration of the vs-code extension.  For those who don't know what an LSP is; it is simply a communications component that is used by any IDE to obtain information regarding your source code. It then uses this information to create outline views, hover, help and diagnostics etc. Rather than use the BlitzMax JSON module, I decided to write a JSON parser specifically for this application that gives me a little more control to transpose JSON directly into BlitzMax Types. I will publish this on GitHub shortly. With the JSON module almost complete, the LSP application can now read/write to/from StdIO and I'm currently working on getting the "initialize" and "shutdown" event handlers operational. Watch this space.

LSP templates

I took a step back with my LSP and decided that what I really need is a template based system for building responses. Previously I had started creating the JSON on the fly but realised that the jsonrpc specification has what it called interfaces which are basically templates, so I wrote a Type that allows you to add templates and variables and then it joins them all together for you. It works well but I might find a better way at some later time. After getting the template system working and removing some debug messages that I think might be inadvertently picked up as responses. For reference, the LSP receives an "initialise" message from the client that contains a lot of data. In my case it was over 4k in size. The LSP then returns an "initialized" message and receives confirmation from the client in the form of an "initialized" notification. The "initialize" and "initialized" messages are very similar. Both contain "jsonrpc"