jhuckaby / Cronicle

A simple, distributed task scheduler and runner with a web based UI.
http://cronicle.net
Other
3.9k stars 389 forks source link

Discord Webhook Messages #591

Open Skyfay opened 1 year ago

Skyfay commented 1 year ago

Summary

I am trying to send a report to Discord via Webhoock after a job. However, it does not work. Is that even possible?

Steps to reproduce the problem

I created a Webhook link in Discord and then entered it in the software under "Web Hook" under "E-mail". image

mikeTWC1984 commented 1 year ago

That's because discord expects message text under "content" property, while cronicle uses "text" property (would work with slack and many other messengers). e.g.

curl  -H "Content-Type: application/json"  -d '{"content": "hello"}'   $WEBHOOK_URL

I don't think you can configure that, although you may do a little tweak in lib/job.js file locate this line: https://github.com/jhuckaby/Cronicle/blob/a093f6b94dba3bb6017b3f9e621ddecf84892973/lib/job.js#L1404 then on the next line add something like hook_data.content = hook_data.text

Skyfay commented 1 year ago

Thank you, that works for now. I'll see if I can make it a bit more beautiful with embeds, but that's already great. Is there a reason why webhooks don't have two, one for success and one for failure?

jhuckaby commented 1 year ago

Thank you for that, @mikeTWC1984. If I add that line into the base code, would it break Slack or others? Hmmm... maybe it should be a configurable property name instead.

In Cronicle v2, the web hooks are much more configurable, including assigning them as actions to job complete, job failure, other error codes, etc.

jhuckaby commented 1 year ago

Adding content as a copy of text seems to work on both Discord and Slack, in my testing. I'll go ahead and commit that right now.

jhuckaby commented 1 year ago

Released v0.9.21 with a fix for this. Thanks again, @mikeTWC1984!

Skyfay commented 1 year ago

Hey @jhuckaby

  1. How is it now possible, for example, to send only failed jobs via Webhook?
  2. I would like to change the webhook for Discord. Embed it so it looks better visually and add information like the email notifications. I don't know how to do that though.
jhuckaby commented 1 year ago

@Skyfay See Wiki here: https://github.com/jhuckaby/Cronicle/wiki/Discord-Webhook-Integration

I believe it answers both of your questions.

Skyfay commented 1 year ago

@jhuckaby Thanks. So, embeds work like this:

{
  "embeds": [{
    "title": "Hello!",
    "description": "Hi! :grinning:"
  }]
}

How could I now integrate this into the config, can you give me an example? And is it possible to configure that the different templates (start, complet, failure) can be sent (Global) to different webhook URL's?

jhuckaby commented 1 year ago

I'm sorry, there's no way to do that with Cronicle. You can only customize the text for the notification.

Apologies, but there's also no way to customize the webhook URLs per outcome. However, this feature will be coming in Cronicle v2 (will release sometime in 2023).