Quantum state heralding using photonic integrated circuits with free electrons