This sounds like the kind of thing you could use Huginn for… I’m still picking up how to use it expediently but it does sound possible.
Update: I have since abandoned Huginn due to an incredible amount of instability when using it with an external Postgres instance. Can’t say I would recommend it unfortunately