instance_1_credentials_url).strip()
    instance_1 = RapidProClient(instance_1_domain, instance_1_token)

    log.info("Downloading the target instance access token...")
    instance_2_token = google_cloud_utils.download_blob_to_string(
        google_cloud_credentials_file_path,
        instance_2_credentials_url).strip()
    instance_2 = RapidProClient(instance_2_domain, instance_2_token)

    # Synchronise the contact fields
    log.info("Synchronising contact fields...")
    instance_1_fields = instance_1.get_fields()
    instance_2_fields = instance_2.get_fields()
    for field in instance_1_fields:
        if field.key not in {f.key for f in instance_2_fields}:
            instance_2.create_field(field.label)
    for field in instance_2_fields:
        if field.key not in {f.key for f in instance_1_fields}:
            instance_1.create_field(field.label)
    log.info("Contact fields synchronised")

    # Synchronise the contacts
    log.info("Synchronising contacts...")
    instance_1_contacts = instance_1.get_raw_contacts()
    instance_2_contacts = instance_2.get_raw_contacts()

    def filter_valid_contacts(contacts):
        valid_contacts = []
        for contact in contacts:
            if len(contact.urns) != 1:
                log.warning(
Exemple #2
0
        google_cloud_credentials_file_path, source_credentials_url).strip()
    source_instance = RapidProClient(source_domain, source_token)

    log.info("Downloading the target instance access token...")
    target_token = google_cloud_utils.download_blob_to_string(
        google_cloud_credentials_file_path, target_credentials_url).strip()
    target_instance = RapidProClient(target_domain, target_token)

    # For each contact field in the source instance, create a matching contact field in the target instance if it
    # does not already exist
    log.info("Copying contact fields...")
    source_fields = source_instance.get_fields()
    target_field_keys = {f.key for f in target_instance.get_fields()}
    for field in source_fields:
        if field.key not in target_field_keys:
            target_instance.create_field(field.label)
    log.info("Contact fields copied")

    log.info("Fetching all contacts from the source instance...")
    contacts = source_instance.get_raw_contacts()
    log.info(f"Fetched {len(contacts)} contacts")

    log.info("Updating contacts in the target instance...")
    # Update each contact's name and fields.
    # Language, groups, blocked, and stopped properties are not touched.
    multiple_urns_count = 0
    telephone_with_no_country_code_count = 0
    updated_count = 0
    for i, contact in enumerate(contacts):
        log.debug(f"Updating contact {i + 1}/{len(contacts)}...")
        if len(contact.urns) != 1:
Exemple #3
0
        workspace_2 = None

    # Synchronise the data
    # Synchronise the contact fields
    new_contact_fields_in_workspace_2 = 0
    if workspaces_to_update in {"2", "both"}:
        log.info(
            f"Synchronising fields from {workspace_1_name} to {workspace_2_name}..."
        )
        for field in workspace_1_fields:
            if field.key not in {f.key for f in workspace_2_fields}:
                new_contact_fields_in_workspace_2 += 1
                if dry_run:
                    log.info(f"Would create field '{field.label}'")
                    continue
                new_field = workspace_2.create_field(field.label, field.key)
    new_contact_fields_in_workspace_1 = 0
    if workspaces_to_update in {"1", "both"}:
        log.info(
            f"Synchronising fields from {workspace_2_name} to {workspace_1_name}..."
        )
        for field in workspace_2_fields:
            if field.key not in {f.key for f in workspace_1_fields}:
                new_contact_fields_in_workspace_1 += 1
                if dry_run:
                    log.info(f"Would create field '{field.label}'")
                    continue
                new_field = workspace_1.create_field(field.label, field.key)
    log.info("Contact fields synchronised")

    def filter_valid_contacts(contacts):