SMS Subscription is not working after couple of hours
Tags: sdk
Sep 22, 2016 at 12:58pm • 3 replies • 0 likes
z-admin
we are using the windows service to create the subscription and this windows service will be running always in the server, after couple of hours or more than those hours the subscription is not working and we have to start and stop the windows service to start the sending the SMS again.
do we need to do this always? do we have any mechanism to continuously keep running the service and sending the SMS all times.
3 Answers
We are using the below code
private SDK sdk; private SubscriptionService subscription;
public void SetupSub()
{
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "SetupSub", "*********************************Function Started*************************");
string appsecret = ConfigurationManager.AppSettings["appsecret"];
string appkey = ConfigurationManager.AppSettings["appkey"];
string userphonenumber = ConfigurationManager.AppSettings["userphonenumber"];
string password = ConfigurationManager.AppSettings["password"];
string defaultendpoint = ConfigurationManager.AppSettings["apiendpoint"];
string fromnumber = ConfigurationManager.AppSettings["fromnumber"];
sdk = new SDK(appkey,appsecret, defaultendpoint, "IncomingSMSapp", "1.0.0");
sdk.Platform.Login(userphonenumber, "", password, true);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information,"Info", "Subscription successful");
subscription = sdk.CreateSubscription();
subscription.EventFilters.Add("/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS");
var connectCount = 0;
subscription.ConnectEvent += (sender, args) => {
connectCount += 1;
// Console.WriteLine(args.Message);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Connected");
};
var messageCount = 0;
subscription.NotificationEvent += (sender, args) => {
messageCount += 1;
// Console.WriteLine(args.Message);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Notification received," + args.Message.ToString());
var obj = JObject.Parse(args.Message.ToString());
string messagecontent= obj.AsJEnumerable()["body"]["subject"].ToString();
messagecontent = messagecontent.Replace("#", "%23");
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Notification received, message" + messagecontent);
string from=obj.AsJEnumerable()["body"]["from"]["phoneNumber"].ToString();
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Notification received, From" + from);
string to = obj.AsJEnumerable()["body"]["to"][0].ToString().Split(':')[1].Split('"')[1];
from = from.Remove(0, 1);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Notification received, To" + to);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Notification received, To" + from);
};
var errorCount = 0;
subscription.ErrorEvent += (sender, args) => {
errorCount += 1;
// Console.WriteLine(args.Message);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Error received," + args.Message);
};
subscription.Register();
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Subscribed successfully");
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Thread", "Waiting for incoming sms events");
private SDK sdk; private SubscriptionService subscription;
public void SetupSub()
{
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "SetupSub", "*********************************Function Started*************************");
string appsecret = ConfigurationManager.AppSettings["appsecret"];
string appkey = ConfigurationManager.AppSettings["appkey"];
string userphonenumber = ConfigurationManager.AppSettings["userphonenumber"];
string password = ConfigurationManager.AppSettings["password"];
string defaultendpoint = ConfigurationManager.AppSettings["apiendpoint"];
string fromnumber = ConfigurationManager.AppSettings["fromnumber"];
sdk = new SDK(appkey,appsecret, defaultendpoint, "IncomingSMSapp", "1.0.0");
sdk.Platform.Login(userphonenumber, "", password, true);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information,"Info", "Subscription successful");
subscription = sdk.CreateSubscription();
subscription.EventFilters.Add("/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS");
var connectCount = 0;
subscription.ConnectEvent += (sender, args) => {
connectCount += 1;
// Console.WriteLine(args.Message);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Connected");
};
var messageCount = 0;
subscription.NotificationEvent += (sender, args) => {
messageCount += 1;
// Console.WriteLine(args.Message);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Notification received," + args.Message.ToString());
var obj = JObject.Parse(args.Message.ToString());
string messagecontent= obj.AsJEnumerable()["body"]["subject"].ToString();
messagecontent = messagecontent.Replace("#", "%23");
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Notification received, message" + messagecontent);
string from=obj.AsJEnumerable()["body"]["from"]["phoneNumber"].ToString();
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Notification received, From" + from);
string to = obj.AsJEnumerable()["body"]["to"][0].ToString().Split(':')[1].Split('"')[1];
from = from.Remove(0, 1);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Notification received, To" + to);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Notification received, To" + from);
};
var errorCount = 0;
subscription.ErrorEvent += (sender, args) => {
errorCount += 1;
// Console.WriteLine(args.Message);
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Incoming SMS Error received," + args.Message);
};
subscription.Register();
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Subscribed successfully");
Logger.TraceLog(System.Diagnostics.TraceEventType.Information, "Info", "Thread", "Waiting for incoming sms events");
0
Hello Team,
Apologies for the late reply on this thread. We are using c# SDK for subscribing for incoming sms event . The subscription works as long as the incoming smses are being received . If there is no sms received for some time let's say an hour and later a new sms is received there is no notification coming. Once we restart the service it starts working again. Can you please help as we were assuming that in sdk we don't need to refresh.
Apologies for the late reply on this thread. We are using c# SDK for subscribing for incoming sms event . The subscription works as long as the incoming smses are being received . If there is no sms received for some time let's say an hour and later a new sms is received there is no notification coming. Once we restart the service it starts working again. Can you please help as we were assuming that in sdk we don't need to refresh.
0
RingCentral access tokens and refresh tokens have expiration times associated with them. By default, access tokens expire in 1 hour and refresh tokens expire in 1 week. This means after 1 hour, your app will need to refresh the access token using the refresh token. If your app is not performing token refresh, it may stop being authorized after 1 hour.
Official RingCentral SDKs will perform auto-refresh if your app continues to make API calls. The new C# Client SDK will also auto renew as long as your service is running.
Are you using a SDK and, if so, which one? If not, what language are you using? Our SDKs are listed here:
https://developers.ringcentral.com/library/sdks.html
More information on OAuth token refresh is available on this here:
https://developers.ringcentral.com/api-docs/latest/index.html#!#OauthTokens.html
Official RingCentral SDKs will perform auto-refresh if your app continues to make API calls. The new C# Client SDK will also auto renew as long as your service is running.
Are you using a SDK and, if so, which one? If not, what language are you using? Our SDKs are listed here:
https://developers.ringcentral.com/library/sdks.html
More information on OAuth token refresh is available on this here:
https://developers.ringcentral.com/api-docs/latest/index.html#!#OauthTokens.html
0
A new Community is coming to RingCentral!
Posts are currently read-only as we transition into our new platform.We thank you for your patience
during this downtime.
Try Workflow Builder
Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!Try RingCentral Workflow Builder