示例#1
0
 def send_to_token(self, data, token):
     message = messaging.Notification(title="Chrysus Payment",
                                      body=data['message'])
     message = messaging.Message(data=data,
                                 token=token,
                                 notification=message)
     response = messaging.send(message)
     return response
示例#2
0
    def send_notification_device(
        self, registration_token="", title="", body="", url=""
    ):
        message = messaging.Message(
            data={"title": title, "body": body, "url": url}, token=registration_token,
        )

        response = messaging.send(message)
示例#3
0
def __createMessage__(token, request_data):
    notification = __create_notification__(request_data)
    if notification is None and request_data.get('data') is None:
        return None

    return messaging.Message(data=request_data.get('data'),
                             token=token,
                             notification=notification)
示例#4
0
    def sendNotif(self, token, title, body):
        notif = messaging.Notification(title=title, body=body)

        msg = messaging.Message(notification=notif, token=token)

        response = messaging.send(message=msg)

        print("Notif sent with response:", response)
 def test_invalid_collapse_key(self, data):
     with pytest.raises(ValueError) as excinfo:
         check_encoding(
             messaging.Message(
                 topic='topic',
                 android=messaging.AndroidConfig(collapse_key=data)))
     assert str(
         excinfo.value) == 'AndroidConfig.collapse_key must be a string.'
示例#6
0
def send_to_topic(topc, content, title):
    topic = topc
    message = messaging.Message(
        notification=messaging.Notification(title=title, body=content),
        topic=topic,
    )
    response = messaging.send(message)
    print('Successfully sent message:', response)
示例#7
0
def file_convert_push(tokens, file_id, file_name, from_ext, to_ext):
    return messaging.Message(
        data={
            NOTIFICATION_ID: CONVERT_NOTIFICATION_ID,
            TITLE: TITLE_CONVERSION_SUCCESS,
            BODY: BODY_CONVERSION_SUCCESS.format(file_name, from_ext, file_name, to_ext),
            FILE_ID: f'{file_id}',
        }, token=tokens)
 def test_invalid_android_notification(self, data):
     with pytest.raises(ValueError) as excinfo:
         check_encoding(
             messaging.Message(
                 topic='topic',
                 android=messaging.AndroidConfig(notification=data)))
     expected = 'AndroidConfig.notification must be an instance of AndroidNotification class.'
     assert str(excinfo.value) == expected
 def test_invalid_webpush_notification(self, data):
     with pytest.raises(ValueError) as excinfo:
         check_encoding(
             messaging.Message(
                 topic='topic',
                 webpush=messaging.WebpushConfig(notification=data)))
     expected = 'WebpushConfig.notification must be an instance of WebpushNotification class.'
     assert str(excinfo.value) == expected
示例#10
0
def message_app(data, game_id):
    players_list = PlayerInGame.query.filter_by(game_id=game_id).all()

    for player in players_list:
        message = messaging.Message(data=data, token=player.device_id)
        response = messaging.send(message)

    return response
 def _check_alert(self, alert):
     with pytest.raises(ValueError) as excinfo:
         check_encoding(
             messaging.Message(
                 topic='topic',
                 apns=messaging.APNSConfig(payload=messaging.APNSPayload(
                     aps=messaging.Aps(alert=alert)))))
     return excinfo
 def test_invalid_priority(self, data):
     with pytest.raises(ValueError) as excinfo:
         check_encoding(messaging.Message(
             topic='topic', android=messaging.AndroidConfig(priority=data)))
     if isinstance(data, six.string_types):
         assert str(excinfo.value) == 'AndroidConfig.priority must be "high" or "normal".'
     else:
         assert str(excinfo.value) == 'AndroidConfig.priority must be a non-empty string.'
示例#13
0
    def send_message(self, message_title, message_body, data=None):
        """
        Send a notification to the device registered with this firebase id.
        If the firebase id is not in use anymore, we remove the registration
        from the database.
        :param message_title: Title of the notification
        :param message_body: Content of the notification
        :param data: Data segment of a Firebase message (see the docs)
        :return: None
        """
        if data is None:
            data = {}

        if not firebase_app:
            _logger.error("google_application_credentials is not correctly "
                          "configured in odoo.conf or invalid. Skipping "
                          "sending notifications")
            return False

        notif = messaging.Notification(title=message_title, body=message_body)

        for firebase_id in self:
            data.update({
                'title': message_title,
                'body': message_body,
            })

            message = messaging.Message(notification=notif,
                                        data=data,
                                        token=firebase_id.registration_id)
            try:
                messaging.send(message=message)
            except (messaging.QuotaExceededError,
                    messaging.SenderIdMismatchError,
                    messaging.ThirdPartyAuthError,
                    messaging.UnregisteredError) as ex:
                _logger.error(ex)
                # Save error in ir.logging to allow tracking of errors
                self.env['ir.logging'].create({
                    'name':
                    'Firebase ' + ex.__class__.__name__,
                    'type':
                    'server',
                    'message':
                    ex,
                    'path':
                    '/firebase_connector/models/firebase_regitration.py',
                    'line':
                    '100',
                    'func':
                    'send_message'
                })
                if ex.code == 'NOT_FOUND':
                    _logger.debug(
                        "A device is not reachable from Firebase, unlinking."
                        "Firebase ID: %s" % firebase_id)
                    firebase_id.unlink()
        return True
