Tol*_*maz 1 php telegram telegram-bot
$data = [
'text' => 'your message here',
'chat_id' => '@channelname'
];
file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($data));
Run Code Online (Sandbox Code Playgroud)
我可以通过这种方式发送消息,但我想动态地在其中放置一个按钮(链接)。我能怎么做?
<?php
$token = '11345342......';
$keyboard = json_encode([
"inline_keyboard" => [
[
[
"text" => "Button 1",
"callback_data" => "1"
],
[
"text" => "Button 2",
"callback_data" => "2"
]
]
]
]);
$data = http_build_query([
'text' => 'your message here',
'chat_id' => '@channelname'
]);
$url = "https://api.telegram.org/bot$token/sendMessage?{$data}&reply_markup={$keyboard}";
$res = @file_get_contents($url);
Run Code Online (Sandbox Code Playgroud)