0 votes
22 views

I get a negative response from the file_get_contents as follows

Telegram Bot PHP: Warning: file_get_contents failed to open stream: 400 Bad Request

Code in Context

ini_set("error_reporting", E_ALL);

$botToken = "249706675:AAGGJtFStHf6zbuQfbAClcGzzlFz75xqFKA";
$website = "https://api.telegram.org/bot".$botToken;

$update = file_get_contents("php://input");
$updateArray = json_decode($update, TRUE);

$chatId = $updateArray["result"][0]["message"]["chat"]["id"];
$message = $updateArray["message"]["text"];

switch($message) {  
    case "/hello":
        sendMessage($chatId, "Hello!");
        break;
    case "/wtf":
        sendMessage($chatId, "I'm personal bot of @TCGroup!");
        break;
    default:
        sendMessage($chatId, "Default");    
}

function sendMessage($chatId, $message) {   
    $url = $GLOBALS["website"]."/sendmessage?chat_id=".$chatId."&text=".urlencode($message);
    file_get_contents($url);    
}

Source Author: Rin Ellei

by (1.4k points)   | 22 views

1 Answer

0 votes

Try camelCasing your sendMessage in the url. And use cURL extension instead of file_get_contents, as it's more efficent.

Credit to: Pato05

by (2.2k points)  

Related questions

+2 votes
0 answers
+3 votes
1 answer
asked Apr 12, 2020 by athar (3.2k points) | 122 views
0 votes
22 answers
asked May 13 by admin (2.2k points) | 219 views
+1 vote
1 answer
asked Oct 4, 2020 by toheed (1.4k points) | 104 views
+1 vote
1 answer
+2 votes
0 answers
asked Jun 20, 2020 by athar (3.2k points) | 46 views
Welcome to Givemeans.net here you can ask questions and get the answers from other members of the community.
143 questions
123 answers
43 comments
159 users