示例#14
0
def send_message(title, body, topic):
    config = messaging.AndroidConfig(ttl=12 * 60 * 60, collapse_key=topic)
    msg = messaging.Message(data={
        'title': title,
        'body': body
    },
                            android=config,
                            topic=topic)
    return messaging.send(msg, False, app)
 def test_invalid_aps(self, data):
     with pytest.raises(ValueError) as excinfo:
         check_encoding(
             messaging.Message(
                 topic='topic',
                 apns=messaging.APNSConfig(payload=messaging.APNSPayload(
                     aps=data))))
     expected = 'APNSPayload.aps must be an instance of Aps class.'
     assert str(excinfo.value) == expected
 def test_invalid_package_name(self, data):
     with pytest.raises(ValueError) as excinfo:
         check_encoding(
             messaging.Message(topic='topic',
                               android=messaging.AndroidConfig(
                                   restricted_package_name=data)))
     assert str(
         excinfo.value
     ) == 'AndroidConfig.restricted_package_name must be a string.'
示例#17
0
def send_order_to_vendor(result, fcm_token):
    try:
        app = firebase_admin.get_app()
    except ValueError as e:
        cred = credentials.Certificate("serviceAccountKey.json")
        firebase_admin.initialize_app(cred)
    msg = messaging.Message(data={'message': 'New Order'}, token=fcm_token)
    msg_id = messaging.send(msg)
    return msg_id
示例#18
0
def send_notification(title, body, token):
    message = messaging.Message(
        notification=messaging.Notification(
            title=title, body=body),
        token=token,
    )

    response = messaging.send(message)
    print('Successfully sent message:', response)
示例#19
0
    def send_message_to_topic(self, message, topic):

        firebase_message = messaging.Message(
            data={'message': message},
            topic=topic,
        )

        response = messaging.send(firebase_message)
        print("successfully sent ", response)
示例#20
0
文件: main.py 项目: hs2361/horario
def success() -> str:
    print(request.json)
    message = messaging.Message(
        notification=messaging.Notification(title=request.json['title'],
                                            body=request.json['body']),
        topic=request.json['topic'],
    )
    response = messaging.send(message)
    return f"Successfully sent message:{response}"
示例#21
0
def notify(device):
    msg = messaging.Message(notification=messaging.Notification(
        title=device,
        body="device is in dangrous state",
    ),
                            topic='danger_notification')
    response = messaging.send(msg)
    # Response is a message ID string.
    print('Successfully sent message:', response)
示例#22
0
def sendMessage(title, link):
    message = messaging.Message(topic='efb',
                                data={
                                    'title': title,
                                    'link': link
                                })

    messaging.send(message)
    print("Message sent: " + title)
 def test_invalid_ttl(self, data):
     with pytest.raises(ValueError) as excinfo:
         check_encoding(messaging.Message(
             topic='topic', android=messaging.AndroidConfig(ttl=data)))
     if isinstance(data, numbers.Number):
         assert str(excinfo.value) == ('AndroidConfig.ttl must not be negative.')
     else:
         assert str(excinfo.value) == ('AndroidConfig.ttl must be a duration in seconds or '
                                       'an instance of datetime.timedelta.')
示例#24
0
def send_notification(topic):
    message = random.choice(messages)
    title = message[0]
    body = message[1]
    message = messaging.Message(notification=messaging.Notification(
        title=title, body=body),
                                topic=topic)
    res = messaging.send(message)
    print('message response : {}'.format(res))
示例#25
0
    def sendRefreshRequest(self, registrationId, conv_Id):
        #First making the message
        tempMessage = messaging.Message(data={"conv_Id": conv_Id},
                                        token=registrationId)

        #Now sending the message to the device with the corresponding ID
        response = messaging.send(tempMessage)
        print("FirebaseHandler sendMessage response: " + response)
        print("FirebaseHandler send RegistrationId: " + registrationId)
示例#26
0
    def send_message(self, device_id, data):
        notification = messaging.Notification(title=data['title'],
                                              body=data['body'])
        message = messaging.Message(notification=notification,
                                    token=device_id,
                                    data=data.get('dataContent'))
        response = messaging.send(message)

        return response
 def test_send(self):
     self.fcm_service._client.session.mount(
         'https://fcm.googleapis.com',
         testutils.MockAdapter(json.dumps({'name': 'message-id'}), 200,
                               self.recorder))
     msg = messaging.Message(topic='foo')
     messaging.send(msg)
     assert len(self.recorder) == 1
     assert self.recorder[0]._extra_kwargs['timeout'] == 4
示例#28
0
 def send_to_topic(self, topic, title, body, image, html):
     message = messaging.Message(
         data=dict(html=html),
         notification=messaging.Notification(title=title,
                                             body=body,
                                             image=image),
         topic=topic,
     )
     messaging.send(message)
示例#29
0
def send_notification(db, user, question):
    """Sends a notification to the user's device"""
    if user.get("notification_token"):
        messaging.send(
            messaging.Message(
                notification=messaging.Notification(title="Aida",
                                                    body=question),
                token=user["notification_token"],
            ))
示例#30
0
def notifySenderMessageRead(fb, token):
    androidNotification = messaging.AndroidNotification(
        sound="default", click_action="FCM_PLUGIN_ACTIVITY")
    androidConfig = messaging.AndroidConfig(collapse_key="key",
                                            priority="high",
                                            notification=androidNotification)
    message = messaging.Message(data={"action": ACTION_MESSAGE_READ},
                                token=token)
    messaging.send(message, dry_run=False, app=fb)