fn check_for_hold(
    data: &mut ConversationInfo,
    bot: &CsmlBot,
    event: &mut Event,
) -> Result<(), EngineError> {
    match state::get_state_key(&data.client, "hold", "position", &mut data.db) {
        // user is currently on hold
        Ok(Some(hold)) => {
            match hold.get("hash") {
                Some(hash_value) => {
                    let flow_hash = get_current_step_hash(&data.context, bot)?;
                    // cleanup the current hold and restart flow
                    if flow_hash != *hash_value {
                        return clean_hold_and_restart(data);
                    }
                    flow_hash
                }
                _ => return Ok(()),
            };

            let index = match serde_json::from_value::<IndexInfo>(hold["index"].clone()) {
                Ok(index) => index,
                Err(_) => {
                    state::delete_state_key(&data.client, "hold", "position", &mut data.db)?;
                    return Ok(());
                }
            };

            let secure_hold = hold["secure"].as_bool().unwrap_or(false);

            if secure_hold {
                event.secure = true;
            }

            // all good, let's load the position and local variables
            data.context.hold = Some(Hold {
                index,
                step_vars: hold["step_vars"].clone(),
                step_name: data.context.step.get_step(),
                flow_name: data.context.flow.to_owned(),
                previous: serde_json::from_value(hold["previous"].clone()).unwrap_or(None),
                secure: secure_hold,
            });

            state::delete_state_key(&data.client, "hold", "position", &mut data.db)?;
        }
        // user is not on hold
        Ok(None) => (),
        Err(_) => (),
    };
    Ok(())
}
/**
 * Verify if the user is currently on hold in a given conversation.
 *
 * If a hold is found, make sure that the flow has not been updated since last conversation.
 * If that's the case, we can not be sure that the hold is in the same position,
 * so we need to clear the hold's position and restart the conversation.
 *
 * If the hold is valid, we also need to load the local step memory
 * (context.hold.step_vars) into the conversation context.
 */
Verify if the user is currently on hold in a given conversation.
If a hold is found, make sure that the flow has not been updated since last conversation.
If that's the case, we can not be sure that the hold is in the same position,
so we need to clear the hold's position and restart the conversation.

If the hold is valid, we also need to load the local step memory
(context.hold.step_vars) into the conversation context.
Verify if the user is currently on hold in a given conversation . If a hold is found make sure that the flow has not been updated since last conversation . If that ' s the case we can not be sure that the hold is in the same position so we need to clear the hold ' s position and restart the conversation . If the hold is valid we also need to load the local step memory ( context . hold . step_vars ) into the conversation context .
fn check_for_hold(
    data: &mut ConversationInfo,
    bot: &CsmlBot,
    event: &mut Event,
) -> Result<(), EngineError> {
    match state::get_state_key(&data.client, "hold", "position", &mut data.db) {
        // user is currently on hold
        Ok(Some(hold)) => {
            match hold.get("hash") {
                Some(hash_value) => {
                    let flow_hash = get_current_step_hash(&data.context, bot)?;
                    // cleanup the current hold and restart flow
                    if flow_hash != *hash_value {
                        return clean_hold_and_restart(data);
                    }
                    flow_hash
                }
                _ => return Ok(()),
            };
            let index = match serde_json::from_value::<IndexInfo>(hold["index"].clone()) {
                Ok(index) => index,
                Err(_) => {
                    state::delete_state_key(&data.client, "hold", "position", &mut data.db)?;
                    return Ok(());
                }
            };
            let secure_hold = hold["secure"].as_bool().unwrap_or(false);
            if secure_hold {
                event.secure = true;
            }
            // all good, let's load the position and local variables
            data.context.hold = Some(Hold {
                index,
                step_vars: hold["step_vars"].clone(),
                step_name: data.context.step.get_step(),
                flow_name: data.context.flow.to_owned(),
                previous: serde_json::from_value(hold["previous"].clone()).unwrap_or(None),
                secure: secure_hold,
            });
            state::delete_state_key(&data.client, "hold", "position", &mut data.db)?;
        }
        // user is not on hold
        Ok(None) => (),
        Err(_) => (),
    };
    Ok(())
}
fn check_for_hold ( data : & mut ConversationInfo , bot : & CsmlBot , event : & mut Event , ) -> Result < ( ) , EngineError > { match state :: get_state_key ( & data . client , " " , " " , & mut data . db ) { // user is currently on hold Ok ( Some ( hold ) ) => { match hold . get ( " " ) { Some ( hash_value ) => { let flow_hash = get_current_step_hash ( & data . context , bot ) ? ; // cleanup the current hold and restart flow if flow_hash != * hash_value { return clean_hold_and_restart ( data ) ; } flow_hash } _ => return Ok ( ( ) ) , } ; let index = match serde_json :: from_value :: < IndexInfo > ( hold [ " " ] . clone ( ) ) { Ok ( index ) => index , Err ( _ ) => { state :: delete_state_key ( & data . client , " " , " " , & mut data . db ) ? ; return Ok ( ( ) ) ; } } ; let secure_hold = hold [ " " ] . as_bool ( ) . unwrap_or ( false ) ; if secure_hold { event . secure = true ; } // all good, let's load the position and local variables data . context . hold = Some ( Hold { index , step_vars : hold [ " " ] . clone ( ) , step_name : data . context . step . get_step ( ) , flow_name : data . context . flow . to_owned ( ) , previous : serde_json :: from_value ( hold [ " " ] . clone ( ) ) . unwrap_or ( None ) , secure : secure_hold , } ) ; state :: delete_state_key ( & data . client , " " , " " , & mut data . db ) ? ; } // user is not on hold Ok ( None ) => ( ) , Err ( _ ) => ( ) , } ; Ok ( ( ) ) }
Verify if the user is currently on hold in a given conversation.
Verify if the user is currently on hold in a given conversation .
data
&mut ConversationInfo
bot
&CsmlBot
event
&mut Event
data
&mut ConversationInfo
bot
&CsmlBot
event
&mut Event