If using Mastodon Then use bot.

How to create a bot to send alerts from IFTTT to Mastodon.

Back when Twitter was fun I coded a handful of bots.

Nothing massively complicated.

Lots of If / Then / Else loops that were designed to start a conversation and elicit a response.

Lets just say they got a reaction.

I wasn’t really too interested on repeating the process on Mastodon and anyway the Fediverse audience is wildly different to the Twitter one.

But I was still interested in automation and wondered what else could be done.

My homemade Googlebot was already controlling my Hue lights via IFTTT and I was pretty sure that IFTTT could talk to Mastodon.

The Mastodon API bit

First things first, we need to authorise IFTTT to be able to write to the Mastodon account.

Following the path ‘Edit profile | Development | New application’ will get you to the screen where you can create an application to interact with Mastodon.

There are a host of available API options but for this purpose, IFTTT just needs to able to ‘write’ to Mastodon i.e. send a ‘Status’ message.

Press ‘Submit’ to create the new application.

Screenshot showing the Mastodon API screen where a new application can be created. It shows an existing application called IFTTT with write permissions. Mastodon API Screen

Now when you go into the newly created application the authorisation keys will be visible.

The ‘access token’ is the important bit here and the string we will need to paste into the IFTTT interface to authorise interaction with Mastodon.

Screenshot showing the Mastodon API screen. It shows where the details of the ‘Access Token’ are generated. It is this token that will be needed for IFTTT to talk to Mastodon. Mastodon Add Application Screen

The IFTTT bit

Once we have authorised an application to be able to write to Mastodon we need to have a step in the IFTTT flow that is a ‘write to Mastodon’ step.

I had previously gone through a process to set up the Hue lights.

I needed to add a further step that was ‘send some text to Mastodon’.

The ‘webhooks’ or ‘web requests’ screen. This is where IFTTT talks to Mastodon and where the previously generated ‘Access Token’ will be pasted. IFTTT Add Webhook Screen

This extra step is a ‘webhook’.

The ‘webhooks’ screen in detail. Here the ‘Access Token’ is pasted in and further details of how to communicate with Mastodon are entered, e.g. what text to send as a ‘Status’ update. IFTTT Add Action Screen

URL

However, the mastodon end point (URL) will depend on the server you are writing to.

I am writing to botsin.space and my end point is:

https://botsin.space/api/v1/statuses

Method

Next, we are sending a ‘POST’ request as we are trying to ‘write’ or POST to Mastodon.

Content Type

We are sending the form using the POST method.

application/x-www-form-urlencoded

Additional Headers

It is the form headers that contain the Mastodon authorisation.

Note: Make sure that the access token has the words ‘Authorization: Bearer ‘ before it, and only one (1) space between the words and the token string.

Authorization: Bearer <Your access token>

Body

Lastly, the form body contains the content of what we are wanting to POST preceded by ‘status=’.

status=Somebody turned the kitchen lights on

Finally, to create the webhook, click ‘Update action’.

Finally

A bot that sends whatever text was in the IFTTT ‘status=’ step to the Mastodon account using the Mastodon API.

However, if you would like to see the real world bot in action it can could be found at botsin.space/@ConsummateTinkerer (no longer alive).

The finished and completed bot showing the updated status, based on the trigger of the HUE lights being turned off. Mastodon Bot Results

And that is how you create a Mastodon IFTTT bot.

This one is straightforward and I’ll look at more complex interactions at a later date.