Updating the Ivory Bridge with the ability to post and attach featured images to Mastodon

An update to the IvoryBridge

Updating the Ivory Bridge with the ability to post and attach featured images to Mastodon

Some time ago, I developed a Flask app to seamlessly bridge my blog posts with my Mastodon account. While I could have utilized a service like Zapier, I was eager to learn about the Mastodon API and explore its capabilities. As it turns out, creating the bridge was entirely feasible.

Recently, I revisited the project to see if I could incorporate the featured images from my blog posts into the Mastodon toots. I am pleased to report that I successfully achieved this. To accomplish this, I followed a process that involved fetching the featured image, posting it to the Mastodon API to obtain a media ID, and then creating a toot with the attached media ID.

For those interested in implementing their own Ivory Bridge, I have open-sourced the code and made it available on my GitHub account. Feel free to give it a try and share your experiences or suggestions.

GitHub - ephergent/ivorybridge
Contribute to ephergent/ivorybridge development by creating an account on GitHub.

*** Update on the webhook posting to Mastodon 5 times in a row ***

I recently encountered an issue with the Ghost blog platform where my IvoryBridge webhook was being retried five times. After some investigation, I discovered that Ghost fires the trigger five times if it doesn't receive an HTTP status 200 within two seconds. This can be problematic, as uploading a featured image often takes longer than the given time frame. Although there was a patch created for this issue previously, I opted to make the necessary adjustments myself, knowing that I would need the skillset for future updates.

Unfortunately, it doesn't seem that the Ghost developers plan to allow changes via an environmental variable. Nevertheless, I'd like to share my solution for those who are experiencing similar challenges:

Using your preferred text editor, open the trigger.js file on your server. You can locate the file in the following directory:

GHOST_HOME/current/core/server/services/webhooks/trigger.js 

Navigate to approximately line 104, and modify the timeout value from 2 * 1000 to 10 * 1000 or another appropriate duration based on your hosting needs. In my case, a 10-second timeout proved more than sufficient.

            const opts = {
                body: reqPayload,
                headers,
                timeout: 10 * 1000,
                retry: process.env.NODE_ENV?.startsWith('test') ? 0 : 5
            };

After saving the changes to the trigger.js file, restart your Ghost service and test the webhook.

If everything works as intended, you should see only a single post in your Mastodon timeline. Best of luck with your Ghost platform adjustments.

Links for reference:

Webhook getting triggered multiple times
Following up to earlier comment, I have put this patch together to resolve my issue to extend timeout various-patches/ghost-webhooks-trigger-extend-timeout.patch at main · influencerTips/various-patches · GitHub As a note will continue to work on this as patch so that it uses the Ghost config file…
various-patches/ghost-webhooks-trigger-extend-timeout.patch at main · influencerTips/various-patches
Used for patches to help make stuff work. Contribute to influencerTips/various-patches development by creating an account on GitHub.