Telerik 推送通知过滤
Telerik push notifications filtering
我正在开发一个系统,该系统会在系统中发布新项目时自动发送推送消息。这很顺利。问题是我必须对软件包和专业进行一些过滤。
在第一个过滤器块中,它可以工作,但它会发送到所有符合其中一个条件的设备。我想要的(并在测试 2 和 3 中尝试过)是它只在有人拥有软件包和某个职业时发送。
telerik api 的愚蠢之处在于它只是 returns 一个 HTTP 400,所以调试非常困难
希望有人能帮助我。
ps。我在片段
中跳过了一些不相关的 code/functions
function sendNotifications(some parameters)
{
string json = "{";
//Test code 1 - This works
json += "\"Filter\": {";
json += "\"Parameters.softwarePakket\": {\"$in\": [ \"{software_package}\"]},";
json += "\"Parameters.beroepsGroep\": {\"$in\": [\"{profession1}\", \"{profession2}\"]},";
json += "\"Parameters.module\": {\"$in\": [\"{module}\"]}},";
//Test code 2 - This doesn't work
//json += "\"Filter\": {\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]}";
//Test code 3 - And this doesn't work either
//json += "\"Filter\": \"{\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]}\"";
//From here its all fine
json += "\"Android\": {\"data\": {\"title\": \"{app_title}\",\"message\": \"{message}\",\"color\": \"#ffffff\",\"largeIcon\": \"{icon}\",\"customData\": \"{type}\"}},";
json += "\"IOS\": {\"aps\": {\"alert\": \"{message}\",\"badge\": \"+1\",\"sound\": \"default\",\"category\": \"{type}\"},\"customData\": \"{type}\"}";
json += "}";
json = json.Replace("{type}", type);
json = json.Replace("{icon}", formatIcon(type));
json = json.Replace("{message}", genericMessage(type));
var request = (HttpWebRequest)WebRequest.Create("http://api.everlive.com/v1/{app_id}/Push/Notifications");
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = json.Length;
using (var stream = new StreamWriter(request.GetRequestStream()))
{
stream.Write(json);
stream.Flush();
stream.Close();
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
我认为您在过滤器字符串的末尾缺少一个逗号。所以代码应该是:
//Test code 2
json += "\"Filter\": {\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]},";
//Test code 3
//json += "\"Filter\": \"{\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]}\",";
我正在开发一个系统,该系统会在系统中发布新项目时自动发送推送消息。这很顺利。问题是我必须对软件包和专业进行一些过滤。
在第一个过滤器块中,它可以工作,但它会发送到所有符合其中一个条件的设备。我想要的(并在测试 2 和 3 中尝试过)是它只在有人拥有软件包和某个职业时发送。
telerik api 的愚蠢之处在于它只是 returns 一个 HTTP 400,所以调试非常困难
希望有人能帮助我。
ps。我在片段
中跳过了一些不相关的 code/functionsfunction sendNotifications(some parameters)
{
string json = "{";
//Test code 1 - This works
json += "\"Filter\": {";
json += "\"Parameters.softwarePakket\": {\"$in\": [ \"{software_package}\"]},";
json += "\"Parameters.beroepsGroep\": {\"$in\": [\"{profession1}\", \"{profession2}\"]},";
json += "\"Parameters.module\": {\"$in\": [\"{module}\"]}},";
//Test code 2 - This doesn't work
//json += "\"Filter\": {\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]}";
//Test code 3 - And this doesn't work either
//json += "\"Filter\": \"{\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]}\"";
//From here its all fine
json += "\"Android\": {\"data\": {\"title\": \"{app_title}\",\"message\": \"{message}\",\"color\": \"#ffffff\",\"largeIcon\": \"{icon}\",\"customData\": \"{type}\"}},";
json += "\"IOS\": {\"aps\": {\"alert\": \"{message}\",\"badge\": \"+1\",\"sound\": \"default\",\"category\": \"{type}\"},\"customData\": \"{type}\"}";
json += "}";
json = json.Replace("{type}", type);
json = json.Replace("{icon}", formatIcon(type));
json = json.Replace("{message}", genericMessage(type));
var request = (HttpWebRequest)WebRequest.Create("http://api.everlive.com/v1/{app_id}/Push/Notifications");
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = json.Length;
using (var stream = new StreamWriter(request.GetRequestStream()))
{
stream.Write(json);
stream.Flush();
stream.Close();
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
我认为您在过滤器字符串的末尾缺少一个逗号。所以代码应该是:
//Test code 2
json += "\"Filter\": {\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]},";
//Test code 3
//json += "\"Filter\": \"{\"$and\":[{\"Parameters.softwarePakket\":\"{software_package}\"},{\"Parameters.beroepsGroep\":\"{profession1}\"}]}\",";