或类似https://t.me/RoobaiOfficaial/2032
我是编码的新手,无法让bot正常工作将不胜感激
编码我如何上传图片并设置聊天ID
<form method="post" enctype="multipart/form-data">
<input type="text" name="chat_id" value="" />
<input type="url" name="photo" value="" />
<input type="submit" name="send" action="<?php echo $website.'/sendPhoto'?>"/>
</form>
然后我添加消息并创建1个包含URL的内联按钮
<?php
$msg= urlencode("test message");
$token="bot_token";
$chatId="chat_id";
$response=($_POST['photo']);
$response=$response.urldecode($msg);
$keyboard = [
'inline_keyboard' => [
[
['text' => 'Buy Now', 'url' => 'https://i.stack.imgur.com/vLHu9.png']
]
]
];
$encodedKeyboard = json_encode($keyboard);
$parameters =
array(
'chat_id' => $chatId,
'text' => $response,
'reply_markup' => $encodedKeyboard
);
send('sendMessage', $parameters); // function description Below
function send($method, $data)
{
$url = "https://api.telegram.org/".$token. "/" . $method;
if (!$curld = curl_init()) {
exit;
}
curl_setopt($curld, CURLOPT_POST, true);
curl_setopt($curld, CURLOPT_POSTFIELDS, $data);
curl_setopt($curld, CURLOPT_URL, $url);
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curld);
curl_close($curld);
return $output;
}
我正在获得这种类型的响应,但是我需要它而没有链接Response
答案 0 :(得分:0)
尝试更新以下两行:
send('sendMessage', $parameters); // function description Below
function send($method, $data)
包含$ token
send('sendMessage', $parameters, $token); // function description Below
function send($method, $data, $token)
此链接说明了为什么它可能无法按您期望的方式工作。 http://php.net/manual/en/language.variables.scope.php