[英]How can i get UserID from Telegram Bot
我想从用户与我的机器人聊天时从用户那里获取userid和chatid,因为我需要该ID才能将查询发送到Sql并注册该用户,但我不知道如何获取userid :(
$data = file_get_contents("php://input");
$update = json_decode($data,true);
$message = $update["message"];
$text = $message["text"];
$cid = $update["message"]["from"]["id"];
$from = $message["from"];
$username = $from["username"];
$nome = $from["first_name"];
$cognome = $form["last_name"];
$cbid = $update["callback_query"]["from"]["id"];
$cbdata = $update["callback_query"]["data"];
$chat_id = $message->chat->id;
$user_id = $message->from->id;
$user = $message->from->username;
并且此代码用于将UserID和ChatID发送到聊天室
if($text == "Datos"){
$but = array(array(array("text" => "UserID", "callback_data" => "Info"),),);
inlineKeyboard($but, $cid, "Clicca uno di questi due pulsanti \nper andare su google o su facebook!");
}
if(callback($update)){
if($cbdata == "Info"){
send($cbid, "estos son los datos: $probando $user $userid $probando2");
}
}
这是我不太确定如何获取userid或chat_id的方式,但是现在我需要将该信息用于代码的另一部分,但是当我再次调用$welcomemessage
,userid的值为空。 我该怎么办?
$userid = $message["from"]["id"];
$welcomemessage = "Este es tu id: $userid";
if ($text == '/hope') {
$welcomemessage;
// Send the generated message back to the Telegram user
file_get_contents($website."/sendmessage?chat_id=".$chatId."&text=".$welcomemessage);
}
这是获取用户ID的最后代码,我希望我能帮助到这个人。
$userid = $message["from"]["id"];
if ($text == '/hope') {
$userid;
file_get_contents($website."/sendmessage?chat_id=".$chatId.);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.