Exemplo n.º 1
0
 def test_send_notification(self, client: Client,
                            ok_response: MockHttpxResponse):
     body = {'contents': {'en': 'hey there'}}
     with mock.patch('httpx.request',
                     side_effect=mock_request(
                         response=ok_response,
                         expected_auth_token=self.REST_API_KEY,
                         expected_method='POST',
                         expected_in_path='/notification',
                         required_body={
                             'app_id': self.APP_ID,
                             **body,
                         })):
         response = client.send_notification(body)
         assert response.status_code == 200
         assert response.body['success']
Exemplo n.º 2
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)