If you use the RingCentral .Net SDK to subscribe for notification, the subscription will be refreshed automatically as long as the access token (from the RestClient) is valid. If you don't use the RingCentral SDK, you have to implement a timer check the expiration time and call renew before it expires. See the code how it is handled by the SDK.
Thank you
I use Nuget Ringcentral.Net Pubnub to subscribe.
So how long did the Token stay alive and how to keep it alive?
I know the token stayed for an hour.
Hi, I implementation the subscription according to RingCentral.Net.Pubnub.Subscription I also run a timer every 55 minutes to keep alive token.
My problem is after a few hours the token continued to refresh but the subscription lost.
I logged token and subscription state every 55 minutes ( when refreshing token)
1) log token state before refreshing.
refreshing token...
2) log subscription mode after refresh token.
3) log token state after refreshing.
The log file log_2019-08-01 - Copy.txt
My code is
public void Init()
{
AsyncContext.Run(async () =>
{
_rc = await _rcEngine.GetRestClient();
});
Timer aTimer = new Timer();
aTimer.Elapsed += OnTimedEvent;
aTimer.Interval = 1000 * 60 * 55;
//aTimer.Interval = 1000 * 20 * 1;
aTimer.Enabled = true;
}
private void OnTimedEvent(object sender, ElapsedEventArgs e)
{
_logger.Info($"token: {_rc.token?.access_token} expires_in:{_rc.token?.expires_in}");
AsyncContext.Run(async () =>
{
await _rc.Refresh();
var subscriptions = await _rc.Restapi().Subscription().List();
if (subscriptions.records.Any())
{
foreach (var subscriptionsRecord in subscriptions.records)
{
_logger.Info($"eventFilters: {String.Join(", ",subscriptionsRecord.eventFilters)} " +
$"expirationTime:{subscriptionsRecord.expirationTime} " +
$"expiresIn:{subscriptionsRecord.expiresIn}");
}
}
});
_logger.Info($"token: {_rc.token?.access_token} expires_in:{_rc.token?.expires_in}");
}
It is hard to say why the subscription is lost w/o knowing how the entire app is implemented and run.
However, if you expect the subscription to run for long hours or days, Webhooks notification is a better choice. Please read this article and consider it.