how to make links for words in telegram bot?

9.4k views Asked by At

I wanted to make a url for the words in telegram bot.
Used this code but it doesn't work:

https://api.telegram.org/bot$botToken/sendMessage?chat_id=chat_id&text=<a href="url.com">the word</a>

how to make link for the words. when the user clicks on the word, he will go to the url adress page

1

There are 1 answers

12
myxaxa On BEST ANSWER

you should use the parse_mode parameter:

$url = 'https://api.telegram.org/bot<BOT_TOKEN>/sendMessage';
$parameters = [
    'text'       => '<a href=\'url.com\'>word</a>',
    'chat_id'    => <chat_id>,
    'parse_mode' => 'HTML'
];

echo $url . '?' . http_build_query($parameters);

output:

https://api.telegram.org/bot<BOT_TOKEN>/sendMessage?text=%3Ca+href%3D%27url.com%27%3Eword%3C%2Fa%3E&chat_id=<chat_id>&parse_mode=HTML