示例#1
0
def send_sms():
    application = create_app(
        os.getenv('NOTIFY_API_ENVIRONMENT') or 'development')
    with application.app_context():
        notifications = get_messages_from_queue('sms')
        for notification in notifications:
            if notification.message_attributes.get('type').get(
                    'StringValue') == 'sms':
                print("Processing SMS messages")
                try:
                    notification_body = json.loads(notification.body)
                    print("Processing {}".format(notification_body['id']))
                    print("notification: {}".format(notification.body))
                    (message_id,
                     sender) = sms_wrapper.send(notification_body['to'],
                                                notification_body['message'],
                                                notification_body['id'])
                    notification.delete()
                    __update_notification_to_sent(notification_body['id'],
                                                  message_id, sender)

                except ClientException as e:
                    print(e)
                    __update_notification_in_error(e, notification_body['id'],
                                                   e.sender)
示例#2
0
def send_email():
    application = create_app(
        os.getenv('NOTIFY_API_ENVIRONMENT') or 'development')
    with application.app_context():
        try:
            notifications = get_messages_from_queue('email')
            for notification in notifications:
                print("Processing Email messages")
                print("notification: {}".format(notification.body))
                if notification.message_attributes.get('type').get(
                        'StringValue') == 'email':
                    try:
                        notification_body = json.loads(notification.body)
                        (message_id, sender) = email_wrapper.send(
                            notification_body['to'],
                            notification_body['sender'], 'Notify Alpha',
                            notification_body['message'],
                            notification_body['id'])
                        notification.delete()
                        __update_notification_to_sent(message_id,
                                                      notification_body,
                                                      sender)
                        print("notification updated: {}".format(
                            notification_body['id']))
                    except ClientException as e:
                        print(e)
                        __update_notification_to_error(notification_body['id'],
                                                       e)

        except Exception as e:
            print(e)
示例#3
0
def test_get_messages_from_queue_returns_message_queue(notify_api):
    q = set_up_mock_queue('email')
    q.send_message(MessageBody=json.dumps(notification.serialize()),
                   MessageAttributes={
                       'type': {
                           'StringValue': 'email',
                           'DataType': 'String'
                       }
                   })

    messages = get_messages_from_queue('email')
    for m in messages:
        assert m.body == json.dumps(notification.serialize())