I am making telegram bot on php. Webhook is set. Bot is not reacting on command “/start” but it is working good with inline_keyboard.
Webhook file:
//Piece of code that works good:
$update = json_decode(file_get_contents('php://input'), TRUE);
$user_chatId = $update['callback_query']['message']['chat']['id'];
$user_first_name = $update['callback_query']['message']['chat']['first_name'];
$user_last_name = $update['callback_query']['message']['chat']['last_name'];
$date = $update['callback_query']['message']['date'];
$str = $update['callback_query']['message']['text'];
$messageText = $update["message"]["text"];
if (isset($update['callback_query'])) {
if ($update['callback_query']['data'] == 'Done') {
// Text for a message
$params=[
'chat_id'=>$user_chatId,
'text'=>'Thank you!',
];
// Sending message on telegram
$ch = curl_init($website . '/sendMessage');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
if ($result === FALSE) {
echo 'An error has occured: ' . curl_error($ch) . PHP_EOL;
}
else {
echo $result;
}
curl_close($ch);
}
//Piece of code that doesn't work:
if($messageText == "/start") {
$conn_new_user = $dbh->prepare('INSERT INTO chat_ids (chat_id) VALUES (:user_chatId)');
$conn_new_user->bindParam(":user_chatId", $user_chatId);
$conn_new_user->execute();
}
If I get rid of statement if: “if($messageText == “/start”)” and leave just database insert than everything works and I get data to database when only inline_button is pressed but I still get nothing on “/start”
Is there any way to fix that?
$messageText is not empty. Inside of “if($messageText == “/start”)” I was putting a code that was inserting the $messageText to another file, everything was working fine. The database statement is right. It works just fine when user presses button on inline_keyboard