Multi-purpose BLF key

I’m setting up a small system using Yealink T26 phones and a SIP doorphone. Latest FreePBX/Asterisk (2.11.02/11.3)

I’d like to have a BLF button on each phone which serves a number of purposes, dependent on the state of the doorphone and the specific extension:

  1. Pressing the button when the extension isn’t busy dials the doorphone
  2. Pressing the button when the doorphone is calling (its assigned ring group) answers the call, regardless of whether the extension is in the ring group
  3. Pressing the button while there is a call in progress between the specific extension and the doorphone sends a code to the doorphone (to answer the door)

I can see how to set up three separate BLF keys to achieve what I want, but not how to set up the conditional logic from within FreePbx - is this possible? Or do I need to dig into the Asterisk side of things?