Я пытаюсь сделать телеграмму ботом, но у меня проблема при отправке фотографии. Это мой код:php telegram bot отправить фото не запускать
У меня есть эта функция:
function apiRequestImage($method, $parameters)
{
if (!is_string($method)) {
error_log("Method name must be a string\n");
return false;
}
if (!$parameters) {
$parameters = array();
} else if (!is_array($parameters)) {
error_log("Parameters must be an array\n");
return false;
}
foreach ($parameters as $key => &$val) {
// encoding to JSON array parameters, for example reply_markup
if (!is_numeric($val) && !is_string($val)) {
$val = json_encode($val);
}
}
$urlpath = API_URL.$method.'?'.http_build_query($parameters);
$handle = curl_init($urlpath);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
}
и это назвать
function processMessage($message) {
// process incoming message
$message_id = $message['message_id'];
$chat_id = $message['chat']['id'];
$img = curl_file_create('test.png','image/png');
if (isset($message['text'])) {
// incoming text message
$text = $message['text'];
if (strpos($text, "/start") === 0) {
apiRequestJson("sendMessage", array('chat_id' => $chat_id, "text" => 'Hello', 'reply_markup' => array(
'keyboard' => array(array('Hello', 'Hi','Bye')),
'one_time_keyboard' => true,
'resize_keyboard' => true)));
} else if ($text === "Hello" || $text === "Hi") {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'Nice to meet you'));
} else if ($text === "Bye") {
apiRequestImage("sendPhoto", array('chat_id' => $chat_id, 'photo' => '@'.$img));
}else if (strpos($text, "/stop") === 0) {
// stop now
} else {
apiRequestWebhook("sendMessage", array('chat_id' => $chat_id, "reply_to_message_id" => $message_id, "text" => 'Cool'));
}
} else {
apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'I understand only text messages'));
}
}
и называть все
if (isset($update["message"])) {
processMessage($update["message"]);
}
Текстовый бег, но фото №. Вы можете мне помочь?
Остальной код: http://pastebin.com/BKPxe2KC