Answer the question
In order to leave comments, you need to log in
How to send a sequence of messages in strict order using batch?
Hello!
I am writing a small chat bot, there is a need to send a sequence of messages.
Send by method
$fb = new \Facebook\Facebook([ данные подключения ]);
$batch = [];
foreach ($messages as $msg) { // messages - уже валидное сообщение для фейсбука
$batch[] = $fb->request('POST', '/me/messages', $msg);
}
$fb->sendBatchRequest($batch);
$fb = new \Facebook\Facebook([ данные подключения ]);
$batch = [];
$i = 0;
foreach ($messages as $msg) { // messages - уже валидное сообщение для фейсбука
if($i > 0)
$msg['message']['text'] = "{result=p_$i:$.*}" . $msg['text'];
$batch['p_' . $i++] = $fb->request('POST', '/me/messages', $msg);
}
$fb->sendBatchRequest($batch);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question