Add warning for unsent Signal groups messages.
This commit is contained in:
parent
d4ce94ddf8
commit
f059e75acd
2 changed files with 57 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue