def performSecurityCheckAndGetConn(event): if "queryStringParameters" in event and event["queryStringParameters"] is not None: if "key" in event["queryStringParameters"]: key = event["queryStringParameters"]["key"] for v in validKeys: if v == key: token = event["queryStringParameters"]["token"] validateToken(event, token) return dbUtil.getConnection() #not found in url, lets check body if "body" in event and event["body"] is not None: body = json.loads(event["body"]) if "key" in body: key = body["key"] for v in validKeys: if v == key: token = body["token"] validateToken(event, token) return dbUtil.getConnection() logger.info("valid key not found in body. call rejected.") #key not matched. rejecting raise CallRejectedException('call rejected')
def groupHandler(message, startTime): # logger.info("group request") chatId = message["chat"]["id"] textCmd, skip = tgBotUtils.validateAndGetText(chatId, message, startTime) if skip: return skip if not textCmd: logger.info("invalid group request: message: {}".format(message)) return tgBotUtils.missingTextError(chatId, message, startTime) userId = message["from"]["id"] conn = dbUtil.getConnection() response, response2, response3, handled, keyboard = handleCommonCommands( False, textCmd, conn, chatId, userId) if not handled: if "/setaddress" in textCmd: response = "This command is not available in a group chat" elif textCmd == "/account": response = "This command is not available in a group chat" else: logger.info("in else. not calling anything") return sendResponse(False, response, response2, response3, keyboard, conn, chatId, textCmd, startTime)
def doPerformCheckAndGetConn(event, app, fnName): if "queryStringParameters" in event and event[ "queryStringParameters"] is not None: if "accessKey" in event["queryStringParameters"]: key = event["queryStringParameters"]["accessKey"] conn = dbUtil.getConnection() checkAccessKey(conn, app, key, fnName) return conn, key logger.info("access key not found in request. call rejected.") #key not matched. rejecting raise CallRejectedException('403')
def missingTextError(chatId, message, startTime): logger.info("processing missingTextError for message: ") logger.info(message) conn = dbUtil.getConnection() auditUtils.auditBot(conn, chatId, "Missing Text", startTime) conn.close() response = "The bot appears to have hit a bug. Please contact the bot operator @bigb4ever \n" respData = {"text": response.encode("utf8"), "chat_id": chatId} url = rds_config.TG_BASE_URL + "/sendMessage?parse_mode=html" requests.post(url, respData) return SUCCESS_RESPONSE
def individualHandler(message, startTime): logger.info("individual request") chatId = message["chat"]["id"] textCmd, skip = tgBotUtils.validateAndGetText(chatId, message, startTime) if skip: return skip userId = message["from"]["id"] conn = dbUtil.getConnection() response, response2, response3, handled, keyboard = handleCommonCommands( True, textCmd, conn, chatId, userId) if not handled: if "/setaddress" in textCmd: response = setAddress(conn, chatId, textCmd) elif textCmd == "/account": response = getAccount(conn, chatId, userId) else: logger.info("in else. not calling anything") return sendResponse(True, response, response2, response3, keyboard, conn, chatId, textCmd, startTime)