Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Discuss
  3. [TUTORIAL] Get your Cloudron Notifications on Telegram with full details.

[TUTORIAL] Get your Cloudron Notifications on Telegram with full details.

Scheduled Pinned Locked Moved Discuss
6 Posts 4 Posters 382 Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • GengarG Offline
    GengarG Offline
    Gengar
    wrote on last edited by Gengar
    #1

    [TUTORIAL] Get your Cloudron Notifications on Telegram with full details.

    Wanna have those kind of notifications ?
    755c6a1e-d6e6-4391-b2c2-e4ffda589caa-image.png

    Here is a tutorial that will guide you step by step how to do it.

    1) Install N8N on your Cloudron instance.

    fcb56874-be95-46b4-bacf-a024ac6518e1-image.png

    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.
    6e2fcfb7-c211-40e3-b5eb-e9a95e53b5d4-image.png

    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).
    be7e7ba7-f33d-4aee-b4fd-c361078582a5-image.png

    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 :
    f373b788-3c9e-4092-8720-517e9c51f4c8-image.png

    Once done, hit "Create a Workflow" :
    c7d3272c-e50f-44b5-aa43-7e77db051873-image.png

    Here is what we are going to create :
    3616bfa9-2c14-4494-ba1d-68c5f42bbd1e-image.png

    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 :
    6897f625-1904-461e-a194-be5cd7978947-image.png

    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 :
    9928c8dd-0c1d-4fef-93ed-0fdb33b9330d-image.png

    Then create a new api token in "read only" (lecture seule on my screenshot) .
    d5c0ec73-6d63-477a-a253-5f143731e932-image.png

    Copy and save it somewhere , we will need it now in n8n.

    Go back to n8n, and add the next block, an HTTP Request:
    6eac6958-96da-44de-b800-9cadfdb39733-image.png

    Set it up as follow :
    00616c27-1bff-4439-8563-63bbef71c780-image.png

    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 :
    9919b0c1-eaff-401f-b0d2-5390c3cb2e2a-image.png

    Value 1
    {{ $json.notifications.length }}

    Code : Split Notifications

    Here add a code block with the following code :
    53037783-0278-43c5-9278-d0411ba9caa6-image.png

    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.

    70a76ca5-cfdd-4a8f-8e53-1031f12d6485-image.png

    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 :
    13362fcd-0fcc-4787-b838-d988cea1ff76-image.png

    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 :
    43a227aa-9ba6-4c52-b376-f394296f21e2-image.png

    And receive all your Cloudron notifications :
    755c6a1e-d6e6-4391-b2c2-e4ffda589caa-image.png

    1 Reply Last reply
    12
    • BrutalBirdieB Offline
      BrutalBirdieB Offline
      BrutalBirdie
      Partner
      wrote on last edited by
      #2

      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?

      Like my work? Consider donating a drink. Cheers!

      GengarG 1 Reply Last reply
      4
      • robiR Offline
        robiR Offline
        robi
        wrote on last edited by
        #3

        Good time to ask for a webhook feature for Cloudron notifications.. then build Cloudron n8n community nodes for more API automations.

        I've discussed a few in the past, and have a few more up my sleve.

        Conscious tech

        1 Reply Last reply
        2
        • BrutalBirdieB BrutalBirdie

          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?

          GengarG Offline
          GengarG Offline
          Gengar
          wrote on last edited by Gengar
          #4

          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 .

          1 Reply Last reply
          5
          • scookeS Offline
            scookeS Offline
            scooke
            wrote on last edited by
            #5

            screaming-baby-bird.gif

            A life lived in fear is a life half-lived

            1 Reply Last reply
            0
            • GengarG Offline
              GengarG Offline
              Gengar
              wrote on last edited by
              #6

              I've added the json template in the tutorial in chapter 3 "3) n8n => THE FUN PART !"

              1 Reply Last reply
              2
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Bookmarks
              • Search