Reputation: 71
I made simple php bot for telegram which reply to me with a message. Code:
<?php
set_time_limit(0);
function SendMessage($message){
global $website, $chatId;
file_get_contents($website."/sendmessage?chat_id=".$chatId."&text=".$message);
}
$botToken = "my token";
$website = "https://api.telegram.org/bot".$botToken;
$content = file_get_contents("php://input");
$update = json_decode($content, TRUE);
$message = $update["message"];
$chatId = $message["chat"]["id"];
$text = $message["text"];
if ($text == "/start") {
SendMessage("welcome, it's nice to meet you");
} else {
SendMessage("сори");
}
And everything was alright, but at some point my bot stopped working. I started debug it by deleting everything that works. And i found interesting result.
images of results to make it clear
Please explain to me how it is possible. And how to solve it.
UPDATE. My script is encoded in UTF-8
Upvotes: 3
Views: 3636
Reputation: 71
Thank you for your advices. I solved it by making proper URL-encoding. I just by added urlencode function:
function SendMessage($message){
global $website, $chatId;
$message = urlencode($message);
file_get_contents($website."/sendmessage?chat_id=".$chatId."&text=".$message);
}
Upvotes: 4