static void Main(string[] args) { var client = new OneSignalClient(""); // Use your Api Key var options = new NotificationCreateOptions { AppId = new Guid(""), // Use your AppId IncludePlayerIds = new List <string>() { "00000000-0000-0000-0000-000000000000" // Use your playerId }, // ... OR ... IncludeExternalUserIds = new List <string>() { "000000" // whatever your custom id is } }; options.Headings.Add(LanguageCodes.English, "New Notification!"); options.Contents.Add(LanguageCodes.English, "This will push a real notification directly to your device."); var result = client.Notifications.Create(options); Console.WriteLine(JsonConvert.SerializeObject(result)); Console.ReadLine(); }
static void Main(string[] args) { var client = new OneSignalClient("NWExxx"); //id del cliente var options = new NotificationCreateOptions { AppId = new Guid("xxx"), // id de la aplicacion IncludedSegments = new string[] { "All" }, }; IList <ActionButtonField> abf = new List <ActionButtonField>() { new ActionButtonField() { Id = "cancelar", Text = "Cancelar" }, new ActionButtonField() { Id = "aceptar", Text = "Aceptar viaje" } }; options.Headings.Add(LanguageCodes.English, "Dummy"); options.Contents.Add(LanguageCodes.English, "contenido de dummy"); options.ActionButtons = abf; client.Notifications.Create(options); }
public IPushOutput Send(IPushInput input) { OneSignalOutPut oneSignalOutPut = new OneSignalOutPut(); OneSignalInformation information = CreateInformation(); OneSignalClient client = new OneSignalClient(information.ApiKey); NotificationCreateOptions options = new NotificationCreateOptions { AppId = new Guid(information.AppId) }; if (!string.IsNullOrEmpty(input.SubTitle)) { options.Subtitle.Add(LanguageCodes.English, input.SubTitle); } options.Priority = input.Priority; options.Headings.Add(LanguageCodes.English, input.Title); options.IncludePlayerIds.Add(input.To); options.Contents.Add(LanguageCodes.English, input.Message); NotificationCreateResult result = client.Notifications.Create(options); if (result.Recipients == 3) { oneSignalOutPut.IsSuccess = true; } oneSignalOutPut.Message = $"{result.Id}-{result.Recipients}"; return(oneSignalOutPut); }
static void Main(string[] args) { var client = new OneSignalClient("Yzg2MDViODAtNzE5OS00OTc0LTlmMmItNDhhYTYyOWVjZWE2"); var options = new NotificationCreateOptions() { AppId = new Guid("d88197f0-c247-4085-a72f-a7ac7aade44a"), IncludedSegments = new List <string> { "All" }, Filters = new List <INotificationFilter> { new NotificationFilterField { Field = NotificationFilterFieldTypeEnum.Tag, Key = "routeId", Value = "2010001" } } }; options.Contents.Add(LanguageCodes.English, "Route 2020001"); client.Notifications.Create(options); }
public async Task <bool> AddWin10Builds(NewBuildPost apiModel) { if (apiModel == null) { return(false); } if (Membership.ValidateUser(apiModel.Username, apiModel.Password)) { IEnumerable <Build> builds = apiModel.NewBuilds.Select(nb => new Build { MajorVersion = nb.MajorVersion, MinorVersion = nb.MinorVersion, Number = nb.Number, Revision = nb.Revision, Lab = nb.Lab, BuildTime = nb.BuildTime.HasValue ? DateTime.SpecifyKind(nb.BuildTime.Value, DateTimeKind.Utc) : null as DateTime?, Added = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), Modified = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), SourceType = TypeOfSource.PrivateLeak }); foreach (Build build in builds) { await _bModel.Insert(build); OneSignalClient osc = new OneSignalClient(ConfigurationManager.AppSettings["push:OneSignalApiKey"]); osc.PushNewBuild(build, $"https://buildfeed.net{Url.Route("Build", new { controller = "Front", action = nameof(FrontController.ViewBuild), id = build.Id, area = "", httproute = "" })}?utm_source=notification&utm_campaign=new_build"); } return(true); } return(false); }
private static void SendPushNotificationUsingCSharpSDk() { NotificationCreateResult result = null; var client = new OneSignalClient("M2QwNDM1NTktNjc2Yi00OWY1LTg5ZjYtZjlhNzE2ZjJjMGFm"); var options = new NotificationCreateOptions(); options.AppId = new Guid("9423ab70-f216-4a77-a364-cdf74f40e4fb"); //options.IncludedSegments = new List<string> { "All" }; options.Contents.Add(LanguageCodes.English, "Hello world!"); options.Headings.Add(LanguageCodes.English, "Hello!"); options.IncludePlayerIds = new List <string> { "17135056-a51d-4b45-bc7c-731b4b3a79eb", "82828ec2-7a9b-46c6-a781-ab07fb2a5998" }; options.Data = new Dictionary <string, string>(); options.Data.Add("notificationType", "SimpleTextMessage"); options.Data.Add("messageId", "03c2de5a-d08b-4b32-9723-d17034a64305"); options.AndroidLedColor = "FF0000FF"; options.IosBadgeType = IosBadgeTypeEnum.SetTo; options.IosBadgeCount = 10; options.AndroidAccentColor = "FFFF0000"; options.Priority = 10; options.DeliverToAndroid = false; try { result = client.Notifications.Create(options); } catch (Exception ex) { } }
private OneSignalNotificationService() { _oneSignalClient = new OneSignalClient(OneSignalId); _notificationCreateOptions = new NotificationCreateOptions(); _notificationCreateOptions.AppId = Guid.Parse(this.ApiId); }
// C# dependency installed via NuGut for access to the OneSignal API is: // https://github.com/Alegrowin/OneSignal.RestAPIv3.Client public static async Task<NotificationCreateResult> SendPushNotification(UserProfileTemporary userProfileTemporary, string title, string body) { if (string.IsNullOrEmpty(userProfileTemporary.PushUserId)) { return new NotificationCreateResult(); } if (title == null) { title = ""; } if (body == null) { body = ""; } var client = new OneSignalClient(Consts.ONE_SIGNAL_API_KEY); // Use your Api Key var options = new NotificationCreateOptions { AppId = new Guid(Consts.ONE_SIGNAL_APP_ID), IncludePlayerIds = new List<string>() { userProfileTemporary.PushUserId }, // IncludedSegments = new List<string>() { "All" } // To send to all }; options.Headings.Add(LanguageCodes.English, title); options.Contents.Add(LanguageCodes.English, body.Replace("<br>", "\n").Replace("\n\n", "\n")); return await client.Notifications.CreateAsync(options); }
public async Task <ActionResult> AddBulk(FormCollection values) { OneSignalClient osc = new OneSignalClient(ConfigurationManager.AppSettings["push:OneSignalApiKey"]); var success = new List <Build>(); var failed = new List <string>(); bool notify = bool.Parse(values[nameof(BulkAddition.SendNotifications)].Split(',')[0]); foreach (string line in values[nameof(BulkAddition.Builds)].Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)) { Match m = Regex.Match(line, @"(([\d]{1,2})\.([\d]{1,2})\.)?([\d]{4,5})(\.([\d]{1,5}))?(\.| \()([a-zA-Z][a-zA-Z0-9._\(\)-]+?)\.(\d\d\d\d\d\d-\d\d\d\d)\)?"); if (m.Success) { try { Build b = new Build { MajorVersion = uint.Parse(m.Groups[2].Value), MinorVersion = uint.Parse(m.Groups[3].Value), Number = uint.Parse(m.Groups[4].Value), Revision = string.IsNullOrEmpty(m.Groups[6].Value) ? null : uint.Parse(m.Groups[6].Value) as uint?, Lab = m.Groups[8].Value, BuildTime = string.IsNullOrEmpty(m.Groups[9].Value) ? null : DateTime.SpecifyKind(DateTime.ParseExact(m.Groups[9].Value, "yyMMdd-HHmm", CultureInfo.CurrentCulture.DateTimeFormat), DateTimeKind.Utc) as DateTime?, Added = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), Modified = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), SourceType = TypeOfSource.PrivateLeak }; await _bModel.Insert(b); if (notify) { osc.PushNewBuild(b, $"https://buildfeed.net{Url.Action(nameof(ViewBuild), new { id = b.Id })}?utm_source=notification&utm_campaign=new_build"); } success.Add(b); } catch (Exception) { failed.Add(line); } } } ViewBag.Results = success.ToArray(); return(View(new BulkAddition { Builds = string.Join("\r\n", failed), SendNotifications = notify })); }
public async void Can_load_app() { using (var client = new OneSignalClient(Constants.ApiKey)) { var app = await client.Apps.View(Constants.TestAppId); app.Name.Should().Be(Constants.TestAppName); } }
public async void Can_load_all_apps() { using (var client = new OneSignalClient(Constants.ApiKey)) { var apps = await client.Apps.View(); apps.Should().NotBeEmpty(); } }
public void Delete(string notificationId) { var client = new OneSignalClient(ApiKey); var options = new NotificationCancelOptions { Id = notificationId, AppId = AppId }; client.Notifications.Cancel(options); }
public NotificationService(IOptions <NotificationSettings> notificationSettings) { _settings = notificationSettings.Value; _oneSignalClient = new OneSignalClient(_settings.ApiKey); _notificationCreateOptions = new NotificationCreateOptions { AppId = new Guid(_settings.AppId) }; }
public void ViewAllDeviceTest() { var client = new OneSignalClient("NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj"); var options = new DevicesViewOptions(); options.AppId = new Guid("92911750-242d-4260-9e00-9d9034f139ce"); var data = client.Devices.ViewAll(options); }
public void ViewSomeDeviceTest() { var client = new OneSignalClient("NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj"); var options = new DeviceViewOptions(); options.AppId = new Guid("92911750-242d-4260-9e00-9d9034f139ce"); options.Id = new Guid("2ea3339c-3113-4780-a2ce-524ea7d67651"); var data = client.Devices.View(options); }
private void EnviarPush(string nome) { var client = new OneSignalClient("NGFjNmJiNjgtNDUwYi00NTEwLTgyMDYtZWEyYzM1NGRjMGNm"); var options = new NotificationCreateOptions(); options.AppId = new Guid("1fc34bfe-eae4-468c-ba2e-a758b27be571"); options.IncludedSegments = new List <string> { "All" }; options.Contents.Add(LanguageCodes.English, "Um novo pedófilo foi encontrado: " + nome); client.Notifications.Create(options); }
public static async Task <string> OneSignalCancelPushNotification(string id, string appId, string restKey) { var client = new OneSignalClient(restKey); var opt = new NotificationCancelOptions() { AppId = appId, Id = id }; NotificationCancelResult result = await client.Notifications.CancelAsync(opt); return(result.Success); }
public static void PushNewBuild(this OneSignalClient osc, Build build, string url) { osc.Notifications.Create(new NotificationCreateOptions { AppId = Guid.Parse(ConfigurationManager.AppSettings["push:AppId"]), IncludedSegments = new List <string> { #if DEBUG "Testers" #else "All" #endif },
public async void Can_create_app() { using (var client = new OneSignalClient(Constants.ApiKey)) { var name = "[test] " + Guid.NewGuid(); var app = await client.Apps.Create(new ViewDevicesRequest { Name = name }); app.Name.Should().Be(name); } }
public static async Task <string> OneSignalPushNotification(CreateNotificationModel request, Guid appId, string restKey) { OneSignalClient client = new OneSignalClient(restKey); var opt = new NotificationCreateOptions() { AppId = appId, IncludePlayerIds = request.PlayerIds, SendAfter = DateTime.Now.AddSeconds(10) }; opt.Headings.Add(LanguageCodes.English, request.Title); opt.Contents.Add(LanguageCodes.English, request.Content); NotificationCreateResult result = await client.Notifications.CreateAsync(opt); return(result.Id); }
public void TestASimpleCall() { var client = new OneSignalClient(""); // Use your Api Key var options = new NotificationCreateOptions(); options.AppId = new Guid(""); // Use your AppId options.IncludePlayerIds = new List <string>() { "00000000-0000-0000-0000-000000000000" // Use your playerId }; options.Headings.Add(LanguageCodes.English, "New Notification!"); options.Contents.Add(LanguageCodes.English, "This will push a real notification directly to your device."); client.Notifications.Create(options); }
public async Task SendNotification(string header, string content, List <Guid> externalUserIds) { var client = new OneSignalClient(_apiKey); // Use your Api Key var options = new NotificationCreateOptions { AppId = new Guid(_appId), // Use your AppId IncludeExternalUserIds = externalUserIds.ConvertAll(x => x.ToString()) }; options.Headings.Add(LanguageCodes.English, header); options.Contents.Add(LanguageCodes.English, content); await client.Notifications.CreateAsync(options); await SaveNotification(content, header, null, NotificationType.NormalNotification, true, null, externalUserIds); }
public async Task SendUnitTest() { var client = new OneSignalClient("<api key>"); var options = new NotificationCreateOptions { AppId = new Guid("<app id>"), IncludedSegments = new List <string> { "All" } }; options.Contents.Add(LanguageCodes.English, "Hello World"); var result = await client.Notifications.CreateAsync(options).ConfigureAwait(true); }
public string Send(string Message, string Url, List <int> FilterUserIds, DateTime?StartingDate, DateTime?EndingDate, string title = "Sistem Portal") { var client = new OneSignalClient(ApiKey); var options = new NotificationCreateOptions { Filters = new List <INotificationFilter>(), AppId = Guid.Parse(AppId) }; options.SendAfter = StartingDate; if (EndingDate != null) { options.TimeToLive = EndingDate.Value.Subtract(DateTime.Now).Days; } var index = 0; foreach (var FilterUserId in FilterUserIds) { index++; options.Filters.Add(new NotificationFilterField { Field = NotificationFilterFieldTypeEnum.Tag, Key = "Id", Relation = "=", Value = FilterUserId.ToString() }); if (index != FilterUserIds.Count) { options.Filters.Add(new NotificationFilterOperator { Operator = "OR" }); } } options.Headings.Add(LanguageCodes.English, title); options.Contents.Add(LanguageCodes.English, Message); options.Url = Url; var returnNotificationId = client.Notifications.Create(options); return(returnNotificationId.Id); }
public async Task SendNotification(string header, string content, string includedSegments) { var client = new OneSignalClient(_apiKey); // Use your Api Key var options = new NotificationCreateOptions { AppId = new Guid(_appId), // Use your AppId IncludedSegments = new string[] { includedSegments } }; options.Headings.Add(LanguageCodes.English, header); options.Contents.Add(LanguageCodes.English, content); await client.Notifications.CreateAsync(options); await SaveNotification(content, header, null, NotificationType.NormalNotification, true, includedSegments, new List <Guid>()); }
// Otra forma de hacerlo con el SDK public ActionResult Index_SDK() { var client = new OneSignalClient("Y2Y1MDFlZTktNjk3My00NTAxLWE3OTctYTAyN2ExNDQ1OTE0"); var options = new OneSignal.CSharp.SDK.Resources.Notifications.NotificationCreateOptions() { AppId = Guid.Parse("444ebbf4-2456-48b8-9b03-95bd9df4bb0d"), IncludedSegments = new List <string> { "All" } }; options.Contents.Add(LanguageCodes.Spanish, "Juan Perez aplicó a tu oferta"); NotificationCreateResult ret = client.Notifications.Create(options); return(View()); }
public async void Cannot_create_invalid_app() { OneSignalApiException error = null; using (var client = new OneSignalClient(Constants.ApiKey)) { try { var app = await client.Apps.Create(new ViewDevicesRequest()); }catch (OneSignalApiException ex) { error = ex; } error.Should().NotBeNull(); error.Response.Errors.Should().Contain("Name Enter an app name"); } }
/// <summary> /// Pushes the message. /// </summary> /// <param name="sender">The sender.</param> /// <param name="to">To.</param> /// <param name="emailMessage">The email message.</param> /// <param name="mergeFields">The merge fields.</param> //private void PushMessage( Sender sender, List<string> to, RockPushMessage pushMessage, Dictionary<string, object> mergeFields ) private void PushMessage(List <string> to, RockPushMessage pushMessage, Dictionary <string, object> mergeFields) { string title = ResolveText(pushMessage.Title, pushMessage.CurrentPerson, pushMessage.EnabledLavaCommands, mergeFields, pushMessage.AppRoot, pushMessage.ThemeRoot); string sound = ResolveText(pushMessage.Sound, pushMessage.CurrentPerson, pushMessage.EnabledLavaCommands, mergeFields, pushMessage.AppRoot, pushMessage.ThemeRoot); string message = ResolveText(pushMessage.Message, pushMessage.CurrentPerson, pushMessage.EnabledLavaCommands, mergeFields, pushMessage.AppRoot, pushMessage.ThemeRoot); string appId = GetAttributeValue("AppId"); string restApiKey = GetAttributeValue("RestAPIKey"); OneSignalClient client = new OneSignalClient(restApiKey); var options = new NotificationCreateOptions { AppId = new Guid(appId), IncludeExternalUserIds = to }; options.Headings.Add(LanguageCodes.English, title); options.Contents.Add(LanguageCodes.English, message); client.Notifications.Create(options); }
public void CreateSimpleNotificationTest() { var client = new OneSignalClient("NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj"); var options = new NotificationCreateOptions(); options.AppId = new Guid("92911750-242d-4260-9e00-9d9034f139ce"); options.IncludedSegments = new List <string> { "All" }; //options.IncludePlayerIds = new List<string> //{ // "81a9b7d9-6ee0-47f8-9045-318df82b1ba1" //}; options.Headings.Add(LanguageCodes.English, "✴️ เริ่มแล้ว Promotion ฉลองเปิดระบบ (beta test) ‼️"); options.Contents.Add(LanguageCodes.English, "ด่วน ❗ เพียง 12 ทีมแรกเท่านั้น ► ชวนเพื่อนๆ รวมเป็นทีมเดียวกันตั้งแต่ 5 คนขึ้นไป รับทันทีทีมละ 5,000 Points"); options.Url = "http://the10threalm.com/"; client.Notifications.Create(options); }
private void SendUyariKapi() { var client = new OneSignalClient("NjVmODdkMmEtZTlkNy00MDNhLTk4MzQtNGE1ZmI0YmU0ODQ3"); var options = new NotificationCreateOptions(); options.AppId = Guid.Parse("03c0d86b-b918-49f6-b85e-442303146b60"); options.IncludedSegments = new List <string> { "All" }; options.Contents.Add(LanguageCodes.English, "Kapı Açık Unutuldu"); client.Notifications.Create(options); db.UYARI.Add(new UYARI { GONDERILME_TARIHI = DateTime.Now, MESSAGE = "Kapı Açık Unutuldu" }); db.SaveChanges(); }