Prevent overwriting a Signal group in Zammad if one already exists
This commit is contained in:
parent
0b2ea19ebc
commit
69394c813d
1 changed files with 18 additions and 0 deletions
|
|
@ -374,6 +374,24 @@ class ChannelsCdrSignalController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Idempotency check: if chat_id is already a group ID, don't overwrite it
|
||||||
|
# This prevents race conditions where multiple group_created webhooks arrive
|
||||||
|
# (e.g., due to retries after API timeouts during group creation)
|
||||||
|
existing_chat_id = ticket.preferences&.dig(:cdr_signal, :chat_id) ||
|
||||||
|
ticket.preferences&.dig('cdr_signal', 'chat_id')
|
||||||
|
if existing_chat_id&.start_with?('group.')
|
||||||
|
Rails.logger.info "Signal group update: Ticket #{ticket.id} already has group #{existing_chat_id}, ignoring new group #{params[:group_id]}"
|
||||||
|
render json: {
|
||||||
|
success: true,
|
||||||
|
skipped: true,
|
||||||
|
reason: 'Ticket already has a group assigned',
|
||||||
|
existing_group_id: existing_chat_id,
|
||||||
|
ticket_id: ticket.id,
|
||||||
|
ticket_number: ticket.number
|
||||||
|
}, status: :ok
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
# Update ticket preferences with the group information
|
# Update ticket preferences with the group information
|
||||||
ticket.preferences ||= {}
|
ticket.preferences ||= {}
|
||||||
ticket.preferences[:cdr_signal] ||= {}
|
ticket.preferences[:cdr_signal] ||= {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue