L
L
lightmanLP2018-12-15 16:01:40
PHP
lightmanLP, 2018-12-15 16:01:40

Why are multiple messages being sent instead of just one?

I wrote the code for the bot in VK. He must respond to the test message hey 1 time. Instead, after a while, he writes hey a few more times. Help me please. The bot works through the Callback API.

<?php<b></b>
if (!isset($_REQUEST)) { 
return;}

$searchres = '';

$confirmation_token = ''; 
$token = '';
$group = '';
$random = 24;

$loadres = ''; 
function bsave ($btype,$bname,$bset,$baseid,$bspecial) { 
 global $base; 
 if ($btype == 'g') { 
  if ($baseid == ''){ 
$base['global'][$bname] = $bset;} 
  else { 
$base['global'][$baseid][$bname] = $bset;}} 
 if ($btype == 'l') { 
  if ($bspecial == '') { 
$base['local'][$baseid][$bname] = $bset;} 
  else { 
$base['local'][$baseid][$bspecial][$bname] = $bset;}} 
 if ($btype == 's') { 
  if ($bspecial == '') { 
$base['special'][$baseid][$bname] = $bset;} 
  else { 
$base['special'][$baseid][$bspecial][$bname] = $bset;}}} 
 
function bload ($btype,$bname,$baseid,$bspecial) { 
 global $base, $loadres; 
 if ($btype == 'g') { 
  if ($baseid == '') { 
   $loadres = $base['global'][$bname];} 
  else { 
   $loadres = $base['global'][$baseid][$bname];}} 
 if ($btype == 'l') { 
  if ($bspecial == '') { 
   $loadres = $base['local']['id'.$baseid][$bname];} 
  else { 
   $loadres = $base['local']['id'.$baseid][$bspecial][$bname];}} 
 if ($btype == 's') { 
  if ($bspecial == '') { 
   $loadres = $base['special'][$baseid][$bname];} 
  else { 
   $loadres = $base['special'][$baseid][$bspecial][$bname];}}} 

$sendres = '';
function Send ($text,$idsend) {
global $sendres,$token,$group;
$sendres = file_get_contents('https://api.vk.com/method/messages.send?peer_id='.$idsend.'&message='.urlencode($text).'&access_token='.$token.'&group_id='.$group.'&v=5.92&random_id='.$random);}

$resname = '';
function Names($NamedId, $N1, $N2, $Nform) {
global $token,$group,$resname;
$Nameref = json_decode(file_get_contents('https://api.vk.com/method/User.get?access_token='.$token.'&group_id='.$group.'&v=5.92&user_ids='.$NamedId.'&name_case='.$Nform));
if ($N1 == 1) {$resname = $Nameref['response'][0]['first_name'];}
if ($N2 == 1) {if ($resname != '') {$resname = $resname.' ';} $resname = $resname.$Nameref['response'][0]['last_name'];}}

$data = json_decode(file_get_contents('php://input')); 
switch ($data->type) { 
case 'confirmation': 
echo $confirmation_token; 
break; 

case 'message_new': 
$id = $data->object->peer_id;
$mes = $data->object->text;
$Aid = $data->object->from_id;


$basecount = 0;
while ($basecount <= count($base['local'])) /*tester func*/ { 
 $searchres = $searchres.key($base['local']);
 $basecount = $basecount + 1;
 next($base['local']);} 
if (strpos($searchres,$Aid) == False) {  
 array_push ($base['local'],'id'.$Aid);
 $ATid = 'id'.$Aid;
 $base['local'][$ATid] = ['party'=>['invite'=>0,'request','invited'=>0]];}
 
if (strpos($mes, '/b') == 0) {
$a = substr($mes, 3);
Send ('',$id);}

if ($mes == 'test') {
Send ("hey",$id);	
}
echo 'ok';
break;}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tempick, 2018-12-15
@tempick

It most likely returns something other than "ok" - try, for example, writing the result sent via the Callback API to a file and see what it writes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question