how to make links for words in telegram bot?
Asked Answered
V

1

2

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

Votive answered 27/12, 2016 at 12:29 Comment(2)
Can you explain your question.. more precisely what do you want – Drainpipe
sure, if you want to create a link for any word you just use this code in html <a href="url.com">WORD</a>. i want to create a link for the message of telegram bot! – Votive
C
6

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
Cosenza answered 27/12, 2016 at 15:14 Comment(12)
'$url = 'api.telegram.org/bot316:AAGeiqA_B4G18M/sendMessage'; $chat_id = "@TweetKon"; $message = $items['text']; $usar = $items['user']['name']; $usaremoji = "πŸ‘€"; $fave = $items['favorite_count']; $faveemoji = " | "; $br = "\n"; $linkesh= "twitter.com/$username"; $Channel = "@TweetKon"; $parameters = [ 'text' => '$message.$br.$usaremoji.<a href="twitter.com/$usar>$usar</…', 'chat_id' => '@TweetKon', 'parse_mode' => 'HTML' ]; echo $url . '?' . http_build_query($parameters);' – Votive
thanks for helping. the final code is here but it didnt work – Votive
it works as well as possible i tried it :) thanks for helping bro – Votive
but i have a problem ! it dosn't show the Variable values – Votive
what do u mean with "Variable values"? – Cosenza
p.s. maybe its better to remove to bot token in the comment above ^_- – Cosenza
sorry i cant speak English well! For example in '$Money="Number";' in this code '$Money' is variable and 'Number' is Value – Votive
php puts variable value in a string only with " quotes. – Cosenza
for example: $x = 5; $str = "$x is the value"; // $str will be '5 is the value'. but in case of $str = '$x is the value'; // $str will be '$x is the value'. more info - php.net/manual/en/… – Cosenza
also u can use concatination: $str = $x . ' is the value'; // $str will be '5 is the value' – Cosenza
UMM i didn'd undrestand ! could you please put these codes in your first code?! – Votive
i practiced and it works as well as possible ... thanks for helping. youre the best – Votive

© 2022 - 2025 β€” McMap. All rights reserved.