0

i can't figure out how can i count inlineKeyboardButton clicks the same as @ChannelButtonsBot or @likebot. How can i make the bot increase by 1 on first click and decrease by 1 on the second click. and of course it needs to know when a new user clicks so it can go above 1. basically the same as the bots i have mentioned.

This is the code i have written. This is specific for Channels:

$ctext = $update->channel_post->text;
$channel_mid = $channel->message_id;
$channel_chatid = $update->channel_post->chat->id;
$data = $update->callback_query->data;
$chat_id2 = $update->callback_query->message->chat->id;
$message_idc = $update->callback_query->message->message_id;


bot(editMessageText,[
    'chat_id' => $channel_chatid,
    'message_id'=>$channel_mid,
    'text' => $ctext,
        'reply_markup'=>json_encode([
         'inline_keyboard'=>[
        [['text'=>'Clicks'. $number,'callback_data'=>"clicks"]],
        ]
])
    ]);

if($data == "clicks"){
$number++;
 bot(editMessageReplyMarkup,[
    'chat_id' => $chat_id2,
    'message_id'=>$message_idc,
        'reply_markup'=>json_encode([
         'inline_keyboard'=>[
        [['text'=>'Clicks'. $number,'callback_data'=>"clicks"]],
        ]
])

        ]);
}

1 Answers1

0

You need to keep track of

  1. Message ID
  2. Number of button clicks
  3. Users who clicked in a database or JSON file.

If a user clicks the button, check whether his Telegram ID exists in the list of users. If it exists, then remove it and subtract 1 from number of clicks. If it doesn't exist, then add it to the list of users and add 1 to number of clicks.

Brian B
  • 80
  • 1
  • 9