(msg)
return registration_processed
This method handles registration via sms.
    Returns True if a contact was registered, False if not.

    To have a case register itself, do the following:

        1) Select "Enable Case Registration Via SMS" in project settings, and fill in the
        associated Case Registration settings.

        2) Text in "join <domain>", where <domain> is the domain to join. If the sending
        number does not exist in the system, a case will be registered tied to that number.
        The "join" keyword can be any keyword in REGISTRATION_KEYWORDS. This is meant to
        support multiple translations.

    To have a mobile worker register itself, do the following:

        1) Select "Enable Mobile Worker Registration via SMS" in project settings.

        2) Text in "join <domain> worker <username>", where <domain> is the domain to join and <username> is the
        requested username.  If the username doesn't exist it will be created, otherwise the registration will error.
        If the username argument is not specified, the username will be the mobile number

        The "join" and "worker" keywords can be any keyword in REGISTRATION_KEYWORDS and
        REGISTRATION_MOBILE_WORKER_KEYWORDS, respectively. This is meant to support multiple
        translations.
This method handles registration via sms.
    Returns True if a contact was registered, False if not.
This method handles registration via sms . Returns True if a contact was registered False if not .
def process_sms_registration(msg):
    """
    This method handles registration via sms.
    Returns True if a contact was registered, False if not.

    To have a case register itself, do the following:

        1) Select "Enable Case Registration Via SMS" in project settings, and fill in the
        associated Case Registration settings.

        2) Text in "join <domain>", where <domain> is the domain to join. If the sending
        number does not exist in the system, a case will be registered tied to that number.
        The "join" keyword can be any keyword in REGISTRATION_KEYWORDS. This is meant to
        support multiple translations.

    To have a mobile worker register itself, do the following:

        1) Select "Enable Mobile Worker Registration via SMS" in project settings.

        2) Text in "join <domain> worker <username>", where <domain> is the domain to join and <username> is the
        requested username.  If the username doesn't exist it will be created, otherwise the registration will error.
        If the username argument is not specified, the username will be the mobile number

        The "join" and "worker" keywords can be any keyword in REGISTRATION_KEYWORDS and
        REGISTRATION_MOBILE_WORKER_KEYWORDS, respectively. This is meant to support multiple
        translations.
    """
    registration_processed = False
    text_words = msg.text.upper().split()
    keyword1 = text_words[0] if len(text_words) > 0 else ""
    keyword2 = text_words[1].lower() if len(text_words) > 1 else ""
    keyword3 = text_words[2] if len(text_words) > 2 else ""
    keyword4 = text_words[3] if len(text_words) > 3 else ""
    cleaned_phone_number = strip_plus(msg.phone_number)
    if is_registration_text(msg.text) and keyword2 != "":
        domain_name = keyword2

        if any_migrations_in_progress(domain_name):
            raise DelayProcessing()

        domain_obj = Domain.get_by_name(domain_name, strict=True)

        if domain_obj is not None:
            if domain_has_privilege(domain_obj, privileges.INBOUND_SMS):
                if (
                        keyword3 in REGISTRATION_MOBILE_WORKER_KEYWORDS
                        and domain_obj.sms_mobile_worker_registration_enabled
                ):
                    username = cleaned_phone_number if keyword4 == '' else keyword4
                    registration_processed = register_sms_user(
                        username=username,
                        domain=domain_obj.name,
                        cleaned_phone_number=cleaned_phone_number,
                        send_welcome_sms=domain_obj.enable_registration_welcome_sms_for_mobile_worker,
                        admin_alert_emails=domain_obj.sms_worker_registration_alert_emails,
                    )
                elif domain_obj.sms_case_registration_enabled:
                    register_sms_contact(
                        domain=domain_obj.name,
                        case_type=domain_obj.sms_case_registration_type,
                        case_name="unknown",
                        user_id=domain_obj.sms_case_registration_user_id,
                        contact_phone_number=cleaned_phone_number,
                        contact_phone_number_is_verified="1",
                        owner_id=domain_obj.sms_case_registration_owner_id,
                    )
                    registration_processed = True
                    if domain_obj.enable_registration_welcome_sms_for_case:
                        send_sms(domain_obj.name, None, cleaned_phone_number,
                                 get_message(MSG_REGISTRATION_WELCOME_CASE, domain=domain_obj.name))
            msg.domain = domain_obj.name
            msg.save()

    return registration_processed
def process_sms_registration ( msg ) : registration_processed = False text_words = msg . text . upper ( ) . split ( ) keyword1 = text_words [ 0 ] if len ( text_words ) > 0 else "" keyword2 = text_words [ 1 ] . lower ( ) if len ( text_words ) > 1 else "" keyword3 = text_words [ 2 ] if len ( text_words ) > 2 else "" keyword4 = text_words [ 3 ] if len ( text_words ) > 3 else "" cleaned_phone_number = strip_plus ( msg . phone_number ) if is_registration_text ( msg . text ) and keyword2 != "" : domain_name = keyword2 if any_migrations_in_progress ( domain_name ) : raise DelayProcessing ( ) domain_obj = Domain . get_by_name ( domain_name , strict = True ) if domain_obj is not None : if domain_has_privilege ( domain_obj , privileges . INBOUND_SMS ) : if ( keyword3 in REGISTRATION_MOBILE_WORKER_KEYWORDS and domain_obj . sms_mobile_worker_registration_enabled ) : username = cleaned_phone_number if keyword4 == '' else keyword4 registration_processed = register_sms_user ( username = username , domain = domain_obj . name , cleaned_phone_number = cleaned_phone_number , send_welcome_sms = domain_obj . enable_registration_welcome_sms_for_mobile_worker , admin_alert_emails = domain_obj . sms_worker_registration_alert_emails , ) elif domain_obj . sms_case_registration_enabled : register_sms_contact ( domain = domain_obj . name , case_type = domain_obj . sms_case_registration_type , case_name = "unknown" , user_id = domain_obj . sms_case_registration_user_id , contact_phone_number = cleaned_phone_number , contact_phone_number_is_verified = "1" , owner_id = domain_obj . sms_case_registration_owner_id , ) registration_processed = True if domain_obj . enable_registration_welcome_sms_for_case : send_sms ( domain_obj . name , None , cleaned_phone_number , get_message ( MSG_REGISTRATION_WELCOME_CASE , domain = domain_obj . name ) ) msg . domain = domain_obj . name msg . save ( ) return registration_processed