How to detect incoming caller ID using AMI


I would like to build into a custom program the ability to detect an incoming call. Firstly I am not sure how can it work. Does my program need to poll or is there another way? I am able to trigger calls but with this I would need some guidance, any help will be appreciated