From f059e75acd68bb15c728149c4a8a3d03351edb47 Mon Sep 17 00:00:00 2001 From: Darren Clarke Date: Fri, 19 Dec 2025 11:20:28 +0100 Subject: [PATCH] Add warning for unsent Signal groups messages. --- .../channels_cdr_signal_controller.rb | 30 +++++++++++++++++++ .../app/jobs/communicate_cdr_signal_job.rb | 27 +++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/packages/zammad-addon-bridge/src/app/controllers/channels_cdr_signal_controller.rb b/packages/zammad-addon-bridge/src/app/controllers/channels_cdr_signal_controller.rb index f09c458..409eac7 100644 --- a/packages/zammad-addon-bridge/src/app/controllers/channels_cdr_signal_controller.rb +++ b/packages/zammad-addon-bridge/src/app/controllers/channels_cdr_signal_controller.rb @@ -458,6 +458,36 @@ class ChannelsCdrSignalController < ApplicationController Rails.logger.info "Signal group member #{member_phone} joined group #{params[:group_id]} for ticket #{ticket.id}" + # Check if any articles had a group_not_joined notification and add resolution note + # Only add resolution note if we previously notified about the delivery issue + articles_with_pending_notification = Ticket::Article.where(ticket_id: ticket.id) + .where("preferences LIKE ?", "%group_not_joined_note_added: true%") + + if articles_with_pending_notification.exists? + # Check if we already added a resolution note for this ticket + resolution_note_exists = Ticket::Article.where(ticket_id: ticket.id) + .where("preferences LIKE ?", "%group_joined_resolution: true%") + .exists? + + unless resolution_note_exists + Ticket::Article.create( + ticket_id: ticket.id, + content_type: 'text/plain', + body: 'Recipient has now joined the Signal group. Pending messages will be delivered shortly.', + internal: true, + sender: Ticket::Article::Sender.find_by(name: 'System'), + type: Ticket::Article::Type.find_by(name: 'note'), + preferences: { + delivery_message: true, + group_joined_resolution: true, + }, + updated_by_id: 1, + created_by_id: 1, + ) + Rails.logger.info "Ticket ##{ticket.number}: Added resolution note about customer joining Signal group" + end + end + render json: { success: true, ticket_id: ticket.id, diff --git a/packages/zammad-addon-bridge/src/app/jobs/communicate_cdr_signal_job.rb b/packages/zammad-addon-bridge/src/app/jobs/communicate_cdr_signal_job.rb index 37e026a..786be4b 100644 --- a/packages/zammad-addon-bridge/src/app/jobs/communicate_cdr_signal_job.rb +++ b/packages/zammad-addon-bridge/src/app/jobs/communicate_cdr_signal_job.rb @@ -40,10 +40,37 @@ class CommunicateCdrSignalJob < ApplicationJob if is_group_chat && group_joined == false Rails.logger.info "Ticket ##{ticket.number}: User hasn't joined Signal group yet, skipping message delivery" + # Track group_not_joined retry attempts separately + article.preferences['group_not_joined_retry'] ||= 0 + article.preferences['group_not_joined_retry'] += 1 + # Mark article as pending delivery article.preferences['delivery_status'] = 'pending' article.preferences['delivery_status_message'] = 'Waiting for user to join Signal group' article.preferences['delivery_status_date'] = Time.zone.now + + # After 3 failed attempts, add a note to inform the agent (only once) + if article.preferences['group_not_joined_retry'] == 3 && !article.preferences['group_not_joined_note_added'] + Ticket::Article.create( + ticket_id: ticket.id, + content_type: 'text/plain', + body: 'Unable to send Signal message: Recipient has not yet joined the Signal group. ' \ + 'The message will be delivered automatically once they accept the group invitation.', + internal: true, + sender: Ticket::Article::Sender.find_by(name: 'System'), + type: Ticket::Article::Type.find_by(name: 'note'), + preferences: { + delivery_article_id_related: article.id, + delivery_message: true, + group_not_joined_notification: true, + }, + updated_by_id: 1, + created_by_id: 1, + ) + article.preferences['group_not_joined_note_added'] = true + Rails.logger.info "Ticket ##{ticket.number}: Added notification note about pending group join" + end + article.save! # Retry later when user might have joined