def provider_to_use(notification_type,
                    notification_id,
                    international=False,
                    sender=None):
    active_providers_in_order = [
        p for p in get_provider_details_by_notification_type(
            notification_type, international) if p.active
    ]

    if not active_providers_in_order:
        current_app.logger.error("{} {} failed as no active providers".format(
            notification_type, notification_id))
        raise Exception("No active {} providers".format(notification_type))

    # Pour forcer l'utilisation de sinch avec un numéro abrege on utilise cette methode qui n est pas totalement sure
    # Un numéro de 5 ou 6 chiffres forcera l'utilisation de sinch
    if sender is not None and notification_type == SMS_TYPE and (
            len(sender) <= 6 and len(sender) >= 5) and sender.isdecimal():
        return clients.get_client_by_name_and_type("sinch", notification_type)

    # Pour forcer l'utilisation de pinpoint avec un numéro de téléphone à 10 chiffres comme sender
    # if sender is not None and notification_type == SMS_TYPE and sender[0] == "+":
    #     return clients.get_client_by_name_and_type("pinpoint", notification_type)

    return clients.get_client_by_name_and_type(
        active_providers_in_order[0].identifier, notification_type)
def provider_to_use(notification: Notification):

    if is_feature_enabled(FeatureFlag.PROVIDER_STRATEGIES_ENABLED):
        provider = provider_service.get_provider(notification)
        return clients.get_client_by_name_and_type(
            provider.identifier, notification.notification_type)

    if is_feature_enabled(FeatureFlag.TEMPLATE_SERVICE_PROVIDERS_ENABLED):
        provider_id = get_provider_id(notification)

        if provider_id:
            return clients.get_client_by_name_and_type(
                load_provider(provider_id).identifier,
                notification.notification_type)

    active_providers_in_order = [
        p for p in get_provider_details_by_notification_type(
            notification.notification_type, notification.international)
        if should_use_provider(p)
    ]

    if not active_providers_in_order:
        current_app.logger.error("{} {} failed as no active providers".format(
            notification.notification_type, notification.id))
        raise Exception("No active {} providers".format(
            notification.notification_type))

    return clients.get_client_by_name_and_type(
        active_providers_in_order[0].identifier,
        notification.notification_type)
Example #3
0
def test_update_notification_to_sending_does_not_update_status_from_a_final_status(
    sample_service, notify_db_session, starting_status, expected_status
):
    template = create_template(sample_service)
    notification = create_notification(template=template, status=starting_status)
    send_to_providers.update_notification_to_sending(notification, clients.get_client_by_name_and_type("mmg", "sms"))
    assert notification.status == expected_status
Example #4
0
def get_sms_provider_client(provider, notification_id):
    try:
        get_provider_details_by_identifier(provider)
    except NoResultFound:
        raise Exception(
            f"Could not find {provider} provider when trying to send notification {notification_id}"
        )

    return clients.get_client_by_name_and_type(provider, SMS_TYPE)
Example #5
0
def provider_to_use(notification_type, notification_id, international=False):
    active_providers_in_order = [
        p for p in get_provider_details_by_notification_type(notification_type, international) if p.active
    ]

    if not active_providers_in_order:
        current_app.logger.error(
            "{} {} failed as no active providers".format(notification_type, notification_id)
        )
        raise Exception("No active {} providers".format(notification_type))

    return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)
def provider_to_use(notification_type, notification_id):
    active_providers_in_order = [
        provider for provider in get_provider_details_by_notification_type(notification_type) if provider.active
    ]

    if not active_providers_in_order:
        current_app.logger.error(
            "{} {} failed as no active providers".format(notification_type, notification_id)
        )
        raise Exception("No active {} providers".format(notification_type))

    return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)
def provider_to_use(notification_type, international=False):
    active_providers = [
        p for p in get_provider_details_by_notification_type(notification_type, international) if p.active
    ]

    if not active_providers:
        current_app.logger.error(
            "{} failed as no active providers".format(notification_type)
        )
        raise Exception("No active {} providers".format(notification_type))

    chosen_provider = random.choices(active_providers, weights=[p.priority for p in active_providers])[0]

    return clients.get_client_by_name_and_type(chosen_provider.identifier, notification_type)