def test_csv_export_is_successful(self, fake_request): client = onesignal.Client(user_auth_key=self.USER_AUTH_KEY, app_id=self.APP_ID, app_auth_key=self.APP_AUTH_KEY) response = client.csv_export() self.assertEqual(response.status_code, 200)
def test_track_open_is_successful(self, fake_request): client = onesignal.Client(user_auth_key=self.USER_AUTH_KEY, app_id=self.APP_ID, app_auth_key=self.APP_AUTH_KEY) response = client.track_open("123", {"opened": True}) self.assertEqual(response.status_code, 200)
def test_update_device_is_successful(self, fake_request): client = onesignal.Client(user_auth_key=self.USER_AUTH_KEY, app_id=self.APP_ID, app_auth_key=self.APP_AUTH_KEY) response = client.update_device("132", {"device_type": 2}) self.assertEqual(response.status_code, 200)
def send_notification(text): onesignal_client = onesignal.Client(app_auth_key="N2E4NTNkNzAtYjhjYi00ZTI0LWIzZWUtYTM1YmIyMmQxNzE4", app_id="1784a5bd-7107-4bda-b628-a19c2034159e") new_notification = onesignal.Notification(post_body={"contents": {"en": text}}) new_notification.post_body["included_segments"] = ["Active Users"] new_notification.post_body["headings"] = {"en": "Din Dong!"} onesignal_client.send_notification(new_notification)
def enviar_notificacao(notificacao): onesignal_client = onesignal_sdk.Client( user_auth_key=settings.ONESIGNAL_AUTH_ID, app={ 'app_auth_key': settings.ONESIGNAL_API_KEY, 'app_id': settings.ONESIGNAL_APP_ID }) # create a notification nova_notificacao = onesignal_sdk.Notification( contents={ 'en': notificacao['mensagem'], 'pt-br': notificacao['mensagem'] }) nova_notificacao.set_parameter('headings', { 'en': notificacao['titulo'], 'pt-br': notificacao['titulo'] }) nova_notificacao.set_parameter('url', settings.APP_URL + notificacao['url']) nova_notificacao.set_target_devices([notificacao['user_id']]) # send notification, it will return a response onesignal_response = onesignal_client.send_notification(nova_notificacao) print(onesignal_response.status_code) print(onesignal_response.json())
def parent_appointment_notification(parent, professional, appointment, booked): """ Used to send parents notifications about children assigned lessons. :param parent: :param child: :param lesson: :return: """ onesignal_client = onesignal_sdk.Client(user_auth_key=settings.PARENT_ONESIGNAL_AUTH_KEY, app={"app_auth_key": settings.PARENT_ONESIGNAL_REST_KEY, "app_id": settings.PARENT_ONESIGNAL_APP_ID}) # create a notification new_notification = onesignal_sdk.Notification() new_notification.set_parameter("contents", { "en": "Appointment with {} on {} from {} to {}, has been {}.".format(professional.profile.full_name, appointment.date.strftime('%m/%d/%Y'), appointment.start_time, appointment.end_time, booked)}) new_notification.set_parameter("headings", {"en": "MOTUS: Appointment {}".format(booked)}) new_notification.set_parameter("template_id", settings.PARENT_ONESIGNAL_APPOINTMENT_TEMPLATE_ID) # set filters new_notification.set_filters([{"field": "tag", "key": "id", "relation": "=", "value": str(parent.profile.user_id)}]) # send notification, it will return a response onesignal_response = onesignal_client.send_notification(new_notification) print(onesignal_response.status_code) print(onesignal_response.json())
def parent_new_lesson_notification(parent, child, lesson): """ Used to send parents notifications about children assigned lessons. :param parent: :param child: :param lesson: :return: """ onesignal_client = onesignal_sdk.Client(user_auth_key=settings.PARENT_ONESIGNAL_AUTH_KEY, app={"app_auth_key": settings.PARENT_ONESIGNAL_REST_KEY, "app_id": settings.PARENT_ONESIGNAL_APP_ID}) # create a notification new_notification = onesignal_sdk.Notification() new_notification.set_parameter("contents", { "en": "{} {} has been assigned lesson: {}.".format(child.first_name, child.last_name, lesson.lesson_name)}) new_notification.set_parameter("headings", {"en": "MOTUS: New assigned lesson!"}) new_notification.set_parameter("template_id", settings.PARENT_ONESIGNAL_NEW_LESSON_TEMPLATE_ID) # set filters new_notification.set_filters([{"field": "tag", "key": "id", "relation": "=", "value": str(parent.profile.user_id)}]) # send notification, it will return a response onesignal_response = onesignal_client.send_notification(new_notification) print(onesignal_response.status_code) print(onesignal_response.json())
def professional_resource_notification(data): """ Used to send professional notifications about new resources :param data: List of professional user IDs :return: """ filter_list = list() for i, item in enumerate(data): if i < len(data) - 1: filter_list.append({"field": "tag", "key": "id", "relation": "=", "value": str(item)}) filter_list.append({"operator": "OR"}) else: filter_list.append({"field": "tag", "key": "id", "relation": "=", "value": str(item)}) onesignal_client = onesignal_sdk.Client(user_auth_key=settings.PROFESSIONAL_ONESIGNAL_AUTH_KEY, app={"app_auth_key": settings.PROFESSIONAL_ONESIGNAL_REST_KEY, "app_id": settings.PROFESSIONAL_ONESIGNAL_APP_ID}) # create a notification new_notification = onesignal_sdk.Notification() new_notification.set_parameter("template_id", settings.PROFESSIONAL_ONESIGNAL_RESOURCES_TEMPLATE_ID) # set filters new_notification.set_filters(filter_list) # send notification, it will return a response onesignal_response = onesignal_client.send_notification(new_notification) print(onesignal_response.status_code) print(onesignal_response.json())
def test_update_app_is_successful(self, fake_request): client = onesignal.Client(user_auth_key=self.USER_AUTH_KEY, app_id=self.APP_ID, app_auth_key=self.APP_AUTH_KEY) response = client.update_app("123", {"name": "new_app"}) self.assertEqual(response.status_code, 200)
def send_sighting_onesignal_notification(data, notify_record, add_seen): filter_list = list() for i, item in enumerate(data): if i < len(data) - 1: filter_list.append({ "field": "tag", "key": "id", "relation": "=", "value": str(item) }) filter_list.append({"operator": "OR"}) else: filter_list.append({ "field": "tag", "key": "id", "relation": "=", "value": str(item) }) onesignal_client = onesignal_sdk.Client( user_auth_key=settings.ONESIGNAL_AUTH_KEY, app={ "app_auth_key": settings.ONESIGNAL_REST_KEY, "app_id": settings.ONESIGNAL_APP_ID }) # create a notification new_notification = onesignal_sdk.Notification() new_notification.set_parameter( "contents", { "en": "Potentially seen at {}. {}".format(add_seen.address, add_seen.description) }) new_notification.set_parameter("headings", { "en": "POTENTIAL SIGHTING: {}".format(notify_record.vulnerable.full_name) }) new_notification.set_parameter("template_id", settings.ONESIGNAL_SIGHTING_TEMPLATE_ID) print("{}/media/{}".format(settings.DOMAIN, notify_record.vulnerable.picture)) new_notification.set_parameter( "ios_attachments", { "id": "{}/media/{}".format(settings.DOMAIN, notify_record.vulnerable.picture) }) new_notification.set_parameter( "big_picture", "{}/media/{}".format(settings.DOMAIN, notify_record.vulnerable.picture)) # set filters new_notification.set_filters(filter_list) # send notification, it will return a response onesignal_response = onesignal_client.send_notification(new_notification) print(onesignal_response.status_code) print(onesignal_response.json())
def professional_new_lesson_notification(data, lesson): """ :param data: :param lesson: :return: """ filter_list = list() for i, item in enumerate(data): if i < len(data) - 1: filter_list.append({"field": "tag", "key": "id", "relation": "=", "value": str(item)}) filter_list.append({"operator": "OR"}) else: filter_list.append({"field": "tag", "key": "id", "relation": "=", "value": str(item)}) onesignal_client = onesignal_sdk.Client(user_auth_key=settings.PROFESSIONAL_ONESIGNAL_AUTH_KEY, app={"app_auth_key": settings.PROFESSIONAL_ONESIGNAL_REST_KEY, "app_id": settings.PROFESSIONAL_ONESIGNAL_APP_ID}) # create a notification new_notification = onesignal_sdk.Notification() new_notification.set_parameter("contents", { "en": "New lesson: '{}' can now be assigned.".format(lesson.lesson_name)}) new_notification.set_parameter("headings", {"en": "MOTUS: New lessons added!"}) new_notification.set_parameter("template_id", settings.PROFESSIONAL_ONESIGNAL_NEW_LESSON_TEMPLATE_ID) # set filters new_notification.set_filters(filter_list) # send notification, it will return a response onesignal_response = onesignal_client.send_notification(new_notification) print(onesignal_response.status_code) print(onesignal_response.json())
def create_notification_client(): onsignalSetting = OneSignalSetting.objects.all().first() if onsignalSetting: return onesignal_sdk.Client( app_auth_key=onsignalSetting.app_auth_key, app_id=onsignalSetting.app_id )
def professional_appointment_notification(professional, parent, appointment): """ Send professional appoint request push notifications. :param professional: :param parent: :param appointment: :return: """ onesignal_client = onesignal_sdk.Client(user_auth_key=settings.PROFESSIONAL_ONESIGNAL_AUTH_KEY, app={"app_auth_key": settings.PROFESSIONAL_ONESIGNAL_REST_KEY, "app_id": settings.PROFESSIONAL_ONESIGNAL_APP_ID}) # create a notification new_notification = onesignal_sdk.Notification() new_notification.set_parameter("contents", { "en": "Appointment request from {} on {} from {}-{}.".format(parent.profile.full_name, appointment.date.strftime('%m/%d/%Y'), appointment.start_time, appointment.end_time)}) new_notification.set_parameter("headings", {"en": "MOTUS: Appointment request"}) new_notification.set_parameter("template_id", settings.PROFESSIONAL_ONESIGNAL_APPOINTMENT_TEMPLATE_ID) # set filters new_notification.set_filters( [{"field": "tag", "key": "id", "relation": "=", "value": str(professional.profile.user_id)}]) # send notification, it will return a response onesignal_response = onesignal_client.send_notification(new_notification) print(onesignal_response.status_code) print(onesignal_response.json())
def test_view_notification_is_successful(self, fake_request): client = onesignal.Client(user_auth_key=self.USER_AUTH_KEY, app_id=self.APP_ID, app_auth_key=self.APP_AUTH_KEY) response = client.view_notification("123") self.assertEqual(response.status_code, 200)
def test_send_notification_has_post_body_params(self, fake_request): client = onesignal.Client(user_auth_key=self.USER_AUTH_KEY, app_id=self.APP_ID, app_auth_key=self.APP_AUTH_KEY) post_body = {"contents": {"en": "Message", "tr": "Mesaj"}} notification = onesignal.Notification(post_body) notification.post_body["included_segments"] = [ "Active Users", "Inactive Users" ] notification.post_body["filters"] = [{ "field": "tag", "key": "level", "relation": "=", "value": "10" }, { "operator": "OR" }, { "field": "tag", "key": "level", "relation": "=", "value": "20" }] response = client.send_notification(notification) self.assertEqual(response.status_code, 200)
def test_send_notification_without_app_id_fails(self): client = onesignal.Client(user_auth_key=self.USER_AUTH_KEY, app_auth_key=self.APP_AUTH_KEY) post_body = {"contents": {"en": "Message", "tr": "Mesaj"}} notification = onesignal.Notification(post_body) with self.assertRaises(onesignal.error.OneSignalError): response = client.send_notification(notification)
def configure_onesignal(): config = current_app.config onesignal_client = onesignal_sdk.Client( user_auth_key=config['ONESIGNAL_USER_AUTH_KEY'], app={ "app_auth_key": config['ONESIGNAL_APP_AUTH_KEY'], "app_id": config['ONESIGNAL_APP_ID'] }) return onesignal_client
def test_send_notification_has_app_id(self, fake_request): client = onesignal.Client(user_auth_key=self.USER_AUTH_KEY, app_id=self.APP_ID, app_auth_key=self.APP_AUTH_KEY) post_body = {"contents": {"en": "Message", "tr": "Mesaj"}} notification = onesignal.Notification(post_body) response = client.send_notification(notification) self.assertEqual(response.status_code, 200)
def __init__(self): """ Inicializa las claves de Onesignal :return: """ self.user_auth_key = properties.user_auth_key self.app_auth_key = properties.app_auth_key self.app_id = properties.app_id try: self.client = onesignal_sdk.Client(user_auth_key=self.user_auth_key, app={"app_auth_key": self.app_auth_key, "app_id": self.app_id}) except OneSignalError as e: print(e)
def post(self, request, format=None): ''' Send push notification to device ''' print('==== push notification: request_data: ', request.data) # registrationId = request.data['registrationId'] # deviceId = request.data['deviceId'] onesignal_user_id = request.data['onesignal_user_id'] notification = request.data['notification'] # Send GCM notification # device = FCMDevice.objects.create( # registration_id=registrationId, # # device_id=deviceId, # active=True, # type='ios' # ) # res = device.send_message( # title=notification['title'], # body=notification['body'], # data=notification['data'] # ) # print('====== res_notification: ', res) # device.delete() # Send Onsignal Push notification onsignalSetting = OneSignalSetting.objects.all().first() if onsignalSetting: onesignal_client = onesignal_sdk.Client( app_auth_key=onsignalSetting.app_auth_key, app_id=onsignalSetting.app_id ) new_notification = onesignal_sdk.Notification( post_body={ 'headings': {'en': notification['title']}, 'contents': {'en': notification['body']}, 'data': notification['data'], 'include_player_ids': [onesignal_user_id,], } ) # send notification, it will return a response onesignal_response = onesignal_client.send_notification(new_notification) print('====== onesignal_response.status_code: ', onesignal_response.status_code) print('====== onesignal_response.json: ', onesignal_response.json()) # Return 200 to rental service return Response(data=onesignal_response, status=200)
def send_found_onesignal_notification(data, notify_record): filter_list = list() for i, item in enumerate(data): if i < len(data) - 1: filter_list.append({ "field": "tag", "key": "id", "relation": "=", "value": str(item) }) filter_list.append({"operator": "OR"}) else: filter_list.append({ "field": "tag", "key": "id", "relation": "=", "value": str(item) }) onesignal_client = onesignal_sdk.Client( user_auth_key=settings.ONESIGNAL_AUTH_KEY, app={ "app_auth_key": settings.ONESIGNAL_REST_KEY, "app_id": settings.ONESIGNAL_APP_ID }) # create a notification new_notification = onesignal_sdk.Notification() new_notification.set_parameter( "contents", {"en": "{} has been found".format(notify_record.vulnerable.full_name)}) new_notification.set_parameter( "headings", {"en": "FOUND: {}".format(notify_record.vulnerable.full_name)}) new_notification.set_parameter("template_id", settings.ONESIGNAL_FOUND_TEMPLATE_ID) # set filters new_notification.set_filters(filter_list) # send notification, it will return a response onesignal_response = onesignal_client.send_notification(new_notification) print(onesignal_response.status_code) print(onesignal_response.json())
def send_one_signal(notification_title): onesignal_client = onesignal_sdk.Client( user_auth_key=ONESIGNAL_USER_AUTH_KEY, app_auth_key=ONESIGNAL_APP_AUTH_KEY, app_id=ONESIGNAL_APP_ID) # create a notification new_notification = onesignal_sdk.Notification( post_body={ "contents": { "en": notification_title, "tr": notification_title }, "included_segments": ["Subscribed Users"] }) # send notification, it will return a response onesignal_response = onesignal_client.send_notification(new_notification) print(onesignal_response.status_code) print(onesignal_response.json())
def notificate(title, message, onesignal_ids, params=None): onesignal_client = onesignal_sdk.Client( user_auth_key=settings.ONESIGNAL_USER_AUTH_KEY, app_auth_key=settings.ONESIGNAL_APP_AUTH_KEY, app_id=settings.ONESIGNAL_APP_ID) content = {"en": message} headings = {"en": title} new_notification = onesignal_sdk.Notification( post_body={"contents": { "en": message }}) new_notification.post_body["content"] = content new_notification.post_body["headings"] = headings new_notification.post_body["include_player_ids"] = onesignal_ids if params is not None: new_notification.post_body["data"] = params onesignal_client.send_notification(new_notification)
def notify_user(sender, recipient, msg): device_ids = recipient.device_set.all().values_list('device_id', flat=True) notification, created = Notification.objects.get_or_create( message=msg, sender=sender, recipient=recipient) if not created: return True if recipient.notifications and device_ids: client = onesignal.Client( app={ 'app_auth_key': settings.ONESIGNAL_APP_KEY, 'app_id': settings.ONESIGNAL_APP_ID }) notification = onesignal.Notification(contents={'en': msg}) notification.set_parameter('headings', {'en': 'FriendThem'}) notification.set_target_devices(list(device_ids)) response = client.send_notification(notification) return response.ok return recipient.notifications and bool(device_ids)
import firebase_admin from firebase_admin import credentials from firebase_admin import db import base64 import os import onesignal as onesignal_sdk cred = credentials.Certificate('/path/to/your/key.json') default_app = firebase_admin.initialize_app( cred, {'databaseURL': 'https://your-base.firebaseio.com'}) pusher_image = db.reference('/images') onesignal_client = onesignal_sdk.Client(user_auth_key="key", app={ "app_auth_key": "key", "app_id": "id" }) logging.config.dictConfig(LOGGING) logger = logging.getLogger('detector') class ImageCreator: def __init__(self, vid): self.win_name = 'Detector' self.cam = cv2.VideoCapture(vid) self.source_h = self.cam.get(cv2.CAP_PROP_FRAME_HEIGHT) self.source_w = self.cam.get(cv2.CAP_PROP_FRAME_WIDTH)
logging.getLogger().setLevel(app.config['LOG_LEVEL']) app.logger.info('Launching packet v' + app.config['VERSION']) app.logger.info('Using the {} realm'.format(app.config['REALM'])) # Initialize the extensions db = SQLAlchemy(app) migrate = Migrate(app, db) app.logger.info('SQLAlchemy pointed at ' + repr(db.engine.url)) APP_CONFIG = ProviderConfiguration(issuer=app.config['OIDC_ISSUER'], client_metadata=ClientMetadata(app.config['OIDC_CLIENT_ID'], app.config['OIDC_CLIENT_SECRET'])) # Initialize Onesignal Notification apps csh_onesignal_client = onesignal.Client(user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'], app_auth_key=app.config['ONESIGNAL_CSH_APP_AUTH_KEY'], app_id=app.config['ONESIGNAL_CSH_APP_ID']) intro_onesignal_client = onesignal.Client(user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'], app_auth_key=app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'], app_id=app.config['ONESIGNAL_INTRO_APP_ID']) # OIDC Auth auth = OIDCAuthentication({'app': APP_CONFIG}, app) # LDAP _ldap = csh_ldap.CSHLDAP(app.config['LDAP_BIND_DN'], app.config['LDAP_BIND_PASS']) # Sentry sentry_sdk.init( dsn=app.config['SENTRY_DSN'],
MAIL_USE_TLS=True, MAIL_USERNAME=EMAIL_USERNAME, MAIL_PASSWORD=EMAIL_PASSWORD) mail = Mail(app) #Global Variables used in Configuration if len(sys.argv) == 2 and sys.argv[1] == 'local': MONGO_URL = "mongodb://*****:*****@ds227243.mlab.com:27243/heroku_sxklq0jf' # Initiate OneSignal onesignal_client = onesignal_sdk.Client(user_auth_key=ONE_SIG_USER_AUTH_KEY, app={ "app_auth_key": ONE_SIG_APP_AUTH_KEY, "app_id": ONE_SIG_APP_ID }) # Assign variables to collections - see README for a description of each collection client1 = MongoClient(MONGO_URL) db = client1.heroku_sxklq0jf credentials = db.credentials people = db.people tasks = db.tasks goals = db.goals notifications = db.notifications social = db.social push_notifications = db.push_notifications
import json import time import urllib.request # from win10toast import ToastNotifier import webbrowser import onesignal as onesignal_sdk pageUrl = "https://www.roblox.com/catalog/json?Category=2&Subcategory=2&SortType=3&Direction=2&PageHash" \ "=0e4ba52b8fb2ab17f924d1fdc696e22d " knownItems = [] currentNotify = None onesignal_client = onesignal_sdk.Client( user_auth_key="ZTgwMzI1MjUtNjM5Yi00MTdkLWE4ODgtYjRlMWY4MGU2NTlj", app={ "app_auth_key": "ODMyYjcxYmEtMjI3Yi00NTNmLTllODctNjYwNjg2NTcyMjBh", "app_id": "0c25cbfd-3b76-4d31-bb5e-0febcef8a3b2" }) def getLimiteds(): page = urllib.request.urlopen(pageUrl).read() data = json.loads(page) # with open('catalog.json') as f: # data = json.load(f) limiteds = [] for x in data: if x["Remaining"] == "": continue
import onesignal as onesignal_sdk # For security you should load your app_api_key from enviroment variables app_id = '877d417d-3142-49d6-9823-87ac29a97486' app_api_key = 'ljksfhsdkjfhskjfhsfklasdfhslfskfjhslakfjsah' # Load OneSignal SDK onesignal_client = onesignal_sdk.Client(app={"app_auth_key": app_api_key, "app_id": app_id}) def send_push_notification(content,headings,url,player_ids): '''Send a push notification to one or multiple users content and headings must be dictionaries {"en": "Message",} url is a string players_id must be an array ''' new_notification = onesignal_sdk.Notification(contents=content) new_notification.set_parameter("include_player_ids",player_ids) new_notification.set_parameter("headings", headings) new_notification.set_parameter("url", url) # send notification, it will return a response onesignal_response = onesignal_client.send_notification(new_notification) return onesignal_response # Sample data content = {"en": "Julián, Your Python Developer vacancy has a new candidate. Click for details.", "es": "Julián, tu vacante Python Developer tiene una nueva postulación, haz clic para ver."} headings = {"en": "You have a new candidate.", "es": "Tienes un nuevo candidato."} player_ids = ['d8ebaaca-d443-4af3-8107-7cd3edeae917','61fd9d54-c432-482d-9010-eafb7b7acf16'] url = "https://test.myjobstudio.com/vacancy/myjobstudio/bla-bla-bla/56.html"
from hashlib import sha256 import onesignal as onesignal_sdk from django.conf import settings onesignal_client = onesignal_sdk.Client( app_id=settings.ONE_SIGNAL_APP_ID, app_auth_key=settings.ONE_SIGNAL_API_KEY) def send_notification_to_user(user, notification): for device in user.devices.all(): notification.set_parameter('ios_badgeType', 'Increase') notification.set_parameter('ios_badgeCount', '1') user_id_contents = (str(user.uuid) + str(user.id)).encode('utf-8') user_id = sha256(user_id_contents).hexdigest() notification.set_filters([ { "field": "tag", "key": "user_id", "relation": "=", "value": user_id }, { "field": "tag", "key": "device_uuid", "relation": "=", "value": device.uuid },