Skip to content

Commit

Permalink
add prefix, add blank safety check
Browse files Browse the repository at this point in the history
  • Loading branch information
DGaffney committed Sep 22, 2023
1 parent 6026c4d commit 57aa278
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/models/bot/alegre.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/models/concerns/alegre_webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 57aa278

Please sign in to comment.