-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Hi team,
I'm currently working on integrating Telegram notifications into Thold. So far, the basic functionality is working — messages are successfully sent with device information and threshold alerts. However, I'm stuck on one specific part: I can't figure out which variable contains the graph image, or how the image itself is generated.
Here is a relevant snippet where the email and Telegram message are sent:
if (trim($warning_emails) != '' && $thold_data['acknowledgment'] == '') {
$message = get_thold_warning_text($thold_data['data_source_name'], $thold_data, $h, $thold_data['lastread'], $thold_data['local_graph_id']);
thold_mail($warning_emails, $warning_bcc_emails, '', $subject, $message, $file_array, '', $notify_list_id, $h, $format_file, $thold_data['graph_timespan']);
send_telegram($message, $subject, $h, $format_file, $thold_data['graph_timespan']);And here’s an example of what I currently receive in Telegram:
NORMAL: 'Threshold name' restored to Normal Threshold with value 1.29 Ti
Device: 'host'
Hostname: 'ip'A Threshold has returned to normal status. Device: 'host' ('IP')
URL: Link to Graph in Cacti
Message:Graph: default.format (Last 7 days)
As you can see, there’s no actual image included — just the text.
Here’s the code of my send_telegram() function, in case it helps:
function send_telegram($tg_text, $subject = '', $host = array(), $format_file = '', $graph_timespan = 7) {
$tg_text = strip_tags($tg_text);
$TG_apiToken = ""; // your telegram apiToken
$TG_chatid =""; // your telegram chatid
$TG_message = '';
if (!empty($subject)) {
$TG_message .= "<b>" . htmlspecialchars($subject) . "</b>\n\n";
}
if (!empty($host)) {
$TG_message .= "<b>Device:</b> " . htmlspecialchars($host['description']) . "\n";
if (!empty($host['hostname'])) {
$TG_message .= "<b>Hostname:</b> " . htmlspecialchars($host['hostname']) . "\n";
}
if (!empty($host['ip'])) {
$TG_message .= "<b>IP:</b> " . htmlspecialchars($host['ip']) . "\n";
}
$TG_message .= "\n";
}
$TG_message .= $tg_text;
if (!empty($format_file)) {
$TG_message .= "\n\n<b>Graph:</b> " . htmlspecialchars($format_file);
if ($graph_timespan > 0) {
$TG_message .= " (Last " . $graph_timespan . " days)";
}
}
$TG_message = urlencode($TG_message);
$response = file_get_contents("https://api.telegram.org/bot$TG_apiToken/sendMessage?chat_id=$TG_chatid&text=$TG_message&parse_mode=HTML");
}My question is:
How is the graph image actually generated and attached (e.g. in email), and where can I get the image file or URL so I can include it in the Telegram message (either as a link or as a photo)?
Thanks in advance for any guidance!