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); }
// 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); }
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) { } }
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); }
/// <summary> /// Creates new notification to be sent by OneSignal system. /// </summary> /// <param name="options">Options used for notification create operation.</param> /// <returns></returns> public NotificationCreateResult Create(NotificationCreateOptions options) { RestRequest restRequest = new RestRequest("notifications", Method.POST); restRequest.AddHeader("Authorization", string.Format("Basic {0}", base.ApiKey)); restRequest.RequestFormat = DataFormat.Json; restRequest.JsonSerializer = new NewtonsoftJsonSerializer(); restRequest.AddBody(options); IRestResponse <NotificationCreateResult> restResponse = base.RestClient.Execute <NotificationCreateResult>(restRequest); if (!(restResponse.StatusCode != HttpStatusCode.Created || restResponse.StatusCode != HttpStatusCode.OK)) { if (restResponse.ErrorException != null) { throw restResponse.ErrorException; } else if (restResponse.StatusCode != HttpStatusCode.OK && restResponse.Content != null) { throw new Exception(restResponse.Content); } } return(restResponse.Data); }
public async Task <NotificationCreateResult> CreateAsync([NotNull] NotificationCreateOptions options, [NotNull] string appName = ElectOneSignalConstants.DefaultAppName) { var appInfo = Options.Apps.Single(x => x.AppName == appName); options.AppId = appInfo.AppId; try { var result = await ElectOneSignalConstants.DefaultApiUrl .ConfigureRequest(config => { config.JsonSerializer = ElectOneSignalConstants.NewtonsoftJsonSerializer; }) .AppendPathSegment("notifications") .WithHeader("Authorization", $"Basic {appInfo.ApiKey}") .PostJsonAsync(options) .ReceiveJson <NotificationCreateResult>() .ConfigureAwait(true); return(result); } catch (FlurlHttpException e) { var response = await e.GetResponseStringAsync().ConfigureAwait(true); throw new HttpRequestException(response); } }
private OneSignalNotificationService() { _oneSignalClient = new OneSignalClient(OneSignalId); _notificationCreateOptions = new NotificationCreateOptions(); _notificationCreateOptions.AppId = Guid.Parse(this.ApiId); }
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); }
public NotificationService(IOptions <NotificationSettings> notificationSettings) { _settings = notificationSettings.Value; _oneSignalClient = new OneSignalClient(_settings.ApiKey); _notificationCreateOptions = new NotificationCreateOptions { AppId = new Guid(_settings.AppId) }; }
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 async Task BroadcastNotificationAsync(string notifcationMessage) { var options = new NotificationCreateOptions(); options.AppId = Guid.Parse(_appId); options.IncludedSegments = new List <string> { "All" }; options.Contents.Add(LanguageCodes.English, notifcationMessage); options.DeliverToAndroid = true; await Task.Run(() => _notificationClient.Notifications.Create(options)); }
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 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 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 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 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>()); }
/// <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(); }
public int SendOneSignalPushNotification(List <string> playerIds, User user, string message) { // OneSignal Notification Generator var client = new OneSignalClient(AppConstants.OneSignalApiKey); // Use your Api Key var options = new NotificationCreateOptions { AppId = new Guid(AppConstants.OneSignalAppId), // Use your AppId IncludePlayerIds = playerIds // new List<string>() // { // "00000000-0000-0000-0000-000000000000" // Use your playerId // } }; options.Headings.Add(LanguageCodes.English, "New Notification!"); options.Contents.Add(LanguageCodes.English, message + " from " + user.Name); var response = client.Notifications.Create(options); return(response.Recipients); }
public static async Task <string> OneSignalPushNotification(CreateNotificationModel request, Guid appId, string restKey) { var client = new OneSignalClient(restKey); var opt = new NotificationCreateOptions() { AppId = appId, IncludedSegments = new string[] { "Subscribed Users" } }; opt.Headings.Add(LanguageCodes.English, request.Title); opt.Contents.Add(LanguageCodes.English, request.Content); try { NotificationCreateResult result = await client.Notifications.CreateAsync(opt); return(result.Id); } catch (Exception ex) { throw; } }
/// <summary> /// Sends the specified communication from the Communication Wizard in Rock. /// </summary> /// <param name="communication">The communication.</param> /// <param name="mediumEntityTypeId">The medium entity type identifier.</param> /// <param name="mediumAttributes">The medium attributes.</param> /// <exception cref="System.NotImplementedException"></exception> public override void Send(Model.Communication communication, int mediumEntityTypeId, Dictionary <string, string> mediumAttributes) { using (var communicationRockContext = new RockContext()) { // Requery the Communication communication = new CommunicationService(communicationRockContext) .Queryable("CreatedByPersonAlias.Person") .FirstOrDefault(c => c.Id == communication.Id); bool hasPendingRecipients; if (communication != null && communication.Status == Model.CommunicationStatus.Approved && (!communication.FutureSendDateTime.HasValue || communication.FutureSendDateTime.Value.CompareTo(RockDateTime.Now) <= 0)) { var qryRecipients = new CommunicationRecipientService(communicationRockContext).Queryable(); hasPendingRecipients = qryRecipients .Where(r => r.CommunicationId == communication.Id && r.Status == Model.CommunicationRecipientStatus.Pending && r.MediumEntityTypeId.HasValue && r.MediumEntityTypeId.Value == mediumEntityTypeId) .Any(); } else { hasPendingRecipients = false; } if (hasPendingRecipients) { var currentPerson = communication.CreatedByPersonAlias?.Person; var globalAttributes = GlobalAttributesCache.Get(); string publicAppRoot = globalAttributes.GetValue("PublicApplicationRoot").EnsureTrailingForwardslash(); var mergeFields = Lava.LavaHelper.GetCommonMergeFields(null, currentPerson); var personEntityTypeId = EntityTypeCache.Get("Rock.Model.Person").Id; var communicationEntityTypeId = EntityTypeCache.Get("Rock.Model.Communication").Id; var communicationCategoryId = CategoryCache.Get(Rock.SystemGuid.Category.HISTORY_PERSON_COMMUNICATIONS.AsGuid(), communicationRockContext).Id; bool recipientFound = true; while (recipientFound) { // make a new rockContext per recipient var recipientRockContext = new RockContext(); var recipient = Model.Communication.GetNextPending(communication.Id, mediumEntityTypeId, recipientRockContext); if (recipient != null) { if (ValidRecipient(recipient, communication.IsBulkCommunication)) { if (recipient.PersonAliasId.HasValue) { try { var mergeObjects = recipient.CommunicationMergeValues(mergeFields); var message = ResolveText(communication.PushMessage, currentPerson, communication.EnabledLavaCommands, mergeObjects, publicAppRoot); var title = ResolveText(communication.PushTitle, currentPerson, communication.EnabledLavaCommands, mergeObjects, publicAppRoot); var sound = ResolveText(communication.PushSound, currentPerson, communication.EnabledLavaCommands, mergeObjects, publicAppRoot); var data = ResolveText(communication.PushData, currentPerson, communication.EnabledLavaCommands, mergeFields, publicAppRoot); var jsonData = Newtonsoft.Json.JsonConvert.DeserializeObject <PushData>(data); var url = jsonData.Url; string appId = GetAttributeValue("AppId"); string restApiKey = GetAttributeValue("RestAPIKey"); OneSignalClient client = new OneSignalClient(restApiKey); var options = new NotificationCreateOptions { AppId = new Guid(appId), IncludeExternalUserIds = new List <string> { recipient.PersonAliasId.ToString() } }; options.Headings.Add(LanguageCodes.English, title); options.Contents.Add(LanguageCodes.English, message); options.Url = url; NotificationCreateResult response = client.Notifications.Create(options); bool failed = !string.IsNullOrWhiteSpace(response.Error); var status = failed ? CommunicationRecipientStatus.Failed : CommunicationRecipientStatus.Delivered; if (failed) { recipient.StatusNote = "OneSignal failed to notify devices"; } else { recipient.SendDateTime = RockDateTime.Now; } recipient.Status = status; recipient.TransportEntityTypeName = this.GetType().FullName; recipient.UniqueMessageId = response.Id; try { var historyService = new HistoryService(recipientRockContext); historyService.Add(new History { CreatedByPersonAliasId = communication.SenderPersonAliasId, EntityTypeId = personEntityTypeId, CategoryId = communicationCategoryId, EntityId = recipient.PersonAlias.PersonId, Verb = History.HistoryVerb.Sent.ConvertToString().ToUpper(), ChangeType = History.HistoryChangeType.Record.ToString(), ValueName = "Push Notification", Caption = message.Truncate(200), RelatedEntityTypeId = communicationEntityTypeId, RelatedEntityId = communication.Id }); } catch (Exception ex) { ExceptionLogService.LogException(ex, null); } } catch (Exception ex) { recipient.Status = CommunicationRecipientStatus.Failed; recipient.StatusNote = "OneSignal Exception: " + ex.Message; } } } recipientRockContext.SaveChanges(); } else { recipientFound = false; } } } } }