Home assistant ldap query

I wrote the following automation media_player.ha_speaker is a mpd player that plays the steam of a other mpd player if it stopped playing.
So i have music. Message music with out messing with the mpd playlist.

alias: inkomende beller
description: ""
trigger:
  - platform: webhook
    webhook_id: sip_call_webhook_id
condition: []
action:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.ha_speaker
      message: >-
        Inkomende beller {{trigger.json.caller |regex_findall_index("\"(.*)\"") 
        }}
      language: nl
mode: single

Now i want a ldap query on the phone number and get a name back a name back from my ldap server.

I have some python experience and i think it is possible but i dont know where to begin.

Can i create a custom string function like {{trigger.json.caller |regex_findall_index(“someotherregex”)
| ldap_query(“savedQuery”) }}

Where savedQuery referenses to a stored ldap query with all other ldap settings?