[GUIDE] Use Telegram as notification service.

  • OMV 3.x
  • core

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [GUIDE] Use Telegram as notification service.

    Using Telegram as a notification service

    What you need

    - OpenMediaVault 3.x (Latest version)
    - Remote ssh access
    - curl (apt-get install curl)


    Since version 3.0.5 openmediavault implemented the execution of scripts any time postfix processes a notification email that is generated by any system services sending five specific environment variables, not arguments. For this to work is compulsory that you configure an email notification account in the relevant section of OpenMediaVault.
    Note: Emails will still be send, there is no workaround in the moment, postfix needs to be configured. If you have a gmail account you can send it to a username alias so that later on you can create a filter rule in the gmail panel (ex: jon.snow+omv@gmail.com).

    In the case of using Telegram for a notification service you need to create a bot.

    telegram.org/blog/bot-revolution

    Those familiar with telegram bots know that you need to create them chatting with the botfather to get the api token
    telegram.me/botfather


    Once you get your token you need to get a chatid. Chatid's are generated once you establish a direct conversation with the bot. So in the application start talking with the bot and send any text as command. Like "/talk"

    On any terminal with curl installed you can run

    curl 'https://api.telegram.org/botREPLACETOKENHERE/getUpdates?offset=0'

    The output will look something like this

    Source Code

    1. {"ok":true,"result":[{"update_id":60704312,
    2. "message":{"message_id":195,"from":{"id":112632459,"first_name":"John","last_name":"Snow","username":"johnsnow"},"chat":{"id":112632459,"first_name":"John","last_name":"Snow","username":"johnsnow","type":"private"},"date":1472369911,"text":"\/talk","entities":[{"type":"bot_command","offset":0,"length":5}]}}]}


    The value for key "id" is the one we need to use (112632459)

    We create our script

    nano /usr/share/openmediavault/notification/sink.d/20telegram

    We paste this contents

    Shell-Script

    1. #!/bin/bash
    2. BOT_TOKEN="REPLACEHERETOKEN"
    3. CHAT_ID="REPLACEHERECHATIDNUMBER"
    4. URL='https://api.telegram.org/bot'${BOT_TOKEN}
    5. MSG_URL=$URL'/sendMessage?chat_id='
    6. send_message (){
    7. curl --data-urlencode "text=$2" "${MSG_URL}$1&"
    8. }
    9. content=$(echo -e "${OMV_NOTIFICATION_SUBJECT} on the ${OMV_NOTIFICATION_DATE} \n\n $(cat ${OMV_NOTIFICATION_MESSAGE_FILE})")
    10. send_message ${CHAT_ID} "${content[@]}"
    Display All
    Save it and change it to executable

    chmod +x /usr/share/openmediavault/notification/sink.d/20telegram

    you can now run the test send mail in notification section of the web control panel


    Questions / Problems / Discussions

    Use Telegram as notification service Q&A
    New wiki
    chat support at #openmediavault@freenode IRC | Spanish & English | GMT+10
    telegram.me/openmediavault broadcast channel
    openmediavault discord server

    The post was edited 10 times, last by subzero79 ().