[英]Telegram bot Referal with Php using the /start command
我正在嘗試根據推薦數量分配給 ma 用戶,使用電報機器人通過將有效負載傳遞給 /start 命令,從那里我可以跟蹤它並知道誰將人們推薦給機器人
我嘗試遵循文檔流程並能夠設置命令,但我沒有看到獲取有效負載的方法
ini_set('error_reporting', E_ALL);
$token="870645666:AAHrjEF006uje1SpG0dFJRFnmfNIZHbGxdM";
$website ="https://api.telegram.org/bot".$token;
$update =file_get_contents("php://input");
$update =json_decode($update, TRUE);
$chatid =$update["message"]["chat"]["id"];
$message =$update["message"]["text"];
$refid=$update["message"]["text"]["payload"];
$ref=mysqli_fetch_assoc(mysqli_query($connect, "SELECT * FROM
bot where refid='$refid'"));
sendMessage($chatid, "You were referred by".$ref['name'];
function sendMessage($chatid, $message){
$url =$website."/sendMessage?
chat_id=".$chatid."&text=".urldecode($message);
file_get_contents($url);
}
當我嘗試訪問有效負載時沒有輸出我嘗試過谷歌,但我找不到使用 php 獲取有效負載的方法。 任何幫助,將不勝感激
https://core.telegram.org/bots#deep-linking
您可以在以“/start”開頭的普通文本消息中接收有效負載
$text = '/start PAYLOAD';
if(stripos($text, '/start ') === 0)
{
$payload = str_replace('/start ', '', $text);
}
Telegram 將消息內容中的 Payload 發送到您的機器人
$message =$update["message"]["text"];
// extract payload from message text
$refid=substr($message, strlen('/start'));
// check is it really first message to start the bot
if($update["message"]["message_id"] != 1 || stripos($message, "/start ") != 0){
// $refid = "";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.