The callback APIs are a really powerful way to get information about
your calls and further secure them. This is the final step before you
allow calls to be connected. If you have followed our other tutorials,
you are likely familiar with the different states of a call:
progressing, established, and ended. With the callback API, you get the
same events, enabling you to make decisions just before you connect the
call to the server.

If you have configured your callback URL, you must to respond to
callbacks for the call to be connected. The Sinch service expects a
response containing Svaml to make it easier to work with. In your C#
project, create a couple of classes to help out:

Svaml contains instructions and actions. For example, an instruction is
playing a sound file to a user, and an action is connecting to a call.
For a complete list of instructions and actions, see the
documentation.

Next, create this method in your callbackcontroller:

[HttpPost]publicasyncTask<Svaml>Post(HttpRequestMessagemessage){}

This method is called for all callback events; they all look slightly
different, but they all contain a JSON request an event.

This event is triggered right before you get the in progress event in a
call client. I think this is the most interesting callback because you
can change the call that is about to happen. Here, you can decide if a
user has enough credit to make a call, or if the phone number is one you
want to connect to, and then make decisions based on that. In case you
are using Sinch to make click-to-call buttons, you may want to check the
dialed phone number against a database. That’s exactly what we are going
to do in this tutorial. I don’t want to connect any phone calls unless
you are trying to call me. In the post method, add:

publicasyncTask<Svaml>Post(HttpRequestMessagemessage){//read the responseStringbody=awaitmessage.Content.ReadAsStringAsync();varjson=JsonConvert.DeserializeObject<JObject>(body);//create a new respone objectvarsvaml=newSvaml();if(json["event"].ToString()=="ice"){//only calls to my personal phone is allowed with this appif(json["to"].ToString()=="+15612600684"){svaml.Action=newSimpleICEAction(){Name="ConnectPSTN",callback=true,maxDuration=600};}else{//else hangupsvaml.Action=newAction{Name="hangup"};}}}