loading...

Discord Integration with Apache NiFi

tspannhw profile image Timothy Spann Originally published at datainmotion.dev on ・2 min read

Discord Integration with Apache NiFi

For Slack, it's easy and built-in but sometimes as I was reminded you may want to send messages elsewhere. Thanks to Brian Stitt for the starting information.

I created a free Discord Server in a few seconds and was ready to send messages.

https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks

You then copy the webhook URL and you are ready to call. It's a long SSL link, just past that into the InvokeHTTP processor.

In our flow we need to create an SSL Context for NiFi. If you are using NiFi in a CDP DataHub there's one for you already configured!

The output will not have a body but there will be cool headers if you want to save them or use them for processing. Otherwise wrap this in a process group and you have an alert system of your own.

Before we call the InvokeHTTP we need to set the username of the bot.

Your message must be encoded as JSON like so:

{

"content": "This is my message"

}

Let's call the hook with our data every field is important.

HTTP Method: POST

Remote URL: https://discord.com ... our copied webhooks link

SSL Context: Create or use a StandardSSLContextService

Date Header: False

Follow Redirecrs: True

Use Digest: False

Always Output Response: True

Add Response Headers to Request: False

Content-Type: application/json

Send Message Body: true

Chunk Encoding: False

Ignore responses content: false

Here are the results:

We can see the output of the call to Discord Webhook HTTPS REST Endpoint:

We can see our bot, Spidey Bo t, has posted some exciting test messages from NiFi.

For Source Code:

https://github.com/tspannhw/NiFiToDiscord

References:

Posted on by:

tspannhw profile

Timothy Spann

@tspannhw

I am a Principal Field Engineer for Data in Motion at Cloudera. I work with Apache NiFi, Apache Kafka, Apache Spark, Apache Flink, IoT, MXNet, DLJ.AI, Deep Learning, Machine Learning, Streaming...

Discussion

markdown guide