コード例 #1
0
def handle_incoming(msg):
    try:
        process_incoming(msg)
        handle_successful_processing_attempt(msg)
    except:
        log_sms_exception(msg)
        handle_unsuccessful_processing_attempt(msg)
コード例 #2
0
ファイル: form_session.py プロジェクト: yonglehou/commcare-hq
def form_session_handler(v, text, msg):
    """
    The form session handler will use the inbound text to answer the next question
    in the open SQLXformsSession for the associated contact. If no session is open,
    the handler passes. If multiple sessions are open, they are all closed and an
    error message is displayed to the user.
    """
    multiple, session = get_single_open_session_or_close_multiple(v.domain, v.owner_id)
    if multiple:
        send_sms_to_verified_number(v, get_message(MSG_MULTIPLE_SESSIONS, v))
        return True

    if session:
        # Metadata to be applied to the inbound message
        inbound_metadata = MessageMetadata(
            workflow=session.workflow,
            reminder_id=session.reminder_id,
            xforms_session_couch_id=session._id,
        )
        add_msg_tags(msg, inbound_metadata)

        try:
            answer_next_question(v, text, msg, session)
        except Exception:
            # Catch any touchforms errors
            log_sms_exception(msg)
            send_sms_to_verified_number(v, get_message(MSG_TOUCHFORMS_DOWN, v))
        return True
    else:
        return False
コード例 #3
0
def handle_incoming(msg):
    try:
        process_incoming(msg)
        handle_successful_processing_attempt(msg)
    except:
        log_sms_exception(msg)
        handle_unsuccessful_processing_attempt(msg)
コード例 #4
0
def form_session_handler(v, text, msg):
    """
    The form session handler will use the inbound text to answer the next question
    in the open SQLXformsSession for the associated contact. If no session is open,
    the handler passes. If multiple sessions are open, they are all closed and an
    error message is displayed to the user.
    """
    multiple, session = get_single_open_session_or_close_multiple(v.domain, v.owner_id)
    if multiple:
        send_sms_to_verified_number(v, get_message(MSG_MULTIPLE_SESSIONS, v))
        return True

    if session:
        # Metadata to be applied to the inbound message
        inbound_metadata = MessageMetadata(
            workflow=session.workflow,
            reminder_id=session.reminder_id,
            xforms_session_couch_id=session._id,
        )
        add_msg_tags(msg, inbound_metadata)

        try:
            answer_next_question(v, text, msg, session)
        except Exception:
            # Catch any touchforms errors
            log_sms_exception(msg)
            send_sms_to_verified_number(v, get_message(MSG_TOUCHFORMS_DOWN, v))
        return True
    else:
        return False
コード例 #5
0
ファイル: form_session.py プロジェクト: dankohn/commcare-hq
def form_session_handler(v, text, msg):
    """
    The form session handler will use the inbound text to answer the next question
    in the open SQLXformsSession for the associated contact. If no session is open,
    the handler passes. If multiple sessions are open, they are all closed and an
    error message is displayed to the user.
    """
    with critical_section_for_smsforms_sessions(v.owner_id):
        if toggles.ONE_PHONE_NUMBER_MULTIPLE_CONTACTS.enabled(v.domain):
            channel = get_channel_for_contact(v.owner_id, v.phone_number)
            running_session_info = XFormsSessionSynchronization.get_running_session_info_for_channel(
                channel)
            if running_session_info.session_id:
                session = SQLXFormsSession.by_session_id(
                    running_session_info.session_id)
                if not session.session_is_open:
                    # This should never happen. But if it does we should set the channel free
                    # and act like there was no available session
                    notify_error(
                        "The supposedly running session was not open and was released. "
                        'No known way for this to happen, so worth investigating.'
                    )
                    XFormsSessionSynchronization.clear_stale_channel_claim(
                        channel)
                    session = None
            else:
                session = None
        else:
            multiple, session = get_single_open_session_or_close_multiple(
                v.domain, v.owner_id)
            if multiple:
                send_sms_to_verified_number(
                    v, get_message(MSG_MULTIPLE_SESSIONS, v))
                return True

        if session:
            session.phone_number = v.phone_number
            session.modified_time = datetime.utcnow()
            session.save()

            # Metadata to be applied to the inbound message
            inbound_metadata = MessageMetadata(
                workflow=session.workflow,
                reminder_id=session.reminder_id,
                xforms_session_couch_id=session._id,
            )
            add_msg_tags(msg, inbound_metadata)

            try:
                answer_next_question(v, text, msg, session)
            except Exception:
                # Catch any touchforms errors
                log_sms_exception(msg)
                send_sms_to_verified_number(
                    v, get_message(MSG_TOUCHFORMS_DOWN, v))
            return True
        else:
            return False