簡體   English   中英

我如何在php中的單個消息電報bot中發送照片,標題和2個嵌入式按鈕

[英]how can i send photo, caption and 2 inline button in single message telegram bot in php

這就是我想要的

或像這樣https://t.me/RoobaiOfficaial/2032

我是編碼新手,無法讓bot工作,將不勝感激

編碼我如何上傳圖片並設置聊天ID

 <form method="post" enctype="multipart/form-data"> <input type="text" name="chat_id" value="" /> <input type="url" name="photo" value="" /> <input type="submit" name="send" action="<?php echo $website.'/sendPhoto'?>"/> </form> 

我添加消息並創建1個包含URL的嵌入式按鈕

 <?php $msg= urlencode("test message"); $token="bot_token"; $chatId="chat_id"; $response=($_POST['photo']); $response=$response.urldecode($msg); $keyboard = [ 'inline_keyboard' => [ [ ['text' => 'Buy Now', 'url' => 'https://i.stack.imgur.com/vLHu9.png'] ] ] ]; $encodedKeyboard = json_encode($keyboard); $parameters = array( 'chat_id' => $chatId, 'text' => $response, 'reply_markup' => $encodedKeyboard ); send('sendMessage', $parameters); // function description Below function send($method, $data) { $url = "https://api.telegram.org/".$token. "/" . $method; if (!$curld = curl_init()) { exit; } curl_setopt($curld, CURLOPT_POST, true); curl_setopt($curld, CURLOPT_POSTFIELDS, $data); curl_setopt($curld, CURLOPT_URL, $url); curl_setopt($curld, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($curld); curl_close($curld); return $output; } 

我正在得到這種類型的響應,但我需要它而無需鏈接響應

嘗試更新以下兩行:

send('sendMessage', $parameters); // function description Below

function send($method, $data)

包括$ token

send('sendMessage', $parameters, $token); // function description Below

function send($method, $data, $token)

該鏈接說明了為什么它可能無法按您期望的方式工作。 http://php.net/manual/zh/language.variables.scope.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM