如何使用电报内联机器人发送消息
How to send message with telegram inline bots
我已经设置了我的 webhook,它会给我更新,但我不知道如何用 php
发送 InlineQueryResult
我想发送这样的短信:
aaaaaaaaaaabbbbbbbbbcccccc
如何使用 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;
}
我不知道我必须使用哪个 InlineQueryResult 才能发送文本。
要使用 InlineQuery 发送文本,您需要使用 InlineQueryResultArticle
(doc),因此将类型设置为 article
。
您无需设置 chat_id
,因为数据会在当前活动的聊天中自动发送。它通过 inline_query_id
识别,它对应于您在 InlineQuery
.
中收到的 id
$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);
我已经设置了我的 webhook,它会给我更新,但我不知道如何用 php
InlineQueryResult
我想发送这样的短信:
aaaaaaaaaaabbbbbbbbbcccccc
如何使用 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;
}
我不知道我必须使用哪个 InlineQueryResult 才能发送文本。
要使用 InlineQuery 发送文本,您需要使用 InlineQueryResultArticle
(doc),因此将类型设置为 article
。
您无需设置 chat_id
,因为数据会在当前活动的聊天中自动发送。它通过 inline_query_id
识别,它对应于您在 InlineQuery
.
id
$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);