MiL*_*TNT 0 php telegram telegram-bot
我已经把我的网络挂接,这让我更新,但我不知道如何发送InlineQueryResult与php
我想发送这样的文字:
aaaaaaaaaaabbbbbbbbbcccccc
Run Code Online (Sandbox Code Playgroud)
我怎么能用php curl发送它?这就是我目前的尝试:
$token = 'bot###';
$chat_id = '###';
$keyboardl = ['inline_keyboard' => [[['text' => "one", 'callback_data' => "1"],['text' => "two", 'callback_data' => "2"]]]];
$data = array("chat_id" => $chat_id,"results" => "??????","reply_markup" => $keyboardl);
$data_string = json_encode($data);
$ch = curl_init('https://api.telegram.org/'.$token.'/answerinlinequery');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
echo $result;
}
Run Code Online (Sandbox Code Playgroud)
我不知道我必须使用哪个InlineQueryResult才能发送文本.
要使用InlineQuery发送文本,您需要使用InlineQueryResultArticle (doc),因此将类型设置为article.
您无需设置,chat_id因为数据会自动在当前活动聊天中发送.它通过与您收到的inline_query_id相对应来识别.idInlineQuery
$results = array();
$entry = array(
"type" => "article",
"id" => "1",
"title" => "Title",
"description" => "Description",
"input_message_content" => array("message_text" => "Text to be sent")
);
array_push($results, $entry);
$post = array(
"inline_query_id" => $queryId,
"results" => json_encode($results)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.telegram.org/bot" . $token . "/answerInlineQuery");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$content = curl_exec ($ch);
curl_close ($ch);
Run Code Online (Sandbox Code Playgroud)