feat: Add support for typing events in webhooks (#11423)
Added support for typing events in webhooks. Two new events are now available: `conversation_typing_on` and `conversation_typing_off`. <img width="746" alt="Screenshot 2025-05-08 at 4 50 24 PM" src="https://github.com/user-attachments/assets/62da7b38-de0f-42c5-84f4-066e653da331" /> --------- Co-authored-by: Pranav <pranav@chatwoot.com> Co-authored-by: Pranav <pranavrajs@gmail.com>
This commit is contained in:
@@ -41,7 +41,9 @@
|
||||
"MESSAGE_UPDATED": "Message updated",
|
||||
"WEBWIDGET_TRIGGERED": "Live chat widget opened by the user",
|
||||
"CONTACT_CREATED": "Contact created",
|
||||
"CONTACT_UPDATED": "Contact updated"
|
||||
"CONTACT_UPDATED": "Contact updated",
|
||||
"CONVERSATION_TYPING_ON": "Conversation Typing On",
|
||||
"CONVERSATION_TYPING_OFF": "Conversation Typing Off"
|
||||
}
|
||||
},
|
||||
"END_POINT": {
|
||||
|
||||
@@ -16,6 +16,8 @@ const SUPPORTED_WEBHOOK_EVENTS = [
|
||||
'webwidget_triggered',
|
||||
'contact_created',
|
||||
'contact_updated',
|
||||
'conversation_typing_on',
|
||||
'conversation_typing_off',
|
||||
];
|
||||
|
||||
export default {
|
||||
|
||||
@@ -83,8 +83,30 @@ class WebhookListener < BaseListener
|
||||
deliver_account_webhooks(payload, account)
|
||||
end
|
||||
|
||||
def conversation_typing_on(event)
|
||||
handle_typing_status(__method__.to_s, event)
|
||||
end
|
||||
|
||||
def conversation_typing_off(event)
|
||||
handle_typing_status(__method__.to_s, event)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def handle_typing_status(event_name, event)
|
||||
conversation = event.data[:conversation]
|
||||
user = event.data[:user]
|
||||
inbox = conversation.inbox
|
||||
|
||||
payload = {
|
||||
event: event_name,
|
||||
user: user.webhook_data,
|
||||
conversation: conversation.webhook_data,
|
||||
is_private: event.data[:is_private] || false
|
||||
}
|
||||
deliver_webhook_payloads(payload, inbox)
|
||||
end
|
||||
|
||||
def deliver_account_webhooks(payload, account)
|
||||
account.webhooks.account_type.each do |webhook|
|
||||
next unless webhook.subscriptions.include?(payload[:event])
|
||||
|
||||
@@ -26,7 +26,8 @@ class Webhook < ApplicationRecord
|
||||
enum webhook_type: { account_type: 0, inbox_type: 1 }
|
||||
|
||||
ALLOWED_WEBHOOK_EVENTS = %w[conversation_status_changed conversation_updated conversation_created contact_created contact_updated
|
||||
message_created message_updated webwidget_triggered inbox_created inbox_updated].freeze
|
||||
message_created message_updated webwidget_triggered inbox_created inbox_updated
|
||||
conversation_typing_on conversation_typing_off].freeze
|
||||
|
||||
private
|
||||
|
||||
|
||||
Reference in New Issue
Block a user