[TUTORIAL] Get your Cloudron Notifications on Telegram with full details.
-
[TUTORIAL] Get your Cloudron Notifications on Telegram with full details.
Wanna have those kind of notifications ?
Here is a tutorial that will guide you step by step how to do it.
1) Install N8N on your Cloudron instance.
2) Create a Telegram Channel (Public or Private) and create a Telegram Bot (it's very easy)
First, open Telegram and create a new channel. You can choose to make it public or private. Give it a name, like "Cloudron Notifications". You’ll need the channel ID later.
Then, search for "
BotFather
" in Telegram and start a chat. Type/start
, then/newbot
. Give your bot a name and a username (the username must end with "bot", like "cloudron_notifier_bot
"). BotFather will give you a token – copy it and save it, you’ll need it in n8n.Now go back to your Telegram channel, open the channel settings, go to "Administrators", and add your bot as an admin. Make sure it has permission to post messages. This will allow n8n to send messages to the channel using your bot.
TIPS : To get your channel ID, you can use Uptime Kuma (in Cloudron) , it has a way of retriving it automatically if you posted in the channel before. Here is a screen of Uptime Kuma and the "Retrive automatically" option (named "Récupérer automatiquement" in my screenshot).
3) n8n => THE FUN PART !
Now let's automate everything in n8n !
Start by creating a credential in n8n, it will be your Chat ID and bot Token generated before with the help of BotFather :
Once done, hit "Create a Workflow" :
Here is what we are going to create :
But you can skip the creation using this cheatcode => Save the following code in a .json file and import it in n8n. You will have to replace the informations starting with
REPLACE_WITH_
in the json file or directly in n8n after the import :{ "name": "Cloudron notifications - optimized", "nodes": [ { "parameters": { "mode": "runOnceForEachItem", "jsCode": "const staticData = $getWorkflowStaticData('global');\nstaticData.notifiedIds = staticData.notifiedIds || [];\n\nif (staticData.notifiedIds.includes($json.id)) {\n return null; // already sent, skip\n}\n\nstaticData.notifiedIds.push($json.id);\n\nreturn {\n json: {\n ...$json,\n status: `🆕 À envoyer: ${$json.id}`\n }\n};" }, "id": "78efcc79-4982-4770-9156-e928b15da511", "name": "Check & Store ID", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 580, -600 ] }, { "parameters": { "chatId": "-REPLACE_WITH_YOUR_TELEGRAM_CHAT_ID", "text": "=📣 <b>Cloudron Notification</b>\n<b>Title:</b> {{ $json.title || \"Sans titre\" }}\n<b>Message:</b> {{ $json.message || \"Pas de contenu\" }}\n", "additionalFields": { "parse_mode": "HTML" } }, "id": "aa664df7-4d0c-49b4-b356-1c4d48340e08", "name": "Send Telegram Message", "type": "n8n-nodes-base.telegram", "typeVersion": 1, "position": [ 800, -600 ], "webhookId": "REDACTED", "credentials": { "telegramApi": { "id": "REPLACE_WITH_YOUR_TELEGRAM_CREDENTIAL_ID", "name": "Telegram-REPLACE_WITH_YOUR_DOMAIN" } } }, { "parameters": { "jsCode": "return $json.notifications.map(n => ({ json: n }));" }, "id": "0475daf5-1e32-4a7b-a4c7-c9d0eed00f3c", "name": "Split Notifications", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 360, -600 ] }, { "parameters": { "conditions": { "string": [ { "value1": "={{ $json.notifications.length }}", "operation": "notEqual", "value2": "0" } ] } }, "id": "820ea8b0-98e7-46de-95e7-2a3de2f1aca8", "name": "Notification exists ?", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 140, -600 ] }, { "parameters": { "url": "https://my.REPLACE_WITH_YOUR_DOMAIN.XYZ/api/v1/notifications?acknowledged=false&page=1&per_page=2", "options": {}, "headerParametersUi": { "parameter": [ { "name": "Authorization", "value": "Bearer REPLACE_WITH_YOUR_CLOUDRON_REAN_ONLY_API_TOKEN" } ] } }, "id": "0ae368d4-82bd-4908-855c-80aab9303079", "name": "Get Cloudron Notifications", "type": "n8n-nodes-base.httpRequest", "typeVersion": 1, "position": [ -80, -600 ] }, { "parameters": { "rule": { "interval": [ { "field": "minutes", "minutesInterval": 1 } ] } }, "id": "0483e050-46ef-4d64-9b93-e3fefd5f46c8", "name": "Schedule Trigger", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [ -300, -600 ] } ], "pinData": {}, "connections": { "Check & Store ID": { "main": [ [ { "node": "Send Telegram Message", "type": "main", "index": 0 } ] ] }, "Split Notifications": { "main": [ [ { "node": "Check & Store ID", "type": "main", "index": 0 } ] ] }, "Notification exists ?": { "main": [ [ { "node": "Split Notifications", "type": "main", "index": 0 } ] ] }, "Get Cloudron Notifications": { "main": [ [ { "node": "Notification exists ?", "type": "main", "index": 0 } ] ] }, "Schedule Trigger": { "main": [ [ { "node": "Get Cloudron Notifications", "type": "main", "index": 0 } ] ] } }, "active": true, "settings": { "executionOrder": "v1" }, "versionId": "693afd07-69b9-4335-8dbb-6db99b7bae56", "meta": { "templateCredsSetupCompleted": true, "instanceId": "REDACTED" }, "id": "WMS9ieiGEvYuv2TF", "tags": [] }
Schedule Trigger
It's just a cron job that will run each 60 seconds.
Setup it like this :
Get Cloudron Notifications - HTTP Request
So the idea of this node is to get the notifications from cloudron. For this you will need a Cloudron API Token with read rights.
To do this, go to your Cloudron > Click on your username > Profile :
Then create a new api token in "read only" (lecture seule on my screenshot) .
Copy and save it somewhere , we will need it now in n8n.
Go back to n8n, and add the next block, an HTTP Request:
Set it up as follow :
URL :
https://my.TLD.xyz/api/v1/notifications?acknowledged=false&page=1&per_page=2
Headers :
Name :Authorization
Value :Bearer YOUR_CLOUDRON_API_READ_ONLY_TOKEN
IF : Notifications exists ?
Notifications exists is an IF block.
Set it up as below :
Value 1
{{ $json.notifications.length }}
Code : Split Notifications
Here add a code block with the following code :
return $json.notifications.map(n => ({ json: n }));
The mode MUST BE "Run Once for All Items".
Code : Check & Store ID
In order to avoid spamming you each 60 seconds, we will setup a second code block that will check is the notification has already been sent. And if it has not been set il will continue to send it and it will store the ID of this notification in memory ready to compare with the next notification ID.
Here is the code used in this block :
const staticData = $getWorkflowStaticData('global'); staticData.notifiedIds = staticData.notifiedIds || []; if (staticData.notifiedIds.includes($json.id)) { return null; // already sent, skip } staticData.notifiedIds.push($json.id); return { json: { ...$json, status: `🆕 À envoyer: ${$json.id}` } };
Send the notification to Telegram
And the last block, sending the notification to your telegram channel using your telegram bot. Here we are using the credentials you created before in n8n.
Set it up as follow :
Here is the HTML text I use in the text field :
📣 <b>Cloudron Notification</b> <b>Title:</b> {{ $json.title || "Sans titre" }} <b>Message:</b> {{ $json.message || "Pas de contenu" }}
AND THAT's IT ! ENJOY !
Just Save It and Activate IT :
And receive all your Cloudron notifications :
-
Hey! That is pretty cool!
Did you know you can export the whole flow as json and post in here as an easy import for people who want to try it out? -
Hey! That is pretty cool!
Did you know you can export the whole flow as json and post in here as an easy import for people who want to try it out?Hey @BrutalBirdie, Yeah I'm aware and I planned to but I was too tired yesterday evening. I started to write the tutorial and I was like "Oh hell, why did I start so late to do that, I have to wake up so early tomorrow" , and I tried to speed run the tutorial.
I will export it today , remove my API tokens from the json and update the tutorial by adding a chapter "fast way - importing json" or something similar .