First take a look at:
There's MANY ways to tell freeswitch what to do.
Let's take a step back, OK?
The simplest is to create a dialplan. With all the condition, regex, time based routing, etc, you can do quite a lot in just a static dialplan. Depending on what you need to do, you may never need to go beyond this. You can even do database calls from the static dialplan with mod_odbc_query (from git freeswitch-contrib).
If you need a bit more flexiblity, you can call a lua script at any point. Lua seems to be the most embeddable language with very low overhead and high community support.
If you need more, you can use XML_curl -- that's from a web server in any language -- that serves up XML specific for each call -- it gets all the variables about the call at that time. (You have to ensure your web server is working!)
Alternatively, there's ESL - freeswitch fires off events for many things you can watch and trigger something. Or, ESL outbound.
If you know C, you can write this logic in a module that is loaded directly with freeswitch.
You can look up all those in the wiki, but I hope this helps explain the bigger picture.