Request: Discord Webhook Notifier

Would any of our talented developers be interested in making a notification driver that can deliver text to a Discord server Webhook?

It seems to be a pretty simple JSON payload. The hard part, i would guess, is the authorization part.

https://discord.com/developers/docs/resources/webhook

EDIT - Sorry, wrong thing, you want discord, not discourse.
Yep, on my list to do, well at least integrating with the Hubitat Community in general. Just not sure when I'll get to it.

1 Like

Here's a very basic example -- just install this into Drivers Code and then create a virtual device from it. You have to create the webhook in your Discord client and then enter the webhook URL into the virtual device configuration.

Expand for code
/*

*/

metadata
{
    definition(name: "Discord Notification Device", namespace: "tomw", author: "tomw", importUrl: "")
    {
        capability "Notification"
    }
    preferences
    {
        input name: "whUrl", type: "text", title: "Webhook URL", required: true, defaultValue: ""
    }
}

def deviceNotification(text)
{
    try
    {
        def params =
            [
                uri: whUrl,
                body: groovy.json.JsonOutput.toJson([content: text]),
                contentType: "application/json",
                requestContentType: "application/json"
            ]
        
        httpPost(params)
        {
        }
    }
    
    catch(e)
    {
        log.debug "error: ${e.message}"
    }
    
}

FYI @makirules

1 Like