2016-06-13 12 views
1

私はphpでテレグラム用のインラインボットを作成しようとしています。私はBotFatherとステップを踏んだ。私は、ボットを作成し、トークンを取得し、setinlineを設定し、プレースホルダメッセージを設定しました。私はwebhookを設定し、それが動作しています。しかし、メッセージにボットをタイプすると何も得られず、メッセージを送信すれば何も起こりません。 Webhookは機能しています。私は通常のメッセージで試してみました。テレグラムインラインボットには何も表示されません

これは私のコードですが、しばらくして私はあきらめてブログから手に入れ、少し編集しました。

$content = file_get_contents("php://input"); 
$update = json_decode($content, true); 

$chatID = $update["message"]["chat"]["id"]; 
//sendMessage(print_r($update,true), $chatID); 

if (isset($update["inline_query"])) { 
    $inlineQuery = $update["inline_query"]; 
    $queryId = $inlineQuery["id"]; 
    $queryText = $inlineQuery["query"]; 

if (isset($queryText) && $queryText !== "") { 
    apiRequestJson("answerInlineQuery", [ 
    "inline_query_id" => $queryId, 
    "results" => ($queryText), 
    "cache_time" => 86400, 
    ]); 
} 
else { 
     apiRequestJson("answerInlineQuery", [ 
     "inline_query_id" => $queryId, 
     "results" => [ 
      [ 
      "type" => "article", 
      "id" => "0", 
      "title" => "TEST", 
      "message_text" => "TEST", 
      ], 
     ] 
     ]); 
    } 
    } 

ボットにはまだ何も表示されません。 私はちょうどステップをスキップしたと思います。

+0

BotのAPIはどのような応答をしますか? – ihoru

+0

@ihoru nothing。私には何も与えません。 –

答えて

2

結果にはinput_message_contentの内部にmessage_textというキーが必要です。
結果は次のようになります。

$results = array(
    array(
     "type" => "article", 
     "id" => "1", 
     "title" => "Title", 
     "description" => "Description", 
     "input_message_content" => array(
      "message_text" => "<code>Message 1</code>", 
      "parse_mode" => "HTML" 
     ) 
    ) 
); 

$postData = array(
    "inline_query_id" => $inlineQuery["id"], 
    "results" => json_encode($results), 
    "cache_time" => 0 
); 
+0

m8に感謝しています。インラインでこれがうまくいきました。しかし、私は 'parse_mod'タグも送る必要があります。 ' 'input_message_content" =>配列(["message_text" => "メッセージテキスト"、 "parse_mode" => "HTML"]) ' 何も動作しませんもう一度... –

+0

'input_message_content'で余分な' [] 'を取り除くだけでよいでしょう。私は実際の例で私の答えを編集しました。 – Maak

関連する問題