Telegram Bot inline query - what array to make query?

I have a problem with a Telegram inline query answer in PHP. I'm using this code:

Class functions:

public function answerInlineQuery($inline_query_id, $results, $cache_time = null, $is_personal = false, $next_offset = null){
    $param = compact('inline_query_id', 'results', 'cache_time', 'is_personal', 'next_offset');
    return $this->sendRequest('answerInlineQuery', $param);
}

public function InlineQueryResultArticle($id, $title, $message_text, $parse_mode = null, $disable_web_page_preview = false, $url = null, $hide_url = false, $description = null, $thumb_url = null, $thumb_width = null, $thumb_height = null)
{
    $type = "article";
    $params = compact("type", "id", "title", "message_text", "parse_mode", "disable_web_page_preview", "url", "hide_url", "description", "thumb_url",
                      "thumb_width", "thumb_height");
    return json_encode($params);
}

private function sendRequest($method, $params)
{
    return json_decode(file_get_contents($this->baseURL . $method . '?' . http_build_query($params)), true);
}

bot.php file :

$t = new telegramBot("##########################");

$data = json_decode($_REQUEST['salam'], true);

//$_REQUEST['salam'] => This method is not the problem and returns JSON that is receive from the telegram server


$id1 = $t->InlineQueryResultArticle($data['inline_query']['id'], "onvan1111", "TeXte Message1");
$id2 = $t->InlineQueryResultArticle($data['inline_query']['id'], "onvan2222", "TeXte Message2", null, false, "http://icons.iconarchive.com/icons/custom-icon-design/flatastic-6/512/Horizontal-type-mask-Tool-icon.png", false, "short");
$id3 = $t->InlineQueryResultArticle($data['inline_query']['id'], "onvan3333", "TeXte Message3");


$res = array($id1,$id2,$id3);

$t->answerInlineQuery($data['inline_query']['id'], $res);

When I send inline query in my robot I have this log from PHP:

<b>Warning</b>:  file_get_contents(https://api.telegram.org/bot#################/answerInlineQuery?inline_query_id=297302915958357271&amp;results=%5B%7B%22type%22%3A%22article%22%2C%22id%22%3A%22297302915958357271%2F0%22%2C%22title%22%3A%22onvan1111%22%2C%22message_text%22%3A%22TeXte+Message1%22%2C%22parse_mode%22%3Anull%2C%22disable_web_page_preview%22%3Afalse%2C%22url%22%3Anull%2C%22hide_url%22%3Afalse%2C%22description%22%3Anull%2C%22thumb_url%22%3Anull%2C%22thumb_width%22%3Anull%2C%22thumb_height%22%3Anull%7D%5D&amp;is_personal=0): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

Where does my code have the problem?

Answers


i found the code problam : result of InlineQueryResultArticle function most not be json and $res at this line :

$t->answerInlineQuery($data['inline_query']['id'], $res);

most be json encode :)


Need Your Help

How to check if a file is in Git repository when visiting from emacs?

git emacs hook

I would be most happy with some kind of emacs hook that would be activated when a file that is under git repository is visited. But other solutions are welcome as well.