136 Commits

Author SHA1 Message Date
Vishnu Narayanan
9527ff6269 feat: Add support for labels in automations (#11658)
- Add support for using labels as an action event for automation
 - Fix duplicated conversation_updated event dispatch for labels
 

Fixes https://github.com/chatwoot/chatwoot/issues/8539 and multiple
issues around duplication related to label change events.
---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2025-09-18 14:17:54 +05:30
Shivam Mishra
b7f3f72b9c fix: Reply time calculation for re-opened conversations (#11787)
This PR fixes the reply time calculation for reopened conversations.
Previously, when a customer sent a message to reopen a resolved
conversation, the reply time metric would be calculated incorrectly
because the `waiting_since` timestamp was not properly set before the
reply event was dispatched. This would create a case where you'd have
reporting events like the following

```
[[33955732, "reply_time", 19.0],
 [33955847, "reply_time", 24.0],
 [33955666, "reply_time", 89.0],
 [33955530, "conversation_bot_handoff", 4.0],
 [33955567, "first_response", 42.0],
 [33955745, "reply_time", 21.0],
 [33955934, "reply_time", 49.0],
 [33955906, "reply_time", 121.0],
 [33987938, "conversation_resolved", 26285.0],
 [35571005, "reply_time", 985492.0]]
```
Note the `reply_time` after `conversation_resolved`

The fix ensures that `waiting_since` is correctly updated when
conversations are reopened, either through incoming messages or manual
status changes, resulting in accurate reply time metrics that measure
only the time from the customer's new message to the agent's response.

## Type of change

Please delete options that are not relevant.

- [x] Bug fix (non-breaking change which fixes an issue)

## How Has This Been Tested?

The changes have been tested with comprehensive specs that verify:

1. **Reply time calculation after conversation reopening** - Ensures
correct timestamps are used when calculating reply times for reopened
conversations
2. **Waiting since updates on status changes** - Verifies that
`waiting_since` is properly set when conversation status changes from
resolved to open
3. **Test the happy path** - Happy path is tested to ensure the
`reply_time` and `first_response_time` is correctly calculated

Test instructions:
1. Create a conversation with the last message from a customer and
resolve it
2. Have an agent reopen it and reply to it
4. When an agent replies, verify that the agent reply_time event is not
created for this message

To fix any existing data, I've written a small script:
https://gist.github.com/scmmishra/fdf458863f2d971978327bbfd5232d0c

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2025-06-27 10:48:07 +05:30
Sojan Jose
273c277d47 feat: Add conversation delete feature (#11677)
<img width="1240" alt="Screenshot 2025-06-05 at 12 39 04 AM"
src="https://github.com/user-attachments/assets/0071cd23-38c3-4638-946e-f1fbd11ec845"
/>


## Changes

Give the admins an option to delete conversation via the context menu

- enable conversation deletion in routes and controller
- expose delete API on conversations
- add delete option in conversation context menu and integrate with card
and list
- implement store action and mutation for delete
- update i18n with new strings

fixes: https://github.com/chatwoot/chatwoot/issues/947

---------

Co-authored-by: iamsivin <iamsivin@gmail.com>
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Co-authored-by: Pranav <pranavrajs@gmail.com>
2025-06-05 15:53:17 -05:00
Sojan Jose
bc42aec68e chore: upgrade ruby version to 3.4.4 (#11524)
- Chore upgrade ruby version to 3.4.4 before we migrate to rails 7.2
over #11037
2025-05-21 19:40:07 +05:30
Pranav
cbdac45824 feat: Improve Captain interactions, activity messages (#11493)
Show captain messages under the name of the assistant which generated
the message.

- Add support for `Captain::Assistant` sender type
- Add push_event_data for captain_assistants
- Add activity message handler for captain_assistants
- Update UI to show captain messages under the name of the assistant
- Fix the issue where openAI errors when image is sent
- Add support for custom name of the assistant

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
2025-05-16 19:27:57 -07:00
Shivam Mishra
c87b2109a9 feat: allow auto resolve waiting option (#11436) 2025-05-08 12:52:17 +05:30
Shivam Mishra
b533980880 feat: Add support for minutes in auto resolve feature (#11269)
### Summary

- Converts conversation auto-resolution duration from days to minutes
for more
granular control
- Updates validation to allow values from 10 minutes (minimum) to 999
days (maximum)
- Implements smart messaging to show appropriate time units in activity
messages

###  Changes

- Created migration to convert existing durations from days to minutes
(x1440)
- Updated conversation resolver to use minutes instead of days
- Added dynamic translation key selection based on duration value
- Updated related specs and documentation
- Added support for displaying durations in days, hours, or minutes
based on value

###  Test plan

- Verify account validation accepts new minute-based ranges
- Confirm existing account settings are correctly migrated
- Test auto-resolution works properly with minute values
- Ensure proper time unit display in activity messages

---------

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
2025-05-07 00:36:15 -07:00
Muhsin Keloth
e0097ab102 chore: Centralize outgoing message reply restrictions for all the channels (#11279) 2025-04-12 08:52:12 +05:30
Shivam Mishra
3a4249da11 feat: Add support for multi-language support for Captain (#11068)
This PR implements the following features

- FAQs from conversations will be generated in account language
- Contact notes will be generated in account language
- Copilot chat will respond in user language, unless the agent asks the
question in a different language

## Changes
### Copilot Chat

- Update the prompt to include an instruction for the language, the bot
will reply in asked language, but will default to account language
- Update the `ChatService` class to include pass the language to
`SystemPromptsService`

### FAQ and Contact note generation

- Update contact note generator and conversation generator to include
account locale
- Pass the account locale to `SystemPromptsService`


<details><summary>Screenshots</summary>

#### FAQs being generated in system langauge

![CleanShot 2025-03-12 at 13 32
30@2x](https://github.com/user-attachments/assets/84685bd8-3785-4432-aff3-419f60d96dd3)


#### Copilot responding in system language

![CleanShot 2025-03-12 at 13 47
03@2x](https://github.com/user-attachments/assets/38383293-4228-47bd-b74a-773e9a194f90)


</details>

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Pranav <pranav@chatwoot.com>
2025-03-19 18:25:33 -07:00
Pranav
10a0333980 feat(ee): Add copilot integration (v1) to the conversation sidebar (#10566) 2024-12-10 15:36:48 -08:00
Shivam Mishra
6e12ba04ab fix: last_activity_at is nil when conv is created (#9934)
The payload does not include last_activity_at when the conversation is created. Because of this the frontend is not able to sort the conversations when appending this. Another problem is that the last_activity_at is not always present, it is added only when a message is created, and it updates it. So this can be nil when the conversation is created, so we fallback to created_at only at the presentation layer
2024-08-12 15:15:49 +05:30
Sojan Jose
8520846b91 chore: Improved indexes for Conversations & Contacts [CW-3300] (#9475)
Based on our recent performant optimisation exercises, We have identified a better indexing strategy for conversations and contacts. The previous index on last_activity_at for conversations significantly slowed down conversation filters. Similarly, the new index on Contacts will allow the page rendering to improve for accounts with many contacts.

fixes: https://linear.app/chatwoot/issue/CW-3300/db-improvements
2024-05-15 16:10:39 -07:00
Sojan Jose
f6d7f3b665 fix: assignee_changed callback not getting triggered during conversation creation (#9334)
The reload method in our callback was refreshing the object and hence the saved_change_to_assignee_id? Method wasn't working in the following callbacks.

This impacted the listeners subscribing to the event `ASSIGNEE_CHANGE`, `TEAM_CHANGE` etc
2024-05-06 11:48:17 -07:00
Pranav
ffd47081bd chore(cleanup): Delete sentiment feature (#9304)
- The feature is unused, removing it for now, will bring it back with better models later.
2024-04-25 22:49:10 -07:00
Sivin Varghese
e49ef773d8 feat: UI to show the SLA threshold in chat screen (#9146)
- UI will show the breach in the conversation list.
- UI will show the breach in the conversation header.

Fixes: https://linear.app/chatwoot/issue/CW-3146/update-the-ui-to-show-the-breach-in-the-conversation-list
Fixes: https://linear.app/chatwoot/issue/CW-3144/ui-update-to-show-the-breachgoing-to-breach
2024-04-04 15:46:46 +05:30
Sojan Jose
4e28481f27 feat: Conversation API to return applied_sla and sla_events (#9174)
* chore: Add sla_events to push_event_data

* chore: Return SLA details in the API

* chore: feature lock sla push event data

* Update _conversation.json.jbuilder

* chore: rubocop fixes
2024-04-01 23:30:07 +05:30
Shivam Mishra
9917cb4273 fix: Convert cached_label_list to text (#9143) 2024-03-25 18:47:08 -07:00
Sojan Jose
ae4c8d818f feat: Ability to block contacts permanently (#8922)
Co-authored-by: Pranav <pranav@chatwoot.com>
2024-02-21 14:18:42 -08:00
Sojan Jose
7776b74126 chore: Apply fixes for items in rubocop_todo [CW-1806] (#8864)
This PR addresses several items listed in our rubocop_todo by implementing the necessary corrections and enhancements. As a result, we are now able to remove the rubocop_todo file entirely, streamlining our codebase and ensuring adherence to our coding standards.

fixes: https://linear.app/chatwoot/issue/CW-1806/chore-rubocop-audit
2024-02-07 13:36:04 +04:00
Pranav Raj S
d28f512de4 fix: Update the label name to use .strip to avoid unnecessary whitespace characters (#8541)
- The cache stores the labels as label1, label2. Without removing the whitespace, the output of cached_label_list_array would be [label1, [whitespace]label2], which doesn't match with the existing labels. This list is returned with proper label names.
2023-12-12 15:04:29 -08:00
Pranav Raj S
890515edfd feat(perf): Cache labels on the conversation model (#8527) 2023-12-11 18:27:55 -08:00
Sojan Jose
8c67ea56e7 chore: Campaign conversations should be created in open state (#8209)
- Ensure that conversations originating from campaigns are created in the open state.
2023-10-25 13:03:08 -07:00
Sojan Jose
e3b8c1fbb5 fix: Include waiting on agent conversations to unattended view (#7667)
Updating the `unattended` tab to include conversations where the customer responded and is awaiting an agent's response.

Previously it showed only the conversations where the first response was pending.

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2023-08-15 15:09:10 -07:00
Pranav Raj S
1a06bfd69c fix: Force account_id in message filters (#7705) 2023-08-10 21:58:25 -07:00
Pranav Raj S
1cac2e86c3 fix: Limit count query to return only 10 values (#7704) 2023-08-10 19:30:02 -07:00
Pranav Raj S
4baa4363f4 fix: Update unread_count being 0 if agent has not seen the conversation (#7690) 2023-08-07 18:50:31 -07:00
Nic Hippenmeyer
65190422c4 fix: Rename unread_since scope (#7267)
- This renames the unread_since scope to created_since, which more accurately describes what the scope returns.
- The EXTRACT(EPOCH FROM created_at) > (?) clause was also simplified and rewritten as created_at > ?, which is equivalent:
2023-07-27 12:29:21 +03:00
Tejaswini Chile
10dd0ba647 feat: Sentiment Analysis (#7475) 2023-07-12 15:03:31 +05:30
Pranav Raj S
93daaea19b feat: Add a sort option for conversations waiting for a reply from an agent (#7364) 2023-06-21 13:20:39 -07:00
Sojan Jose
595e6e79f0 chore: Add sla policy association to conversation (#7360)
Adds the sla policy association to the conversation

Fixes: https://linear.app/chatwoot/issue/CW-1615/applying-an-sla-to-the-conversation
2023-06-21 14:48:50 +05:30
Shivam Mishra
2f2ae88cba fix: unattended count mismatch in report and list (#7263) 2023-06-08 17:58:13 +05:30
Sojan Jose
7ab7bac6bf chore: Enable the new Rubocop rules (#7122)
fixes: https://linear.app/chatwoot/issue/CW-1574/renable-the-disabled-rubocop-rules
2023-05-19 14:37:10 +05:30
Muhsin Keloth
2c3160cfee feat: API to list all attachments for a conversation (#7059)
Fixes: https://linear.app/chatwoot/issue/CW-1678/api-to-list-all-attachments-for-a-conversation
2023-05-12 15:48:06 +05:30
Tejaswini Chile
6137a45214 chore: Update link in the reply summary email (#7024)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2023-05-09 17:39:09 -07:00
Shivam Mishra
d95283f5c2 feat: improvements to priority (#6981)
* fix: colors for urgent icon

* feat: trigger updated event on priority change

* fix: specs
2023-04-25 22:28:19 +05:30
Shivam Mishra
a34729c153 feat: add activity message for priority change (#6933)
* feat: add priority const

* feat: add toggle priority method

* feat: update controller route and specs

* refactor: status change method

* refactor: abstract label change and mute activity

* feat: add priority change_activity

* fix: interpolation for previous_changes

* refactor: reduce cognitive complexity of priority_change_activity

* refactor: move priority activity message handler to a separate module

* refactor: move typing logic to a service

* refactor: tests to reduce complexity

* fix: typo

* fix: constants

* fix: priority conditions

* fix: add a response

* fix: argument destructuring in I18n.t

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2023-04-20 16:41:53 +05:30
Shivam Mishra
9c0259da6b feat: add priority field to conversation (#6921) (#6927)
* feat: add priority

* feat: add indexes
2023-04-19 13:23:14 +05:30
Tejaswini Chile
6a0ca35de4 Feat: detect language of the message content (#6660) 2023-04-04 08:57:27 +05:30
Shivam Mishra
bc8e8f3bb5 feat: add index to conversation id and account_id (#6757)
- This PR adds an index to conversations id and account_id. This improves the performance of some reports query
2023-03-28 22:34:04 +05:30
Sojan Jose
de8c26dce8 chore: Additional indexes and fixes (#6675)
- Fix breakage related to the look-up job in Heroku deploys 
- Add additional db indexes for performance optimisations
2023-03-15 19:52:02 +05:30
Shivam Mishra
06ffaa90fc fix: bots included in time to response metrics (#6409)
* feat: ignore bots in avg_first_response_time

* feat: ignore bots in avg_first_response count

* feat: add bot handoff event

* feat: add handoff event listener and reporting event

* fix: ignore agent bot in first response

* refactor: calculate first_response with last handoff

* refactor: method defn order

* test: new reporting events

* feat: Revert "feat: ignore bots in avg_first_response count"

This reverts commit de1977c219a2e7a9180dd02272244fe3b3f7ce89.

* feat: Revert "feat: ignore bots in avg_first_response_time"

This reverts commit bb9171945d5e3b2f6015f4f96dd1b76b3efb6987.

* fix: business hour calculation for first_reply

* fix: event_start_time for first_response

* feat: add migration to recompute first_responses

* refactor: separate mute helpers for conversation

* refactor: rename migration

* refactor: migration script

* fix: migration typo

* fix: typo in query

* feat: update schema.rb

* Revert "feat: update schema.rb"

This reverts commit 353ef355f2d956dd219907bb66982dc90ca5d896.

* feat: update schema

* refactor: update events as a batch job

* fix: ignore the event if value is negative

* feat: don't create a new hand-off if it's already present

* refactor: break the action into smaller chunks

* refactor: update reporting listener spec

Handle the case to ensure extra bot handoffs are not created for a give conversation

* fix: import error

---------

Co-authored-by: Vishnu Narayanan <vishnu@chatwoot.com>
2023-02-25 09:48:48 +05:30
Pranav Raj S
7044eda281 chore: Add controllers for conversation participants (#6462)
Co-authored-by: Aswin Dev P.S <aswindevps@gmail.com>
Co-authored-by: Sojan Jose <sojan@chatwoot.com>
2023-02-15 16:33:31 -08:00
Sojan Jose
5cbfcfbfa0 chore: Limit conversation resolution Job (#6433)
We will be adding a limit to the resolution job so that it is performed at a spaced interval. This will ensure there won't be a sudden spike in resource usage

fixes: chatwoot/product#707
2023-02-13 14:00:52 +05:30
Nithin David Thomas
85b52a1d3f feat: Add a view for unattended conversations (#5890)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2022-11-29 08:18:00 -08:00
Fayaz Ahmed
9eb861a3b7 feat: Custom attributes in automations and refactor (#4548)
* Custom attributes

* Custom Attrs Manifest

* Fix dropdown values for custom attributes

* Handle edit mode for custom attributes

* Ported duplicate logic to a mixin

* fix Code climate issue

* Fix Codeclimate complexity warning

* Bug fix - Custom attributes getting duplicated

* Bug fixes and Code Climate issue fix

* Code Climate Issues Breakdown

* Fix test spec

* Add labels for Custom attributes in dropdown

* Refactor

* Refactor Automion mixin

* Refactor Mixin

* Refactor getOperator

* Fix getOperatorType

* File name method refactor

* Refactor appendNewCondition

* spec update

* Refactor methods

* Mixin Spec update

* Automation Mixins Test Specs

* Mixin Spec Rerun

* Automation validations mixin spec

* Automation helper test spec

* Send custom_attr key

* Fix spec fixtures

* fix: Changes for custom attribute type and lower case search

* fix: Specs

* fix: Specs

* fix: Ruby version change

* fix: Ruby version change

* Removes Lowercased values and fix label value in api payload

* Fix specs

* Fixed Query Spec

* Removed disabled labels if no attributes are present

* Code Climate Fixes

* fix: custom attribute with indifferent access

* fix: custom attribute with indifferent access

* Fix specs

* Minor label fix

* REtrigger circle ci build

* Update app/javascript/shared/mixins/specs/automationMixin.spec.js

* Update app/javascript/shared/mixins/specs/automationMixin.spec.js

* fix: Custom attribute case insensitivity search

* Add missing reset action method to input

* Set team_input to single select instead of multiple

* fix: remove value case check for date,boolean and number data type

* fix: cognitive complexity

* fix: cognitive complexity

* fix: Fixed activity message for automation system

* fix: Fixed activity message for automation system

* fix: Fixed activity message for automation system

* fix: codeclimate

* fix: codeclimate

* fix: action cable events for label update

* fix: codeclimate, conversation modela number of methods

* fix: codeclimate, conversation modela number of methods

* fix: codeclimate, conversation modela number of methods

* fix: codeclimate, conversation modela number of methods

* Fix margin bottom for attachment button

* Remove margin bottom to avoid conflict from macros

* Fix automation action query generator using the right key

* fix: not running message created event for activity message

* fix: not running message created event for activity message

* codeclimate fix

* codeclimate fix

* codeclimate fix

* Update app/javascript/dashboard/mixins/automations/methodsMixin.js

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>

* Update app/javascript/shared/mixins/specs/automationHelper.spec.js

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>

* Update app/javascript/dashboard/helper/automationHelper.js

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>

* Update app/javascript/dashboard/mixins/automations/methodsMixin.js

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
Co-authored-by: Tejaswini <tejaswini@chatwoot.com>
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Co-authored-by: Sojan Jose <sojan@pepalo.com>
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2022-11-10 10:53:29 +05:30
smartdev58
9c0cce0392 chore: Mark conversations as pending instead of reopen when bot is present (#5751)
With this change, conversations are marked as pending instead of reopening when a bot is connected to that Inbox. 

Fixes: #5668
2022-11-02 13:54:56 -07:00
Sojan Jose
3a71fe3260 chore: Stop duplicate websocket updates for conversation updates (#5711)
- remove extra dispatch for label updates
2022-10-21 18:06:02 -07:00
Tejaswini Chile
4a299a9441 fix: Add an action cable events for label updates (#5694)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2022-10-21 16:12:35 -07:00
Sojan Jose
5bd5395d31 chore: Add missing indexes for attachments table (#5588)
- index for attachments table
- index for conversations table
2022-10-10 15:23:33 -07:00
Jordan Brough
9ddf4c205c chore: Add index on conversations.uuid (#5179)
- We search for conversations by this attribute (e.g. in ReplyMailbox and CsatSurveyController) so it seems like we should have an index on it.
2022-08-23 19:05:30 +05:30