Triggering kestra on posting to Ghost

I have had a few issues publishing posts on a schedule recently, mostly down the fact that I sit behind cloudflare. One of the things I wanted to do was check that the post had published. Yes, I could hop on to the blog and look, but I would much prefer to be told. While I do use uptime Kuma for monitoring some of my services, this was a bit too complicated for that.

I have been using Kestra for a while, and I do have uptime kuma monitoring it (using a basic web login). Since I know kestra is running and when it is not, I can then get ghost to let me know when something has happened. Fortunately, Ghost supports Webhooks and so does Kestra. I have written about kestra and web hooks before, but I will cover the trigger flow again.

I started by creating a flow in Kestra, called GhostTrigger. This is the recieving trigger in kestra. Ghost needs to be able to reach this url. The following flow was then set up:

id: ghostTrigger
namespace: ansible
description: Start tasks on a webhook from Ghost

labels:
  env: prod
  project: trigger-wrapper

tasks:
  - id: returnData
    type: io.kestra.plugin.core.debug.Return
    format: "v1: {{ trigger.body }}"
  - id: call_outputs_slack-notifer-webhook
    type: io.kestra.plugin.core.flow.Subflow
    namespace: outputs
    flowId: slack-notifier-webhook
    inputs:
      payload: "{{ trigger.body }}"
    wait: true
    transmitFailed: false

triggers:
  - id: ghostTrigger
    type: io.kestra.plugin.core.trigger.Webhook
    description: Ghost webhook
    key: 123456 # Your key here. Don't use 123456!

Once set up, I then tested that I could reach the url from my ghost server. The full url is : https://{your_hostname}/api/v1/executions/webhook/{namespace}/{flowId}/{key}

In my case, it would be: https://kestra/api/v1/executions/webhook/ansible/ghostTrigger/123456

If you want to know more about this, see my previous post. Once this is all working and you can see a (failing) flow being triggered, we can move on to Ghost. The failure, is due to the trigger not having a body and can be ignored at this time. The Slack notifier webhook will need to be set up for you, as this is custom for me.

In Ghost, go to the admin page, then click on the settings cog. Inside the settings, look for "Integrations" under the advanced section. Click on the text that says "Add custom integration". Give your integration a name. I chose the boring name "kestra". Once done, optionally add a description to the section.

Next click "Add Webhook". Give your web hook a name, then select which event you want to trigger on. I chose the "Post published" event. A list of events can be found here. I set the target url to be https://kestra/api/v1/executions/webhook/ansible/ghostTrigger/123456, as per the testing. You will need to add a new webook in Ghost for each event you want to trigger on.

Once complete, you will have a trigger in kestra for every action you wanted to run. For me, this posts a message to slack everytime I publish a post, at a scheduled time. This can, of course, be done using the slack integration, but now I can run extra things based on the trigger.

Things you could do include:

Deploying code to a github repo at post time.
Launching of a new web site at post time.
Custom mail drop

The list goes on...

As an Amazon Associate I earn from qualifying purchases.

If you have found this post useful, please consider donating.