WhatsApp/Signal/Formstack/admin updates
This commit is contained in:
parent
bcecf61a46
commit
d0cc5a21de
451 changed files with 16139 additions and 39623 deletions
|
|
@ -312,8 +312,42 @@ class CdrSignal
|
|||
def from_article(article)
|
||||
# sends a message from a zammad article
|
||||
|
||||
Rails.logger.debug { "Create signal message from article to '#{article[:to]}'..." }
|
||||
Rails.logger.debug { "Create signal message from article..." }
|
||||
|
||||
@api.send_message(article[:to], article[:body])
|
||||
# Get the recipient from ticket preferences
|
||||
ticket = Ticket.find_by(id: article.ticket_id)
|
||||
raise "No ticket found for article #{article.id}" unless ticket
|
||||
|
||||
recipient = ticket.preferences.dig('cdr_signal', 'chat_id')
|
||||
|
||||
# If auto-groups is enabled and no chat_id, use original_recipient
|
||||
if recipient.blank? && ENV['BRIDGE_SIGNAL_AUTO_GROUPS'].to_s.downcase == 'true'
|
||||
recipient = ticket.preferences.dig('cdr_signal', 'original_recipient')
|
||||
raise "No Signal chat_id or original_recipient found in ticket preferences" unless recipient
|
||||
elsif recipient.blank?
|
||||
raise "No Signal chat_id found in ticket preferences"
|
||||
end
|
||||
|
||||
Rails.logger.debug { "Sending to recipient: '#{recipient}'" }
|
||||
|
||||
# Include ticket ID as conversationId for group creation callback
|
||||
options = {}
|
||||
options[:conversationId] = ticket.number if ticket
|
||||
|
||||
# Get attachments from the article
|
||||
attachments = Store.list(object: 'Ticket::Article', o_id: article.id)
|
||||
if attachments.any?
|
||||
attachment_data = attachments.map do |attachment|
|
||||
{
|
||||
data: Base64.strict_encode64(attachment.content),
|
||||
filename: attachment.filename,
|
||||
mime_type: attachment.preferences['Mime-Type'] || attachment.preferences['Content-Type'] || 'application/octet-stream'
|
||||
}
|
||||
end
|
||||
options[:attachments] = attachment_data
|
||||
Rails.logger.debug { "Sending #{attachment_data.length} attachment(s) with message" }
|
||||
end
|
||||
|
||||
@api.send_message(recipient, article[:body], options)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -35,6 +35,16 @@ class CdrSignalApi
|
|||
end
|
||||
|
||||
def send_message(recipient, text, options = {})
|
||||
post('send', { to: recipient.to_s, message: text }.merge(parse_hash(options)))
|
||||
# Don't encode conversationId with CGI
|
||||
params = { to: recipient.to_s, message: text }
|
||||
if options[:conversationId]
|
||||
params[:conversationId] = options[:conversationId]
|
||||
options.delete(:conversationId)
|
||||
end
|
||||
if options[:attachments]
|
||||
params[:attachments] = options[:attachments]
|
||||
options.delete(:attachments)
|
||||
end
|
||||
post('send', params.merge(parse_hash(options)))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -312,8 +312,33 @@ class CdrWhatsapp
|
|||
def from_article(article)
|
||||
# sends a message from a zammad article
|
||||
|
||||
Rails.logger.debug { "Create whatsapp message from article to '#{article[:to]}'..." }
|
||||
Rails.logger.debug { "Create whatsapp message from article..." }
|
||||
|
||||
@api.send_message(article[:to], article[:body])
|
||||
# Get the recipient from ticket preferences
|
||||
ticket = Ticket.find_by(id: article.ticket_id)
|
||||
raise "No ticket found for article #{article.id}" unless ticket
|
||||
|
||||
recipient = ticket.preferences.dig('cdr_whatsapp', 'chat_id')
|
||||
raise "No WhatsApp chat_id found in ticket preferences" unless recipient
|
||||
|
||||
Rails.logger.debug { "Sending to recipient: '#{recipient}'" }
|
||||
|
||||
options = {}
|
||||
|
||||
# Get attachments from the article
|
||||
attachments = Store.list(object: 'Ticket::Article', o_id: article.id)
|
||||
if attachments.any?
|
||||
attachment_data = attachments.map do |attachment|
|
||||
{
|
||||
data: Base64.strict_encode64(attachment.content),
|
||||
filename: attachment.filename,
|
||||
mime_type: attachment.preferences['Mime-Type'] || attachment.preferences['Content-Type'] || 'application/octet-stream'
|
||||
}
|
||||
end
|
||||
options[:attachments] = attachment_data
|
||||
Rails.logger.debug { "Sending #{attachment_data.length} attachment(s) with message" }
|
||||
end
|
||||
|
||||
@api.send_message(recipient, article[:body], options)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ class CdrWhatsappApi
|
|||
end
|
||||
|
||||
def send_message(recipient, text, options = {})
|
||||
post('send', { to: recipient.to_s, message: text }.merge(parse_hash(options)))
|
||||
params = { to: recipient.to_s, message: text }
|
||||
params[:attachments] = options[:attachments] if options[:attachments]
|
||||
options.delete(:attachments) if options[:attachments]
|
||||
post('send', params.merge(parse_hash(options)))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue