insert('users', ['phone_number' => $testPhone, 'name' => 'Reactor', 'status' => 'active']); $origMsgId = '1001'; $db->insert('conversations', [ 'user_id' => $userId, 'message_id' => $origMsgId, 'direction' => 'incoming', 'message_type' => 'text', 'content' => 'Original msg', 'status' => 'received', 'created_at' => date('Y-m-d H:i:s') ]); $payload = [ 'object' => 'whatsapp_business_account', 'entry' => [ [ 'changes' => [ [ 'field' => 'conversations', 'value' => [ 'messaging_product' => 'whatsapp', 'metadata' => [ 'display_phone_number' => '16505551111', 'phone_number_id' => '123' ], 'contacts' => [ [ 'profile' => ['name' => 'reactor'], 'wa_id' => $testPhone ] ], 'conversations' => [ [ 'from' => $testPhone, 'id' => '2001', 'timestamp' => time(), 'type' => 'reaction', 'reaction' => ['message_id' => $origMsgId, 'emoji' => '👍'] ] ] ] ] ] ] ] ]; $r = $webhook->processPayload($payload); $conv = $db->fetch('SELECT * FROM conversations WHERE message_id = :mid', ['mid' => '2001']); if ($conv) { echo "Reaction saved: reaction_to_message_id={$conv['reaction_to_message_id']}, reaction_emoji={$conv['reaction_emoji']}\n"; } else { echo "Reaction not saved\n"; } // Cleanup reaction test $db->execute('DELETE FROM conversations WHERE message_id = :mid', ['mid' => '2001']); $db->execute('DELETE FROM conversations WHERE message_id = :mid', ['mid' => $origMsgId]); $db->execute('DELETE FROM users WHERE id = :id', ['id' => $userId]); // Test reply/context $testPhone2 = '573007777111'; $userId2 = $db->insert('users', ['phone_number' => $testPhone2, 'name' => 'Replier', 'status' => 'active']); $origMsgId2 = '1002'; $db->insert('conversations', [ 'user_id' => $userId2, 'message_id' => $origMsgId2, 'direction' => 'incoming', 'message_type' => 'text', 'content' => 'Original for reply', 'status' => 'received', 'created_at' => date('Y-m-d H:i:s') ]); $payload2 = [ 'object' => 'whatsapp_business_account', 'entry' => [ [ 'changes' => [ [ 'field' => 'conversations', 'value' => [ 'conversations' => [ [ 'from' => $testPhone2, 'id' => '2002', 'timestamp' => time(), 'type' => 'text', 'text' => ['body' => 'Reply message'], 'context' => ['id' => $origMsgId2] ] ] ] ] ] ] ] ]; $r2 = $webhook->processPayload($payload2); $conv2 = $db->fetch('SELECT * FROM conversations WHERE message_id = :mid', ['mid' => '2002']); if ($conv2) { echo "Reply saved: reply_to_message_id={$conv2['reply_to_message_id']}\n"; } else { echo "Reply not saved\n"; } // Cleanup reply test $db->execute('DELETE FROM conversations WHERE message_id = :mid', ['mid' => '2002']); $db->execute('DELETE FROM conversations WHERE message_id = :mid', ['mid' => $origMsgId2]); $db->execute('DELETE FROM users WHERE id = :id', ['id' => $userId2]); echo "Done\n";