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.
https://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
https://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
{"ok":true,"result":[{"update_id":60704312,
"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
#!/bin/bash
BOT_TOKEN="REPLACEHERETOKEN"
CHAT_ID="REPLACEHERECHATIDNUMBER"
URL='https://api.telegram.org/bot'${BOT_TOKEN}
MSG_URL=$URL'/sendMessage?chat_id='
send_message (){
curl --data-urlencode "text=$2" "${MSG_URL}$1&"
}
content=$(echo -e "${OMV_NOTIFICATION_SUBJECT} on the ${OMV_NOTIFICATION_DATE} \n\n $(cat ${OMV_NOTIFICATION_MESSAGE_FILE})")
send_message ${CHAT_ID} "${content[@]}"
Alles anzeigen
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