[RELEASE] Echo Speaks V4

UPDATED WITH NEW URL and functions:

Not in the position to say everything that needs updated here (the node.js code is really old), but one of the problems is in the ""/api/bootstrap" api no longer returns as a valid check.

Replace both validateCookie && validateCookieResp functions in the Echo Speaks application code starting at line 2143.

I deleted the cookie and reauthorized from scratch and showing greens and my echo's are talking again. I am US region so not sure if this solves everything...but helped so far.

Boolean validateCookie(Boolean frc=false) {
    Boolean valid; valid = (Boolean)state.authValid
    Integer lastChk = getLastTsValSecs("lastCookieChkDt", 3600)
    Integer lastSpoke = getLastTsValSecs("lastSpokeToAmazon", 3600)
    Boolean cookieOk = getCookieVal() && getCsrfVal()
    if(!frc && valid && lastChk <= 1800 && cookieOk) { return valid }
    if(!frc && valid && lastSpoke <= 1800 && lastChk < 3600 && cookieOk) { return valid }
    if(frc && valid && lastChk <= 60 && cookieOk) { return valid }

    valid = false
    String meth='validateCookie'
    if(!cookieOk) {
        authValidationEvent(valid, meth)
        return valid
    }
    try {
        Long execDt = wnow()
        Map params = [
            uri: getAmazonUrl(),
            path: "/api/customer-status",
            query: ["version": iZ],
            headers: getReqHeaderMap(true),
            contentType: sAPPJSON,
            timeout: 20,
        ]
        logTrace(meth)
        if(!frc) { execAsyncCmd("get", "validateCookieResp", params, [dt:execDt]) }
        else {
            httpGet(params) { resp->
                valid = validateCookieResp(resp, [dt:execDt])
            }
        }
    } catch(ex) {
        respExceptionHandler(ex, "validateCookie", true)
        incrementCntByKey("err_app_cookieValidCnt")
    }
    return valid
}

Boolean validateCookieResp(resp, data){
    try {
        String meth = 'validateCookieResp'
        if(resp?.status != 200) { logWarn("${resp?.status} $meth"); return false }
        else {
            logDebug "$meth ${resp?.data}"
            updTsVal("lastSpokeToAmazon")
            authValidationEvent(true, meth)
            updTsVal("lastCookieChkDt")
            logDebug("Cookie Validation: (true) | Process Time: (${(wnow()-(Long)data.dt)}ms)")
            return true
        }
    } catch(ex) {
        respExceptionHandler(ex, "validateCookieResp", true)
        incrementCntByKey("err_app_cookieValidCnt")
    }
    return false
}

This is better:

8 Likes