Skip to main content

Dear Team, I have been able to test some of the functionalities of the RingCentral system and I am fine with it.

However, i am still having some challenges with the webhook API.
I followed the instruction on the website to set up a web hook api for our proposed fax system.

However I am not receiving any notification on the web hook end point as expected. Please tell me what I am doing wrong. My web hook end point is called createsubscription(for you to kindly look up). Please see all my code snippets below

StartUp

app.Run((context) =>
{
context.Request.Headers.TryGetValue("Validation-Token", out StringValues validationToken);
context.Response.Headers.Add("Validation-Token", validationToken);
if (context.Request.Path == "/webhook" && context.Request.Method == "POST")
{
using (StreamReader reader = new StreamReader(context.Request.Body, Encoding.UTF8))
{
var str = reader.ReadToEndAsync();
Console.WriteLine(str);
}
}

return Task.CompletedTask;
});


//Program Class
public class Program
{
static RestClient restClient;
const string DELIVERY_ADDRESS = "https://e889-96-73-205-2.ngrok.io/ringcentral/hook";
public static void Main(string[] args)
{
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
CreateHost(args);
subscription();


}
async static void subscription()
{
const string RECIPIENT = "+16079303426";
const string RINGCENTRAL_CLIENTID = "MJ9Ch2XRRm6xjTQXSsbRYA";
const string RINGCENTRAL_CLIENTSECRET = "254-Vxa_SBa_6JXDBja0Aw8R1dxS1URvxxxxxxxx";
const string RINGCENTRAL_SERVER = "https://platform.devtest.ringcentral.com";
const bool RINGCENTRAL_PRODUCTION = false;

const string RINGCENTRAL_USERNAME = "+1470xxxxyyyy";
const string RINGCENTRAL_PASSWORD = "pwd";
const string RINGCENTRAL_EXTENSION = "101";


restClient = new RestClient(
RINGCENTRAL_CLIENTID,
RINGCENTRAL_CLIENTSECRET,
RINGCENTRAL_SERVER);
restClient.Authorize(
RINGCENTRAL_USERNAME,
RINGCENTRAL_EXTENSION,
RINGCENTRAL_PASSWORD).Wait();
await restClient.Restapi().Subscription().Post(new CreateSubscriptionRequest
{
eventFilters = new[] { "/restapi/v1.0/account/312526004/extension/312526004/fax?direction=Inbound" },
deliveryMode = new NotificationDeliveryModeRequest
{
transportType = "WebHook",
address = DELIVERY_ADDRESS
}
});
Console.WriteLine("WebHook ready!");
}
}


public class RingCentralController : Controller
{
 //Web Hook End Point
HttpPost]
Route("hook")]
public ActionResult<HttpResponseMessage> createsubscription(CreateSubscriptionRequest createSubscriptionRequest)
{
string authtoken = createSubscriptionRequest.deliveryMode.verificationToken;
if (authtoken.Length > 0)
{
return BadRequest();
}

HttpResponseMessage responseMessage = new HttpResponseMessage();
responseMessage.Headers.Add("Validation-Token", authtoken);

return responseMessage;

}
}

First of all, here are some guidelines and best practices to get help.

1. NEVER post sensitive information about your app, user credentials in public forum (I already modified your post to hide them).

2. Post code within code block and correct indents for better readability.

3. Post some trace log so people can see what could happen at what point.


Check if you pass the line Console.WriteLine("WebHook ready!");?

Your defined path is "/ringcentral/hook" but you expect the "/webhook" path

if (context.Request.Path == "/webhook" && context.Request.Method == "POST")

You also have some extra code to define a different webhook endpoint. Why?

[HttpPost]
[Route("hook")]

Where do you get the instruction and the code from? I recommend to follow the code in this dev guide getting started.



Reply