public async Task <string> CreateTopicGroup(string SenderTokenID, string SenderTopicName) { FCMController fcm = new FCMController(); ctblFCM fcmDetails = new ctblFCM(); fcmDetails = (ctblFCM)fcm.GetctblFCM(1); // string token = "euGW0vssj4c:APA91bGAL3ks7gOTG6c8NIMfw698cwT2YQLO9iXEM_OCLgv7EdtNVg2m_xFye7WL056tPFtV_S8NqMT-rv_zDh8sg0YZXJMqhzo4UaUu553gXdcRy5XssoB63z81VmXrmDPyN36raY3g"; // SenderTokenID = token; // string SERVER_API_KEY = "AAAAPYj679o:APA91bEKN3E2csYZVghk3DpyHbVWn43gzTbYZ_z8rjIoDuVxWpALbHL_v6OEx8RQTfP5pQ7KD_JNeSJwJmFIx3Aq-OYcq5fid1mYhrF4fgPV3CjEeNFTttIhZxs7158hkUr_WzC_NHqtByTQho0_2wUoiWZt6rY-4Q"; //var SENDER_ID = "264291151834"; // string SERVER_API_KEY = fcmDetails.SERVER_API_KEY; //var SENDER_ID = fcmDetails.PROJECT_KEY; WebRequest tRequest; String sResponseFromServer; tRequest = WebRequest.Create("https://iid.googleapis.com/iid/v1/" + SenderTokenID + "/rel/topics/" + SenderTopicName); tRequest.Method = "post"; tRequest.Headers.Add(string.Format("Authorization: key={0}", fcmDetails.SERVER_API_KEY)); tRequest.Headers.Add(string.Format("project_id:{0}", fcmDetails.PROJECT_KEY)); tRequest.ContentType = "application/json"; tRequest.ContentLength = 0; try { tRequest.GetRequestStream(); /* Stream dataStream; * * using (WebResponse tResponse = tRequest.GetResponse()) * { * using (Stream stream = tResponse.GetResponseStream()) * { * // XmlTextReader reader = new XmlTextReader(stream); * // var json = serializer.Serialize(stream); * * dataStream = tResponse.GetResponseStream(); * StreamReader tReader = new StreamReader(dataStream); * sResponseFromServer = tReader.ReadToEnd(); * tReader.Close(); * dataStream.Close(); * tResponse.Close(); * } * }*/ } catch (Exception ex) { sResponseFromServer = ex.Message.ToString(); } sResponseFromServer = await CheckTopicGroup(SenderTokenID, SenderTopicName); return(sResponseFromServer); }
public ctblFCM GetctblFCM(int id) { ctblFCM ctblFCM = db.ctblFCMs.Find(id); if (ctblFCM == null) { ctblFCM ctblFC = new ctblFCM(); ctblFC.SERVER_API_KEY = " No FCM DETAILS FOUND. "; return(ctblFC); } return(ctblFCM); }
public async Task <cStatus> GetfcmsubcriptioncheckAsync(string DeviceID) { cStatus st = new cStatus(); FCMController fcm = new FCMController(); ctblFCM fcmDetails = new ctblFCM(); fcmDetails = (ctblFCM)fcm.GetctblFCM(1); string uri; //uri = "https://iid.googleapis.com/iid/info/f0l3VKFi_bs:APA91bEvLlgSHIwB3zJv3YEL_jkjxXRVzWY85jNe4_6tSC-IE7oh-FqJBajA9nuDNI7pZCZ1eqa2aDjCCpK9bS7jW0ONezffGvRMs7q4lbyVGEYkKLv4tH9wE26b80aSLM5sdowG349G?details=true"; uri = "https://iid.googleapis.com/iid/info/" + DeviceID + "?details=true"; try { var client = new RestClient(uri); var request = new RestRequest(Method.GET); request.AddHeader("sender", string.Format("id={0}", fcmDetails.PROJECT_KEY)); request.AddHeader("Content-Type", "application/json"); request.AddHeader("authorization", string.Format("key={0}", fcmDetails.SERVER_API_KEY)); IRestResponse <cFCMSubscribed> asyncHandle = await client.ExecuteGetTaskAsync <cFCMSubscribed>(request); //return asyncHandle.Content.ToString(); st.DesctoDev = asyncHandle.Content.ToString(); if (st.DesctoDev.Contains("THANDORA_ADMIN") && st.DesctoDev.Contains("INDIA")) { st.StatusMsg = "THANDORA Installed successfully"; st.StatusID = 0; } else { st.StatusMsg = "THANDORA Installation failed. Please install it again. "; st.StatusID = 1; } return(st); } catch (Exception ex) { st.StatusID = 1;// Notification failure st.StatusMsg = ex.Message.ToString(); return(st); } }
public async Task <string> CheckTopicGroup(string SenderTokenID, string SenderTopicName) { // string token = "euGW0vssj4c:APA91bGAL3ks7gOTG6c8NIMfw698cwT2YQLO9iXEM_OCLgv7EdtNVg2m_xFye7WL056tPFtV_S8NqMT-rv_zDh8sg0YZXJMqhzo4UaUu553gXdcRy5XssoB63z81VmXrmDPyN36raY3g"; // SenderTokenID = token; FCMController fcm = new FCMController(); ctblFCM fcmDetails = new ctblFCM(); fcmDetails = (ctblFCM)fcm.GetctblFCM(1); // string SERVER_API_KEY = "AAAAPYj679o:APA91bEKN3E2csYZVghk3DpyHbVWn43gzTbYZ_z8rjIoDuVxWpALbHL_v6OEx8RQTfP5pQ7KD_JNeSJwJmFIx3Aq-OYcq5fid1mYhrF4fgPV3CjEeNFTttIhZxs7158hkUr_WzC_NHqtByTQho0_2wUoiWZt6rY-4Q"; // var SENDER_ID = "264291151834"; //string SERVER_API_KEY = fcmDetails.SERVER_API_KEY; //var SENDER_ID = fcmDetails.PROJECT_KEY; WebRequest tRequest; String sResponseFromServer; tRequest = WebRequest.Create("https://iid.googleapis.com/iid/info/" + SenderTokenID + "?details=true"); tRequest.Method = "get"; //tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", fcmDetails.SERVER_API_KEY)); tRequest.Headers.Add(string.Format("project_id:{0}", fcmDetails.PROJECT_KEY)); tRequest.ContentType = "application/json"; //tRequest.UseDefaultCredentials = true; var postData = new { operation = "create", notification_key_name = "Thandora-603103", }; var serializer = new JavaScriptSerializer(); var json = serializer.Serialize(postData); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.ContentLength = 0; try { Stream dataStream; using (WebResponse tResponse = tRequest.GetResponse()) { using (Stream stream = tResponse.GetResponseStream()) { // XmlTextReader reader = new XmlTextReader(stream); // var json = serializer.Serialize(stream); dataStream = tResponse.GetResponseStream(); StreamReader tReader = new StreamReader(dataStream); sResponseFromServer = tReader.ReadToEnd(); tReader.Close(); dataStream.Close(); tResponse.Close(); if (sResponseFromServer.Contains(SenderTopicName)) { sResponseFromServer = "Topic Created/Subscribed in the Name of " + SenderTopicName; } } } // tRequest.GetRequestStream(); // WebResponse tResponse = tRequest.GetResponse(); } catch (Exception ex) { sResponseFromServer = ex.Message.ToString(); } return(sResponseFromServer); }
public async Task <cStatus> SubscriberNotificationAsync(string DeviceID, string subscriber, string msg) { cStatus st = new cStatus(); FCMController fcm = new FCMController(); ctblFCM fcmDetails = new ctblFCM(); fcmDetails = (ctblFCM)fcm.GetctblFCM(1); string uri; uri = "https://fcm.googleapis.com/fcm/send"; try { var client = new RestClient(uri); var request = new RestRequest(Method.POST); request.AddHeader("sender", string.Format("id={0}", fcmDetails.PROJECT_KEY)); request.AddHeader("content-type", "application/json"); request.AddHeader("authorization", string.Format("key={0}", fcmDetails.SERVER_API_KEY)); var postData = new { to = DeviceID, data = new { MessageID = 1 }, priority = "high", notification = new { body = subscriber + msg, title = "Subscription update", icon = "myicon" } }; var serializer = new JavaScriptSerializer(); var json = serializer.Serialize(postData); //request.AddParameter("application/json", "{\r\n \"to\" : \""+DeviceID+"\"\r\n \"data\":{\r\n \t \"enquiryID\": "+enquiryid.ToString()+"\r\n }\r\n \r\n \"notification\":\r\n {\r\n \"body\": \""+enquirymessage+"\",\r\n \"title\":\""+FromUser +"\",\r\n \"icon\": \"myicon\"\r\n }\r\n }", ParameterType.RequestBody); //request.AddParameter("application/json", request.JsonSerializer.Serialize( new {to = DeviceID, data = new {MessageID = enquiryid}, notification = new // { body = enquirymessage, title = FromUser,icon = "myicon" } }) , ParameterType.RequestBody); request.AddParameter("application/json", json, ParameterType.RequestBody); /*var rs = client.Execute(request); * sResponseFromServer = rs.Content.ToString(); * return sResponseFromServer;*/ //var asyncHandle = await client.ExecuteAsync(request, NotificationOnComplete); IRestResponse <cFCMReturn> asyncHandle = await client.ExecutePostTaskAsync <cFCMReturn>(request); //return asyncHandle.Content.ToString(); st.DesctoDev = asyncHandle.Content.ToString(); st.returnID = asyncHandle.Data.success; st.StatusID = asyncHandle.Data.failure; //return asyncHandle.Data.success.ToString(); return(st); } catch (Exception ex) { st.StatusID = 1;// Notification failure st.StatusMsg = ex.Message.ToString(); return(st); } }
public async Task <cStatus> EnquiryNotificationAsync(string DeviceID, string FromUser, string Message, int id, string NotifyType, int senderID) { cStatus st = new cStatus(); FCMController fcm = new FCMController(); ctblFCM fcmDetails = new ctblFCM(); fcmDetails = (ctblFCM)fcm.GetctblFCM(1); string uri; uri = "https://fcm.googleapis.com/fcm/send"; try { var client = new RestClient(uri); var request = new RestRequest(Method.POST); request.AddHeader("sender", string.Format("id={0}", fcmDetails.PROJECT_KEY)); request.AddHeader("content-type", "application/json"); request.AddHeader("authorization", string.Format("key={0}", fcmDetails.SERVER_API_KEY)); /*var postData = new * { * to = DeviceID, * data = new * { * MessageID = enquiryid * }, * * notification = new * { * body = enquirymessage, * title = FromUser, * icon = "myicon" * } * };*/ int typeid = 0; if (NotifyType == "Comments") { typeid = 2; } if (NotifyType == "Enquiry") { typeid = 3; } if (NotifyType == "Feedback") { typeid = 4; } var postData = new { to = DeviceID, data = new { title = NotifyType, message = Message, SenderName = FromUser, imageUrl = "", messageId = id, SenderID = senderID, notificationType = typeid //(1->PostMessage, 2-- > Comment, 3 --> Enquiry, and so on) }, priority = "high" }; var serializer = new JavaScriptSerializer(); var json = serializer.Serialize(postData); //request.AddParameter("application/json", "{\r\n \"to\" : \""+DeviceID+"\"\r\n \"data\":{\r\n \t \"enquiryID\": "+enquiryid.ToString()+"\r\n }\r\n \r\n \"notification\":\r\n {\r\n \"body\": \""+enquirymessage+"\",\r\n \"title\":\""+FromUser +"\",\r\n \"icon\": \"myicon\"\r\n }\r\n }", ParameterType.RequestBody); //request.AddParameter("application/json", request.JsonSerializer.Serialize( new {to = DeviceID, data = new {MessageID = enquiryid}, notification = new // { body = enquirymessage, title = FromUser,icon = "myicon" } }) , ParameterType.RequestBody); request.AddParameter("application/json", json, ParameterType.RequestBody); /*var rs = client.Execute(request); * sResponseFromServer = rs.Content.ToString(); * return sResponseFromServer;*/ //var asyncHandle = await client.ExecuteAsync(request, NotificationOnComplete); IRestResponse <cFCMReturn> asyncHandle = await client.ExecutePostTaskAsync <cFCMReturn>(request); //return asyncHandle.Content.ToString(); st.DesctoDev = asyncHandle.Content.ToString(); st.returnID = asyncHandle.Data.success; st.StatusID = asyncHandle.Data.failure; //return asyncHandle.Data.success.ToString(); return(st); } catch (Exception ex) { st.StatusID = 1;// Notification failure st.StatusMsg = ex.Message.ToString(); return(st); } }
private async Task <IHttpActionResult> EnquiryNotification(string DeviceID, string FromUser, string enquirymessage, int enquiryid) { string toGroup; FCMController fcm = new FCMController(); ctblFCM fcmDetails = new ctblFCM(); fcmDetails = (ctblFCM)fcm.GetctblFCM(1); //var value = "New TELLER:" + TellerService; WebRequest tRequest; String sResponseFromServer; tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; //tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", fcmDetails.SERVER_API_KEY)); tRequest.Headers.Add(string.Format("Sender: id={0}", fcmDetails.PROJECT_KEY)); tRequest.ContentType = "application/json;charset=UTF-8"; //toGroup = "/topics/" + GroupName; var postData = new { //registration_ids = deviceids, //to=devicegroup, //to= "ckZ8rtZ6r1I:APA91bHvdVlS7p7-XdQMWAVI1zpG6LfU40Mrllj9u2wRtGhnQ-GUPk43BjtfsDadoJmYviCsn1mMluXaJfWrldLWLccddgAE1cUVIbVP1a7JSo3IIlraZoi4qipt8v-1owIavTniwahd", to = DeviceID, //to = toGroup, data = new { MessageID = enquiryid }, notification = new { body = enquirymessage, title = FromUser, icon = "myicon" } }; var serializer = new JavaScriptSerializer(); var json = serializer.Serialize(postData); Byte[] byteArray = Encoding.UTF8.GetBytes(json); //Console.WriteLine(data); // Byte[] byteArray = Encoding.UTF8.GetBytes(postData); tRequest.ContentLength = byteArray.Length; try { Stream dataStream; //Stream dataStream = tRequest.GetRequestStream(); using (dataStream = tRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); } WebResponse tResponse = tRequest.GetResponse(); // dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); dataStream = tResponse.GetResponseStream(); StreamReader tReader = new StreamReader(dataStream); sResponseFromServer = tReader.ReadToEnd(); tReader.Close(); dataStream.Close(); tResponse.Close(); } catch (Exception ex) { sResponseFromServer = ex.Message.ToString(); } // return sResponseFromServer; return(Ok(sResponseFromServer)); }
public async Task <cStatus> NewTellerNotificationAsync(string GroupName, string TellerName, string TellerService, int senderID) { string toGroup, uri; cStatus st = new cStatus(); FCMController fcm = new FCMController(); ctblFCM fcmDetails = new ctblFCM(); fcmDetails = (ctblFCM)fcm.GetctblFCM(1); var value = "New TELLER:" + TellerService; uri = "https://fcm.googleapis.com/fcm/send"; toGroup = "/topics/" + GroupName; try { var client = new RestClient(uri); var request = new RestRequest(Method.POST); request.AddHeader("sender", string.Format("id={0}", fcmDetails.PROJECT_KEY)); request.AddHeader("content-type", "application/json"); request.AddHeader("authorization", string.Format("key={0}", fcmDetails.SERVER_API_KEY)); var postData = new { //registration_ids = deviceids, //to=devicegroup, //to= "ckZ8rtZ6r1I:APA91bHvdVlS7p7-XdQMWAVI1zpG6LfU40Mrllj9u2wRtGhnQ-GUPk43BjtfsDadoJmYviCsn1mMluXaJfWrldLWLccddgAE1cUVIbVP1a7JSo3IIlraZoi4qipt8v-1owIavTniwahd", to = toGroup, data = new { title = " available in THANDORA", message = TellerName + " joined in Thandora as " + TellerService, SenderName = TellerName, imageUrl = "", messageId = senderID, SenderID = senderID, notificationType = 4 //(1->PostMessage, 2-- > Comment, 3 --> Enquiry, 4 -> New Teller and so on) }, priority = "high", /* data = new * { * MessageID = 1 * },*/ /*notification = new * { * body = TellerName + " joined in Thandora as " + TellerService, * title = TellerName + " using THANDORA", * icon = "myicon" * }*/ }; var serializer = new JavaScriptSerializer(); var json = serializer.Serialize(postData); //request.AddParameter("application/json", "{\r\n \"to\" : \""+DeviceID+"\"\r\n \"data\":{\r\n \t \"enquiryID\": "+enquiryid.ToString()+"\r\n }\r\n \r\n \"notification\":\r\n {\r\n \"body\": \""+enquirymessage+"\",\r\n \"title\":\""+FromUser +"\",\r\n \"icon\": \"myicon\"\r\n }\r\n }", ParameterType.RequestBody); //request.AddParameter("application/json", request.JsonSerializer.Serialize( new {to = DeviceID, data = new {MessageID = enquiryid}, notification = new // { body = enquirymessage, title = FromUser,icon = "myicon" } }) , ParameterType.RequestBody); request.AddParameter("application/json", json, ParameterType.RequestBody); /*var rs = client.Execute(request); * sResponseFromServer = rs.Content.ToString(); * return sResponseFromServer;*/ //var asyncHandle = await client.ExecuteAsync(request, NotificationOnComplete); IRestResponse <cFCMReturn> asyncHandle = await client.ExecutePostTaskAsync <cFCMReturn>(request); //return asyncHandle.Content.ToString(); st.DesctoDev = asyncHandle.Content.ToString(); st.returnID = asyncHandle.Data.success; // TOPIC DISTIBUTION WONT RETURN SUCCESS OR FAILURE st.StatusID = asyncHandle.Data.failure; // TOPIC DISTIBUTION WONT RETURN SUCCESS OR FAILURE //return asyncHandle.Data.success.ToString(); return(st); } catch (Exception ex) { st.StatusID = 1; st.StatusMsg = ex.Message.ToString(); return(st); } }
public async Task PostMessageforEachDeviceAsync(string titlebroadcast, string DeviceID, string SenderName, string msgCategory, string message, string imgPath, int MsgID, int senderID) { string uri; cStatus st = new cStatus(); FCMController fcm = new FCMController(); ctblFCM fcmDetails = new ctblFCM(); fcmDetails = (ctblFCM)fcm.GetctblFCM(1); string value; if (message.Length > 50) { value = message.Substring(0, 40) + "..."; } else { value = message; } uri = "https://fcm.googleapis.com/fcm/send"; /* if (SenderName.Equals("THANDORA ADMIN") == true) * { * toGroup = "/topics/THANDORA_ADMIN"; * } * else * { * toGroup = "/topics/" + GroupName; * } */ try { var client = new RestClient(uri); var request = new RestRequest(Method.POST); request.AddHeader("sender", string.Format("id={0}", fcmDetails.PROJECT_KEY)); request.AddHeader("content-type", "application/json"); request.AddHeader("authorization", string.Format("key={0}", fcmDetails.SERVER_API_KEY)); var postData = new { //registration_ids = deviceids, //to=devicegroup, //to= "ckZ8rtZ6r1I:APA91bHvdVlS7p7-XdQMWAVI1zpG6LfU40Mrllj9u2wRtGhnQ-GUPk43BjtfsDadoJmYviCsn1mMluXaJfWrldLWLccddgAE1cUVIbVP1a7JSo3IIlraZoi4qipt8v-1owIavTniwahd", //to = toGroup, to = DeviceID, data = new { title = titlebroadcast + "/" + msgCategory, message = value, SenderName = SenderName, imageUrl = imgPath, messageId = MsgID, SenderID = senderID, notificationType = "1" //(1->PostMessage, 2-- > EnquiryReply and so on) }, priority = "high" /*notification = new * { * body = value, * title = titlebroadcast + "/" + msgCategory + "/" + SenderName, * icon = "myicon" * }*/ }; var serializer = new JavaScriptSerializer(); var json = serializer.Serialize(postData); //request.AddParameter("application/json", "{\r\n \"to\" : \""+DeviceID+"\"\r\n \"data\":{\r\n \t \"enquiryID\": "+enquiryid.ToString()+"\r\n }\r\n \r\n \"notification\":\r\n {\r\n \"body\": \""+enquirymessage+"\",\r\n \"title\":\""+FromUser +"\",\r\n \"icon\": \"myicon\"\r\n }\r\n }", ParameterType.RequestBody); //request.AddParameter("application/json", request.JsonSerializer.Serialize( new {to = DeviceID, data = new {MessageID = enquiryid}, notification = new // { body = enquirymessage, title = FromUser,icon = "myicon" } }) , ParameterType.RequestBody); request.AddParameter("application/json", json, ParameterType.RequestBody); /*var rs = client.Execute(request); * sResponseFromServer = rs.Content.ToString(); * return sResponseFromServer;*/ //var asyncHandle = await client.ExecuteAsync(request, NotificationOnComplete); IRestResponse <cFCMReturn> asyncHandle = await client.ExecutePostTaskAsync <cFCMReturn>(request); //return asyncHandle.Content.ToString(); st.DesctoDev = asyncHandle.Content.ToString(); st.returnID = asyncHandle.Data.success; // TOPIC DISTIBUTION WONT RETURN SUCCESS OR FAILURE st.StatusID = asyncHandle.Data.failure; // TOPIC DISTIBUTION WONT RETURN SUCCESS OR FAILURE //return asyncHandle.Data.success.ToString(); } catch (Exception ex) { st.StatusID = 1;// Notification failure st.StatusMsg = ex.Message.ToString(); } }