3cx-web-API icon indicating copy to clipboard operation
3cx-web-API copied to clipboard

Missed-call Alert API

Open wasimfirmz opened this issue 10 months ago • 0 comments

I'm trying to setup a missed call alert webhook in the makecall.cs file.

I'm trying with this code. but it is not working, can you please suggest me the right approach for this?

    private static void OnCallStateChanged(object sender, TCX.PBXAPI.CallStateChangedEventArgs e)
    {
        if (e.State == CallState.Missed || e.State == CallState.NotAnswered)
        {
            NotifyMissedCall(token: authToken, args1: e.FromExtension, args2: e.ToExtension, args3: e.CallDuration.ToString()); // Call your API to notify about the missed call
        }
    }

    private static void NotifyMissedCall(string token, string args1, string args2, string args3)
    {
        string apiUrl = "https://your-api-url/missed-call-notification";
        
        string postData = $"{{\"token\": \"{token}\", \"fromExtension\": \"{args1}\", \"toExtension\": \"{args2}\", \"callDuration\": \"{args3}\"}}";

        using (var client = new WebClient())
        {
            client.Headers[HttpRequestHeader.ContentType] = "application/json";
            string response = client.UploadString(apiUrl, "POST", postData);
            Console.WriteLine("API Response: " + response);
        }
    }

wasimfirmz avatar Apr 17 '24 05:04 wasimfirmz