Check out the documentation for AMI. Use your language of choice to do some sockets interfacing with Asterisk server. Do either the basic authentication or MD5 challenge to start a session. Once you have a session open you can send commands like “Action: CoreShowChannels”
action: coreshowchannels
Response: Success
EventList: start
Message: Channels will follow
From this output that you receive back you can parse out the “Channel” values. To get the channel id for the call you want, you’d also need to parse out caller information. For example if I want to do something to the channel ext 150 is using, I would parse out callerIdnum or some other value as well from this list, and check to make sure it was 150.