Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.
Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin. Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegramda forward messagega reply qilib yozganda qanday qilib forward egasiga xabar yuboradi?

0 ovoz
206 marta ko‘rilgan
so‘radi 07 aprel E-soft (698 bal)
teglar o‘zgartirildi 04 may E-soft

Salom! Savolimni aniqlashtirsam. Hozir men adminga murojaat qiladigan bot yaratayotgan edim. Hozirgi kod user yuborgan xabarni adminga forward qiladi. Kod:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$token = "121408874:AAH9dlXGKXwFUh9b0pI1xqvok25Mlo"; // bot tokeni
define('API_KEY',$token); 

$admin = "71740489"; // admin IDsi
$bot_us = "ESoftAdmnUzBot"; // bot usernamesi @ siz

function bot($method,$datas=[]){
    $url = "https://api.telegram.org/bot".API_KEY."/".$method;
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$datas);
    $res = curl_exec($ch);
    if(curl_error($ch)){
        var_dump(curl_error($ch));
    }else{
        return json_decode($res);
    }
}

$update = json_decode(file_get_contents('php://input'));
$message = $update->message;
$message_id = $update->message->message_id;
$chat_id = $message->chat->id;
$text = $message->text;
$nick = $message->from->first_name;
$fnick = $message->from->last_name;
$user_id = $message->from->id;

if ($text == "/start" or $text == "/start@$bot_us"){
    bot('sendMessage',[
    'chat_id' => $chat_id,
    'text' => "*Salom* [$nick $fnick](tg://user?id=$user_id) botimizga xush kelibsiz!",
    'parse_mode'=>'markdown'
    ]);
}

if(isset($message) and $chat_id != $admin and $text!="/start"){
    bot('forwardMessage',[
    'chat_id'=>$admin,
    'from_chat_id'=>$chat_id,
    'message_id'=>$message_id
    ]);
}

Endi shu forward qilingan messagega admin reply qilib yozsa userga yuboradigan qilish kerak. Shunga yordam beraolasizlarmi? Javob uchun avvaldan rahmat!

izoh qoldirdi 04 may E-soft (698 bal)
Savolni soddalashtirsam men kodni yozib chiqdim kod quyidagicha bo'ldi:

<?php
//bot framework by @UzBestMaster

error_reporting(E_ALL);
ini_set('display_errors', 1);

$token = "1214408874:AAH9dlX7xGwbXwFUh9b01xqvok25Mlo"; // bot tokeni
define('API_KEY',$token);

$admin = "717404897"; // admin IDsi
$bot_us = "ESoftAdminUzBot"; // bot usernamesi @ siz

function bot($method,$datas=[]){
    $url = "https://api.telegram.org/bot".API_KEY."/".$method;
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$datas);
    $res = curl_exec($ch);
    if(curl_error($ch)){
        var_dump(curl_error($ch));
    }else{
        return json_decode($res);
    }
}

$update = json_decode(file_get_contents('php://input'));
$message = $update->message;
$message_id = $update->message->message_id;
$chat_id = $message->chat->id;
$text = $message->text;
$nick = $message->from->first_name;
$fnick = $message->from->last_name;
$user_id = $message->from->id;
$reply = $message->reply_to_message->text;
$forward = $message->reply_to_message->forward_from->id;

if ($text == "/start" or $text == "/start@$bot_us"){
    bot('sendMessage',[
    'chat_id' => $chat_id,
    'text' => "*Salom* [$nick $fnick](tg://user?id=$user_id) botimizga xush kelibsiz!",
    'parse_mode'=>'markdown'
    ]);
}

if(isset($message) and $chat_id != $admin and $text!="/start"){
    bot('forwardMessage',[
    'chat_id'=>$admin,
    'from_chat_id'=>$chat_id,
    'message_id'=>$message_id
    ]);
}

if(isset($reply)){
   bot('sendMessage',[
    'chat_id' => $forward,
    'text' => $text,
    'parse_mode'=>'markdown'
    ]);
}

Ammo bu yerda xatolik User profilining maxfiylik xavfsizlik qismida uztilgan xabarlarni o'chirib qo'ygan bo'lsa o'sh userga xabar bormayapti. Shuni qanday qilib to'g'irlasa bo'ladi?
izoh qoldirdi 05 may MrMuminov (232 bal)
Bu yerda xatolik bo'lmaydi. chunki user botga start bosgan demak xabar boradi. skrit qilingan profil bolsa ham

agar botni ochirib tashlagan bolsa(aynan block qilgan bolsa) shu holatda xabar bormaydi.

1 ta javob

+1 ovoz
javob berdi 10 aprel Akbarali (25 bal)

Жавоб агар пасдаги кодга тушунмасангиз  https://t.me/uzgeeksflood/73948 да тўлиқ код мавжуд

if ($sreply == 'Xabar matnini kiriting'){
    $option = $menu;
    $keyfd = buildKeyBoard($option, $onetime = false);
    $content = ['chat_id' => $chat_id, 'reply_markup' => $keyfd, 'text' => "*рџ“ЁXabaringiz bizga yetib keldiрџ“ќ*
    _рџ‘®Tez orada javob qaytaramizвњЌ_", 'parse_mode' => 'markdown'];
    xabarYubor($content);
    $option = [["javob#$chat_id"]];
    $keyfd = buildKeyBoard($option, $onetime = false);
    $content = ['chat_id' => $admin, 'reply_markup' => $keyfd, 'text' => "Yangi Xabar \n Kimdan: $ufname $uname \n Login: @$ulogin \n ID: $uid \n\n Matn: $text", 'parse_mode' => 'markdown'];
    xabarYubor($content);
}
$inreg = explode("#",$text);
$intype  = $inreg[0];
$us_id  = $inreg[1];
if ($intype == 'javob') {
   $keyfd = buildForceReply($selective=true);
    $content = ['chat_id' => $chat_id, 'reply_markup' => $keyfd, 'text' => "javob matnini kiriting#$us_id", 'parse_mode' => 'markdown'];
    xabarYubor($content);
}
$inreg = explode("#",$sreply);
$intype  = $inreg[0];
$us_id  = $inreg[1];
if ($intype == 'javob matnini kiriting'){
    $option = $menu;
    $keyfd = buildKeyBoard($option, $onetime = false);
    $content = ['chat_id' => $us_id, 'reply_markup' => $keyfd, 'text' => $text, 'parse_mode' => 'markdown'];
    xabarYubor($content);
    $option = $menu;
    $keyfd = buildKeyBoard($option, $onetime = false);
    $content = ['chat_id' => $admin, 'reply_markup' => $keyfd, 'text' => "Xabar yetkazildi", 'parse_mode' => 'markdown'];
    xabarYubor($content);
}

izoh qoldirdi 10 aprel E-soft (698 bal)
Men forward messagega reply qilib javob yozishni soʻrayapman. Id bilan javob berishni bilaman.
izoh qoldirdi 05 may MrMuminov (232 bal)
$user_id = $message->from->id;
$reply = $message->reply_to_message->text;
$forward = $message->reply_to_message->forward_from->id;
// Shu yerga qarang tepaga

if ($text == "/start" or $text == "/start@$bot_us"){
    bot('sendMessage',[

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...