I could write this. But there is one issue. There as far as I can tell no way to send control clicks to a client that is not in the forground. You can send hotkeys but not mouse clicks. I have tired many times and many ways to do this.
So the only other way is use a pixel search or click at the spot of where the invite would be at and accpet it that way.
If you want me to do that I can. But you might not like that for speed.