feat(voice): add activity messages + customizable body for call permission
Emit a conversation activity message when the call permission template is sent (in the controller's render_permission_request) and another when the contact accepts the prompt (in CallPermissionReplyService). Read an inbox provider_config['call_permission_request_body'] override before falling back to the i18n default — surfaced in the inbox UI in a separate change.
This commit is contained in:
@@ -298,6 +298,9 @@ en:
|
||||
issue_created: 'Linear issue %{issue_id} was created by %{user_name}'
|
||||
issue_linked: 'Linear issue %{issue_id} was linked by %{user_name}'
|
||||
issue_unlinked: 'Linear issue %{issue_id} was unlinked by %{user_name}'
|
||||
whatsapp_call:
|
||||
permission_requested: 'Sent a call permission request to %{contact_name}.'
|
||||
permission_granted: '%{contact_name} accepted the call permission request.'
|
||||
csat:
|
||||
not_sent_due_to_messaging_window: 'CSAT survey not sent due to outgoing message restrictions'
|
||||
auto_resolve:
|
||||
|
||||
@@ -123,6 +123,7 @@ class Api::V1::Accounts::WhatsappCallsController < Api::V1::Accounts::BaseContro
|
||||
sent = send_permission_request_safely
|
||||
if sent
|
||||
record_permission_request_wamid(sent)
|
||||
emit_permission_requested_activity
|
||||
status = 'permission_requested'
|
||||
else
|
||||
status = 'failed'
|
||||
@@ -141,12 +142,33 @@ class Api::V1::Accounts::WhatsappCallsController < Api::V1::Accounts::BaseContro
|
||||
|
||||
# Treat transport errors as a falsy return so we render 422 rather than 500.
|
||||
def send_permission_request_safely
|
||||
provider_service.send_call_permission_request(@conversation.contact.phone_number.delete('+'))
|
||||
provider_service.send_call_permission_request(
|
||||
@conversation.contact.phone_number.delete('+'),
|
||||
*permission_request_body_args
|
||||
)
|
||||
rescue StandardError => e
|
||||
Rails.logger.warn "[WHATSAPP CALL] permission_request failed: #{e.class} #{e.message}"
|
||||
nil
|
||||
end
|
||||
|
||||
# Pass the inbox-level override only when present so the provider falls back
|
||||
# to the i18n default for inboxes that haven't customized the prompt.
|
||||
def permission_request_body_args
|
||||
custom_body = @conversation.inbox.channel.provider_config&.dig('call_permission_request_body').presence
|
||||
custom_body ? [custom_body] : []
|
||||
end
|
||||
|
||||
def emit_permission_requested_activity
|
||||
content = I18n.t(
|
||||
'conversations.activity.whatsapp_call.permission_requested',
|
||||
contact_name: @conversation.contact.name
|
||||
)
|
||||
::Conversations::ActivityMessageJob.perform_later(
|
||||
@conversation,
|
||||
{ account_id: @conversation.account_id, inbox_id: @conversation.inbox_id, message_type: :activity, content: content }
|
||||
)
|
||||
end
|
||||
|
||||
# Stash the outbound wamid so the reply webhook can match context.id back here.
|
||||
def record_permission_request_wamid(sent)
|
||||
attrs = (@conversation.additional_attributes || {}).merge(
|
||||
|
||||
@@ -11,11 +11,23 @@ class Whatsapp::CallPermissionReplyService
|
||||
return unless conversation
|
||||
|
||||
clear_permission_flag(conversation)
|
||||
emit_permission_granted_activity(conversation)
|
||||
broadcast_permission_granted(conversation.contact, conversation)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def emit_permission_granted_activity(conversation)
|
||||
content = I18n.t(
|
||||
'conversations.activity.whatsapp_call.permission_granted',
|
||||
contact_name: conversation.contact.name
|
||||
)
|
||||
::Conversations::ActivityMessageJob.perform_later(
|
||||
conversation,
|
||||
{ account_id: conversation.account_id, inbox_id: conversation.inbox_id, message_type: :activity, content: content }
|
||||
)
|
||||
end
|
||||
|
||||
def extract_reply_data
|
||||
message = params.dig(:entry, 0, :changes, 0, :value, :messages, 0)
|
||||
reply = message&.dig(:interactive, :call_permission_reply)
|
||||
|
||||
Reference in New Issue
Block a user