I think you can replace both AcceptGroup() and StaticPopup_Hide("PARTY_INVITE") with

/click StaticPopup1Button1

Not tested this, so I don't know if it works, but basically it clicks the first button on a dialog, so it should work for other dialogs.