How to automatically shrink a SQL Server transaction log only if it exceeds a certain limit (e.g. 20 GB)
Our database is set to FULL recovery mode and we take a database
  backup and a log backup every night.


I think you need to take log backups much more often than every night. Try every hour to see if that keeps your file growth in check. If not you may need to run them more frequently. 

You could also deploy an SQL Agent Alert that triggers when the log percent used reaches a certain threshold. This alert could send an email or fire an agent job that runs a log backup job.

Also I wouldn't ever recommend automatically shrinking files.