This script sends HTML-formatted messages to Telegram users or chats, leveraging the Telegram Bot API. It calculates values dynamically using commands from a runner (e.g., a Linux server), and customizes messages by substituting template variables with actual values.
To test the script's functionality:
- Edit the
bot-ping.conf
file to setBOT_TOKEN
andNOTIFY_TG_IDS
with your own bot token and Telegram user/chat IDs. - Run the script with the
--send-html
parameter:./send_message.sh --send-html <path-to-template.html>
All user/chat IDs listed in NOTIFY_TG_IDS
in the configuration file will receive a message with:
- Server uptime
- CPU/memory load
- Requested user ID
To use your own variables and messages:
- Modify the
template.html
file to include any allowed HTML tags (see the Telegram Bot SDK reference). - Add custom variables using
{{key}}
syntax (e.g.,{{my_custom_value}}
) withintemplate.html
.
- Add corresponding commands in
dynamic_variables.sh
for each{{key}}
you defined in the HTML template. - The keys in
dynamic_variables.sh
and{{key}}
intemplate.html
must match exactly. - Example if you've passed {{my_custom_value}} to html template:
html_vars["my_custom_value"]="some_command_to_get_value"