M
M
Manuchehr Jalolov2016-09-01 16:19:15
PHP
Manuchehr Jalolov, 2016-09-01 16:19:15

How to correctly apply InlineKeyboardButton in PHP?

<?php
$access_token = '***токен***';
$api = 'https://api.telegram.org/bot' . $access_token; 
$output = json_decode(file_get_contents('php://input'), TRUE);
$chat_id = $output['message']['chat']['id'];
$first_name = $output['message']['chat']['first_name'];
$last_name = $output['message']['chat']['last_name'];
$message = $output['message']['text'];
switch($message) {
  case '/mail':
  $btn = new InlineKeyboardButton([
        'text' => 'Web-Site',
        'url' => 'http://lostov.net16.net'
    ]);
    $info_text = 'Хей ' . ' ' . $first_name . ' ' . $last_name . ', Привет если есть вопросы то вам сюда:
  ' . $btn;
    sendMessage($chat_id, $info_text);
  break;
  case '/dev':
    $dev_text = 'Bot:
  PHP: 5.7
  Ver: 1.0.0';
    sendMessage($chat_id, $dev_text);
  break;
   default:
    break;
}
function sendMessage($chat_id, $message) {
  file_get_contents($GLOBALS['api'] . '/sendMessage?chat_id=' . $chat_id . '&text=' . urlencode($message));
}
?>

here is the code but here only /dev works and the other part /mail is not displayed when i remove $btn from the code then it works how to use the buttons then?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nllm, 2016-09-01
@kinglostov

Code pulled out from somewhere
An InlineKeyboardButton is created, but it is not described / connected anywhere.
Is this all code?

M
Manuchehr Jalolov, 2016-09-01
@kinglostov

but it is not described/not connected anywhere.

how to do it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question