From 57aa278cb005b7abbb04fbfb44aec03de8c04f96 Mon Sep 17 00:00:00 2001 From: Devin Gaffney Date: Fri, 22 Sep 2023 10:22:44 -0700 Subject: [PATCH] add prefix, add blank safety check --- app/models/bot/alegre.rb | 4 ++-- app/models/concerns/alegre_webhooks.rb | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/bot/alegre.rb b/app/models/bot/alegre.rb index e42afbfc9a..a1bcbc8bf5 100644 --- a/app/models/bot/alegre.rb +++ b/app/models/bot/alegre.rb @@ -128,7 +128,7 @@ def get_language_from_transcription end def self.valid_request?(request) - request.query_parameters['token'] == CheckConfig.get('alegre_token') + !request.query_parameters['token'].blank? && request.query_parameters['token'] == CheckConfig.get('alegre_token') end @@ -499,7 +499,7 @@ def self.request_api(method, path, params = {}, query_or_body = 'body', retries parsed_response = JSON.parse(response_body) if parsed_response.dig("queue") == 'audio__Model' && parsed_response.dig("body", "callback_url") != nil redis = Redis.new(REDIS_CONFIG) - redis_response = redis.blpop(parsed_response.dig("body", "id"), timeout=120) + redis_response = redis.blpop("alegre:webhook:#{parsed_response.dig("body", "id")}", 120) return JSON.parse(redis_response[1]) end parsed_response diff --git a/app/models/concerns/alegre_webhooks.rb b/app/models/concerns/alegre_webhooks.rb index a0e20156f8..5ad92e520b 100644 --- a/app/models/concerns/alegre_webhooks.rb +++ b/app/models/concerns/alegre_webhooks.rb @@ -13,8 +13,9 @@ def webhook(request) begin doc_id = request.params["data"]["requested"]["body"]["id"] redis = Redis.new(REDIS_CONFIG) - redis.lpush(doc_id, request.params.to_json) - redis.expire(doc_id, 1.day.to_i) + key = "alegre:webhook:#{doc_id}" + redis.lpush(key, request.params.to_json) + redis.expire(key, 1.day.to_i) rescue StandardError => e CheckSentry.notify(AlegreCallbackError.new(e.message), { alegre_response: body }) end