Skip to main content

Hello,

I've been working on setting up a Webhook using the Quick Start Guide example for C#, but I've run into a problem with the Validation Token. I don't see anywhere in the quick start guide where the token is referenced, and I've thus far not found anything on the forums for the C# example. My code currently is identical to the example in the guide with the two exceptions being:

  • eventFilters = new[] { "/restapi/v1.0/account/~/telephony/sessions" }
  • deliveryMode = new NotificationDeliveryMode{...}

There is no NotificationDeliveryModeRequest in the RingCentral.Net package from what I've been able to find. Should I be using a different package for this, and is that why I have no validation token? Are there additional steps that were not included in the quick start guide? Or is there something that I've missed elsewhere? Any advice or assistance would be appreciated!

Did you run this script (Startup.cs) when testing? If so, can you print the validation-token to the console?

app.Run( async (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.ReadToEnd();
Console.WriteLine(str);
}
}
});

I've ran both the server and the setup projects as listed in the quick start guide using the command line prompts given within the guide. This is what I get from the server (script above) project:

2023-03-31-13-55-49-psinet-microsoft-visual-studio.png

I don't see a validation token anywhere, and I'm not able to do anything with the console except exit out of running it. Is there a component that I'm missing somewhere? I've put my full Startup.cs for the server down below as reference (it should be the same as the guide unless I've missed something?)

public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
}

public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env)
{
if (env.IsDevelopment()) app.UseDeveloperExceptionPage();

app.Run(async (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.ReadToEnd();
Console.WriteLine(str);
}
}
});

}
}

It appears that it was a problem on the server side. My project targets .NET 7.0 and it was missing calls to configuration! Here's the relevant code added if anyone else is having this issue:

In Startup.cs

public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

In Program.cs

using webhook_server;

var builder = WebApplication.CreateBuilder(args);
var startup = new Startup(builder.Configuration);

startup.ConfigureServices(builder.Services);

var app = builder.Build();

startup.Configure(app, app.Environment);

app.Run();

Thank you for pointing me in the right direction for looking at the server. Would it be possible for this information be added to the documentation regarding target frameworks for C# Webhooks?


I ma using old .NET 5.0. Let me check if adding the configuration to old .NET would also work then I will update. Otherwise, I can add a note to the dev guide. Thanks for sharing your finding!


Reply