Closed Albert2106 closed 3 years ago
Как-то так.
$buttons = [
['text' => 'Send contact', 'request_contact' => true],
];
$replyMarkup = new ReplyKeyboardMarkup($buttons, true, false, true);
Не получаеться вот код:
$bot->command("getcontact", function ($message) use ($bot) {
$buttons =
[
['text' => 'Send contact', 'request_contact' => true]
];
$replyMarkup = new \TelegramBot\Api\Types\ReplyKeyboardMarkup($buttons, true, false, true);
$bot->sendContact($message->getChat()->getId(), "Отправьте номер",$replyMarkup);
});
Выходят ошибки: Fatal error: Uncaught Error: Object of class TelegramBot\Api\Types\ReplyKeyboardMarkup could not be converted to string in \vendor\telegram-bot\api\src\BotApi.php:258
$bot->sendMessage($message->getChat()->getId(), "Отправьте номер", null, false, null, $keyboard);
@L1keStyle проблема решена?
Спасибо
Не знаю как раньше было, но сейчас Телеграм выдает ошибку: Bad Request: field "keyboard" of the ReplyKeyboardMarkup must be an Array of Arrays. Массив
$buttons =
[
['text' => 'Send contact', 'request_contact' => true]
];
Преобразуется в массив объектов, а не в массив массивов как требует API
Кнопку запроса телефона юзера у меня так получилось сделать:
$bot = new \TelegramBot\Api\Client($token);
// кнопка
$bot->command('phone', function ($message) use ($bot) {
$buttons =
[[
['text' => 'Отправить номер', 'request_contact' => true]
]];
$replyMarkup = new \TelegramBot\Api\Types\ReplyKeyboardMarkup($buttons, true, false, true);
$bot->sendMessage($message->getChat()->getId(), 'Мы запомнили Ваш номер', null, false, null, $replyMarkup);
});
// получение номера
$bot->on(function (\TelegramBot\Api\Types\Update $update) use ($bot) {
$message = $update->getMessage();
if ($message->getContact() != null) {
$bot->sendMessage($message->getChat()->getId(), 'Your phone: ' . $message->getContact()->getPhoneNumber());
} else {
$bot->sendMessage($message->getChat()->getId(), 'Your message: ' . $message->getText());
}
}, function () {
return true;
});
I fixed your problem, your $replyMarkup stay in position attribute reply message id!
$bot = new \TelegramBot\Api\Client($token);
// кнопка
$bot->command('phone', function ($message) use ($bot) {
$buttons =
[[
['text' => 'Отправить номер', 'request_contact' => true]
]];
$replyMarkup = new \TelegramBot\Api\Types\ReplyKeyboardMarkup($buttons, true, false, true);
$bot->sendMessage($message->getChat()->getId(), 'Мы запомнили Ваш номер', null, false, null, null, $replyMarkup);
});
// получение номера
$bot->on(function (\TelegramBot\Api\Types\Update $update) use ($bot) {
$message = $update->getMessage();
if ($message->getContact() != null) {
$bot->sendMessage($message->getChat()->getId(), 'Your phone: ' . $message->getContact()->getPhoneNumber());
} else {
$bot->sendMessage($message->getChat()->getId(), 'Your message: ' . $message->getText());
}
}, function () {
return true;
});
Как сделать кнопку sendContact? Можно пример?