#!/bin/bash # LinuxGSM alert_telegram.sh module # Author: Daniel Gibbs # Contributors: https://linuxgsm.com/contrib # Website: https://linuxgsm.com # Description: Sends Telegram Messenger alert. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" json=$( cat << EOF { "chat_id": "${telegramchatid}", "message_thread_id": "${telegramthreadid}", "parse_mode": "HTML", "disable_notification": "${telegramdisablenotification}", "text": "${alerttitle}\n\nServer name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\n EOF ) if [ -n "${querytype}" ]; then json+=$( cat << EOF Is my Game Server Online?\nCheck here\n\n EOF ) fi if [ -n "${alerturl}" ]; then json+=$( cat << EOF More info\n${alerturl}\n\n EOF ) fi json+=$( cat << EOF Server Time\n$(date)", "disable_web_page_preview": "yes" } EOF ) fn_print_dots "Sending Telegram alert" telegramsend=$(curl --connect-timeout 3 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" ${curlcustomstring} "https://${telegramapi}/bot${telegramtoken}/sendMessage" | grep "error_code") if [ -n "${telegramsend}" ]; then fn_print_fail_nl "Sending Telegram alert: ${telegramsend}" fn_script_log_fail "Sending Telegram alert: ${telegramsend}" else fn_print_ok_nl "Sending Telegram alert" fn_script_log_pass "Sent Telegram alert" fi