You can take a look at these messaging integration samples for your scenario. In particular, out of these, "Execute logic based on contract state doc" and "Execute logic based on events doc" seem to be what you might be looking for.
Let us know if it helps.
Thanks,
Sana