简体   繁体   中英

Telegram bot Referal with Php using the /start command

I am trying to get points allocated to ma user based on the number of referrals, using the telegram bot by passing a payload to the /start command from where i can track it and know who has been referring people to the bot

i have tried following the documentation process and was able to set the command but i didn't see a way of getting the payload

  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);

                                    }

There is no output for the payload when i try to access it i have tried google but i can't find a way to fetch the payload using php. Any help would be appreciated

https://core.telegram.org/bots#deep-linking

You can receive the payload in a normal text message that starts with "/start"

$text = '/start PAYLOAD';
if(stripos($text, '/start ') === 0)
{
    $payload = str_replace('/start ', '', $text);
}

Telegram sends Payload inside the message content to your bot

$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 = "";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM