Skip to content

Commit

Permalink
Merge pull request #13 from jkarppinen/jkarppinen-escape-telegram-mes…
Browse files Browse the repository at this point in the history
…sage

[telegram] escape messages with special chars #8
  • Loading branch information
jkarppinen authored Feb 16, 2025
2 parents f1bb78f + d8da134 commit b9b8485
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/integrations/telegram.msg.send.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?php
function send_telegram_msg($title, $description, $url)
{
function escape_telegram_message(string $message): string {
return htmlspecialchars($message, ENT_NOQUOTES | ENT_HTML5, 'UTF-8');
}

function send_telegram_msg(string $title, string $description, string $url): void {
include dirname(__FILE__) . "/../../secrets.php";
$token = $secrets->telegram_token;
$group_id = $secrets->telegram_group_id;
$escaped_title = escape_telegram_message($title);
$escaped_desc = escape_telegram_message($description);

$tgsend = "https://api.telegram.org/bot{$token}/sendMessage";
$fields = [
"chat_id" => $group_id,
"text" => "<b>{$title}</b>\n\n{$description}",
"text" => "<b>{$escaped_title}</b>\n\n{$escaped_desc}",
"parse_mode" => "html", // alternatives: 'markdown'
];

Expand Down

0 comments on commit b9b8485

Please sign in to comment.