Dear Team, I have been able to test some of the functionalities of the RingCentral system and I am fine with it.
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;
}
}