Exemplo n.º 1
0
    def enviar_notificacion_onesignal(self, notificacion):
        ajuste = self.db.query(Ajuste).first()
        print("Enviando Notificacion a un solo cliente")

        try:
            # Parametros
            APP_ID = ajuste.app_id
            REST_API_KEY = ajuste.rest_api_key
            CHANNEL_ID = ajuste.channel_id  # DE LA CATEGORIA PRIORITARY
            cli = notificacion.receptor.token_notificacion
            if cli and cli != 'undefined' and cli != '0':
                print('Token..:')
                print(cli)

                client = Client(app_id=APP_ID, rest_api_key=REST_API_KEY)
                img = ''
                notification_body = {
                    'contents': {'en': notificacion.mensaje, 'es': notificacion.mensaje},
                    # 'subtitle': {'en': n.subtitle, 'es': n.subtitle}, // Si se quiere agregar un subtitulo
                    'headings': {'en': notificacion.titulo, 'es': notificacion.titulo},
                    # 'included_segments': ['Active Users', 'Inactive Users'], // cuando se especifica el include_player_ids, los segmentos ya no se envian
                    'include_player_ids': [cli],
                    'big_picture': img,  # Foto cuando la notificacion se expande
                    'small_icon': 'icon',  # Icono de la notificacion
                    # 'android_accent_color': '0065ab',# Color de fondo del small_icon
                    # 'huawei_accent_color': '0065ab',# Color de fondo del small_icon
                    'huawei_small_icon': 'icon',
                    'large_icon': img,  # Foto con la notificacion sin expandirse
                    'huawei_large_icon': img,  # Foto con la notificacion sin expandirse
                    'android_channel_id': CHANNEL_ID,  # Categoria de la notificacion definida en OneSignal
                    'huawei_channel_id': CHANNEL_ID,  # Categoria de la notificacion definida en OneSignal
                    'android_background_layout': '{"headings_color": "FFFF0000", "contents_color": "FF00FF00"}'
                }
                print('Cuerpo de la Notificacion..')
                print('..')
                print('..')
                print(notification_body)
                print('..')
                print('..')
                response = client.send_notification(notification_body)
                # print('Notificacion enviada: ')
                # print(response)
                # self.deshabilitar_notificacion(n)
        except OneSignalHTTPError as e:
            print("Error al enviar la notificacion: " + str(notificacion.id) + ' ' + str(notificacion.titulo))
            print(e)
            print(e.message)
Exemplo n.º 2
0
 def client(self):
     return Client(self.APP_ID, self.REST_API_KEY, self.USER_AUTH_TOKEN)
Exemplo n.º 3
0
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_socketio import SocketIO
from onesignal_sdk.client import Client

from WebPortal.Config.ConfigFlask import Config
from WebPortal.Config.ConfigOneSignal import ConfigOneSignal

db = SQLAlchemy()
bcrypt = Bcrypt()
loginMan = LoginManager()
SocketIOClient = SocketIO()
OneSignalClient = Client(app_id=ConfigOneSignal.App_ID,
                         rest_api_key=ConfigOneSignal.Rest_API_Key)


def create_WebPortal(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(Config)

    db.init_app(app)
    bcrypt.init_app(app)
    loginMan.init_app(app)
    SocketIOClient.init_app(app)

    from WebPortal.Authentication.routes import Authentication
    from WebPortal.Usercontrol.routes import UserControl
    from WebPortal.MainPage.routes import MainPage
    from WebPortal.Notifications.routes import Notifications
Exemplo n.º 4
0
from django.conf import settings

from onesignal_sdk.client import Client
from onesignal_sdk.error import OneSignalHTTPError

ONESIGNAL_APP_ID = settings.ONESIGNAL_APP_ID
ONESIGNAL_REST_API_KEY = settings.ONESIGNAL_REST_API_KEY

onesignal_client = Client(app_id=ONESIGNAL_APP_ID,
                          rest_api_key=ONESIGNAL_REST_API_KEY)


def send_notification(notification_body):
    try:
        onesignal_client.send_notification(notification_body)
    except OneSignalHTTPError as e:
        pass