Skip to content

Commit

Permalink
1068 Displaying chats for deletion (buerokratt#1069)
Browse files Browse the repository at this point in the history
* Added updated SQL to display proper chats.

* Refactored initial form with dates, to display.

* Added new dsl, updated GUI, added new component
  • Loading branch information
ExiRain authored Dec 13, 2024
1 parent 336c0f7 commit a41ca7a
Show file tree
Hide file tree
Showing 9 changed files with 873 additions and 31 deletions.
20 changes: 20 additions & 0 deletions DSL/Resql/get-chats-to-be-removed-count.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
WITH ChatsToDelete AS (
SELECT COUNT(*) AS total_count
FROM chat c
WHERE c.ended IS NOT NULL
AND c.status = 'ENDED'
AND (
(end_user_id IS NOT NULL AND end_user_id <> '' AND ended::date <= :auth_date::date)
OR
(end_user_id IS NULL OR end_user_id = '' AND ended::date <= :anon_date::date)
)
AND EXISTS (
SELECT 1
FROM message m
WHERE m.chat_base_id = c.base_id
AND m.content IS NOT NULL
AND m.content <> ''
)
)
SELECT total_count
FROM ChatsToDelete;
192 changes: 192 additions & 0 deletions DSL/Resql/get-chats-to-be-removed.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
WITH MaxChatHistoryComments AS (
SELECT MAX(id) AS maxId
FROM chat_history_comments
GROUP BY chat_id
),
ChatHistoryComments AS (
SELECT comment, chat_id
FROM chat_history_comments
JOIN MaxChatHistoryComments ON id = maxId
),
MessageWithContent AS (
SELECT
MAX(id) AS maxId,
MIN(id) AS minId
FROM message
WHERE content <> ''
AND content <> 'message-read'
GROUP BY chat_base_id
),
FirstContentMessage AS (
SELECT created, chat_base_id
FROM message
JOIN MessageWithContent ON message.id = MessageWithContent.minId
),
LastContentMessage AS (
SELECT content, chat_base_id
FROM message
JOIN MessageWithContent ON message.id = MessageWithContent.maxId
),
TitleVisibility AS (
SELECT value
FROM configuration
WHERE key = 'is_csa_title_visible'
AND NOT deleted
ORDER BY id DESC
LIMIT 1
),
FulfilledMessages AS (
SELECT MAX(id) AS maxId
FROM message
WHERE event = 'contact-information-fulfilled'
GROUP BY chat_base_id
),
ContactsMessage AS (
SELECT chat_base_id, content
FROM message
JOIN FulfilledMessages ON id = maxId
),
MaxMessages AS (
SELECT MAX(id) AS maxId
FROM message
GROUP BY chat_base_id
),
Messages AS (
SELECT event, updated, chat_base_id
FROM message
JOIN MaxMessages ON id = maxID
),
MaxChats AS (
SELECT MAX(id) AS maxId
FROM chat
WHERE ended IS NOT NULL
AND status <> 'IDLE'
AND (
(end_user_id IS NOT NULL AND end_user_id <> '' AND ended::date <= :auth_date::date)
OR
(end_user_id IS NULL OR end_user_id = '' AND ended::date <= :anon_date::date)
)
GROUP BY base_id
),
EndedChatMessages AS (
SELECT
base_id,
customer_support_id,
customer_support_display_name,
csa_title,
end_user_id,
end_user_first_name,
end_user_last_name,
end_user_email,
end_user_phone,
end_user_os,
end_user_url,
status,
updated,
ended,
forwarded_to_name,
received_from,
labels,
created,
feedback_text,
feedback_rating
FROM chat
RIGHT JOIN MaxChats ON id = maxId
),
RatedChats AS (
SELECT MAX(feedback_rating) AS rating
FROM chat
WHERE feedback_rating IS NOT NULL
GROUP BY base_id
),
RatedChatsCount AS (
SELECT COUNT(rating) AS total FROM RatedChats
),
Promoters AS (
SELECT COUNT(rating) AS p FROM RatedChats WHERE rating >= 9
),
Detractors AS (
SELECT COUNT(rating) AS d FROM RatedChats WHERE rating <= 6
),
NPS AS (
SELECT ROUND(((p / (GREATEST(total, 1) * 1.0)) - (d / (GREATEST(total, 1) * 1.0))) * 100.0, 2) AS nps
FROM RatedChatsCount
CROSS JOIN Promoters
CROSS JOIN Detractors
)
SELECT c.base_id AS id,
c.customer_support_id,
c.customer_support_display_name,
(CASE WHEN TitleVisibility.value = 'true' THEN c.csa_title ELSE '' END) AS csa_title,
c.end_user_id,
c.end_user_first_name,
c.end_user_last_name,
c.end_user_email,
c.end_user_phone,
c.end_user_os,
c.end_user_url,
c.status,
FirstContentMessage.created,
c.updated,
c.ended,
c.forwarded_to_name,
c.received_from,
c.labels,
s.comment,
LastContentMessage.content AS last_message,
(CASE WHEN m.event = '' THEN NULL ELSE LOWER(m.event) END) AS last_message_event,
ContactsMessage.content AS contacts_message,
m.updated AS last_message_timestamp,
c.feedback_text,
c.feedback_rating,
nps,
CEIL(COUNT(*) OVER() / :page_size::DECIMAL) AS total_pages
FROM EndedChatMessages AS c
JOIN Messages AS m ON c.base_id = m.chat_base_id
LEFT JOIN ChatHistoryComments AS s ON s.chat_id = m.chat_base_id
JOIN LastContentMessage ON c.base_id = LastContentMessage.chat_base_id
JOIN FirstContentMessage ON c.base_id = FirstContentMessage.chat_base_id
LEFT JOIN ContactsMessage ON ContactsMessage.chat_base_id = c.base_id
CROSS JOIN TitleVisibility
CROSS JOIN NPS
WHERE (
:search IS NULL OR
:search = '' OR
LOWER(c.customer_support_display_name) LIKE LOWER('%' || :search || '%') OR
LOWER(c.end_user_first_name) LIKE LOWER('%' || :search || '%') OR
LOWER(ContactsMessage.content) LIKE LOWER('%' || :search || '%') OR
LOWER(s.comment) LIKE LOWER('%' || :search || '%') OR
LOWER(c.status) LIKE LOWER('%' || :search || '%') OR
LOWER(m.event) LIKE LOWER('%' || :search || '%') OR
LOWER(c.base_id) LIKE LOWER('%' || :search || '%') OR
TO_CHAR(FirstContentMessage.created, 'DD.MM.YYYY HH24:MI:SS') LIKE '%' || :search || '%' OR
TO_CHAR(c.ended, 'DD.MM.YYYY HH24:MI:SS') LIKE '%' || :search || '%' OR
EXISTS (
SELECT 1
FROM message AS msg
WHERE msg.chat_base_id = c.base_id
AND LOWER(msg.content) LIKE LOWER('%' || :search || '%')
)
)
ORDER BY
CASE WHEN :sorting = 'created asc' THEN FirstContentMessage.created END ASC,
CASE WHEN :sorting = 'created desc' THEN FirstContentMessage.created END DESC,
CASE WHEN :sorting = 'ended asc' THEN c.ended END ASC,
CASE WHEN :sorting = 'ended desc' THEN c.ended END DESC,
CASE WHEN :sorting = 'customerSupportDisplayName asc' THEN c.customer_support_display_name END ASC,
CASE WHEN :sorting = 'customerSupportDisplayName desc' THEN c.customer_support_display_name END DESC,
CASE WHEN :sorting = 'endUserName asc' THEN c.end_user_first_name END ASC,
CASE WHEN :sorting = 'endUserName desc' THEN c.end_user_first_name END DESC,
CASE WHEN :sorting = 'endUserId asc' THEN c.end_user_id END ASC,
CASE WHEN :sorting = 'endUserId desc' THEN c.end_user_id END desc,
CASE WHEN :sorting = 'contactsMessage asc' THEN ContactsMessage.content END ASC,
CASE WHEN :sorting = 'contactsMessage desc' THEN ContactsMessage.content END DESC,
CASE WHEN :sorting = 'comment asc' THEN s.comment END ASC,
CASE WHEN :sorting = 'comment desc' THEN s.comment END DESC,
CASE WHEN :sorting = 'labels asc' THEN c.labels END ASC,
CASE WHEN :sorting = 'labels desc' THEN c.labels END DESC,
CASE WHEN :sorting = 'status asc' THEN c.status END ASC,
CASE WHEN :sorting = 'status desc' THEN c.status END DESC,
CASE WHEN :sorting = 'id asc' THEN c.base_id END ASC,
CASE WHEN :sorting = 'id desc' THEN c.base_id END DESC
OFFSET ((GREATEST(:page, 1) - 1) * :page_size) LIMIT :page_size;
50 changes: 50 additions & 0 deletions DSL/Ruuter.private/DSL/POST/agents/chats/removable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
declaration:
call: declare
version: 0.1
description: "Decription placeholder for 'ENDED-CHATS'"
method: post
accepts: json
returns: json
namespace: backoffice
allowlist:
body:
- field: endDate
type: string
description: "Body field 'endDate'"
- field: startDate
type: string
description: "Body field 'startDate'"
- field: page
type: number
description: "Body field 'page'"
- field: page_size
type: number
description: "Body field 'page_size'"
- field: sorting
type: string
description: "Body field 'sorting'"
- field: search
type: string
description: "Body field 'search'"

extractRequestData:
assign:
startDate: "${incoming.body.startDate}"
endDate: "${incoming.body.endDate}"

getEndedChats:
call: http.post
args:
url: "[#CHATBOT_RESQL]/get-chats-to-be-removed"
body:
auth_date: ${startDate}
anon_date: ${endDate}
page: ${incoming.body.page}
page_size: ${incoming.body.page_size}
sorting: ${incoming.body.sorting}
search: ${incoming.body.search}
result: res

returnSuccess:
return: ${res.response.body}
next: end
34 changes: 34 additions & 0 deletions DSL/Ruuter.private/DSL/POST/agents/removable-count.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
declaration:
call: declare
version: 0.1
description: "Decription placeholder for 'ENDED-CHATS-COUNT'"
method: post
accepts: json
returns: json
namespace: backoffice
allowlist:
body:
- field: authDate
type: string
description: "Body field 'authDate'"
- field: anonDate
type: string
description: "Body field 'anonDate'"

extractRequestData:
assign:
authDate: "${incoming.body.authDate}"
anonDate: "${incoming.body.anonDate}"

getEndedChats:
call: http.post
args:
url: "[#CHATBOT_RESQL]/get-chats-to-be-removed-count"
body:
auth_date: ${authDate}
anon_date: ${anonDate}
result: res

returnSuccess:
return: ${res.response.body}
next: end
3 changes: 2 additions & 1 deletion GUI/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ REACT_APP_SERVICE_ID=conversations,settings,monitoring
REACT_APP_NOTIFICATION_NODE_URL=http://localhost:4040
REACT_APP_CSP=upgrade-insecure-requests; default-src 'self'; font-src 'self' data:; img-src 'self' data:; script-src 'self' 'unsafe-eval' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; object-src 'none'; connect-src 'self' http://localhost:8086 http://localhost:8088 http://localhost:8085 http://localhost:4040 https://admin.dev.buerokratt.ee/chat/menu.json;
REACT_APP_ENABLE_HIDDEN_FEATURES=TRUE
REACT_APP_MENU_JSON=[{"id":"conversations","label":{"et":"Vestlused","en":"Conversations"},"path":"/chat","children":[{"label":{"et":"Vastamata","en":"Unanswered"},"path":"/unanswered"},{"label":{"et":"Aktiivsed","en":"Active"},"path":"/active"},{"label":{"et":"Ootel","en":"Pending"},"path":"/pending"},{"label":{"et":"Ajalugu","en":"History"},"path":"/history"}]},{"id":"training","label":{"et":"Treening","en":"Training"},"path":"/training","children":[{"label":{"et":"Treening","en":"Training"},"path":"/training","children":[{"label":{"et":"Teemad","en":"Themes"},"path":"/training/intents"},{"label":{"et":"Avalikud teemad","en":"Public themes"},"path":"/training/common-intents"},{"label":{"et":"Teemade järeltreenimine","en":"Post training themes"},"path":"/training/intents-followup-training"},{"label":{"et":"Vastused","en":"Answers"},"path":"/training/responses"},{"label":{"et":"Kasutuslood","en":"User Stories"},"path":"/training/stories"},{"label":{"et":"Konfiguratsioon","en":"Configuration"},"path":"/training/configuration"},{"label":{"et":"Vormid","en":"Forms"},"path":"/training/forms"},{"label":{"et":"Mälukohad","en":"Slots"},"path":"/training/slots"},{"label":{"et":"Automatic Teenused","en":"Automatic Services"},"path":"/auto-services"}]},{"label":{"et":"Ajaloolised vestlused","en":"Historical conversations"},"path":"/history","children":[{"label":{"et":"Ajalugu","en":"History"},"path":"/history/history"},{"label":{"et":"Pöördumised","en":"Appeals"},"path":"/history/appeal"}]},{"label":{"et":"Mudelipank ja analüütika","en":"Modelbank and analytics"},"path":"/analytics","children":[{"label":{"et":"Teemade ülevaade","en":"Overview of topics"},"path":"/analytics/overview"},{"label":{"et":"Mudelite võrdlus","en":"Comparison of models"},"path":"/analytics/models"},{"label":{"et":"Testlood","en":"testTracks"},"path":"/analytics/testcases"}]},{"label":{"et":"Treeni uus mudel","en":"Train new model"},"path":"/train-new-model"}]},{"id":"analytics","label":{"et":"Analüütika","en":"Analytics"},"path":"/analytics","children":[{"label":{"et":"Ülevaade","en":"Overview"},"path":"/overview"},{"label":{"et":"Vestlused","en":"Chats"},"path":"/chats"},{"label":{"et":"Tagasiside","en":"Feedback"},"path":"/feedback"},{"label":{"et":"Nõustajad","en":"Advisors"},"path":"/advisors"},{"label":{"et":"Avaandmed","en":"Reports"},"path":"/reports"}]},{"id":"services","label":{"et":"Teenused","en":"Services"},"path":"/services","children":[{"label":{"et":"Ülevaade","en":"Overview"},"path":"/overview"},{"label":{"et":"Uus teenus","en":"New Service"},"path":"/newService"},{"label":{"et":"Automatic Teenused","en":"Automatic Services"},"path":"/auto-services"},{"label":{"et":"Probleemsed teenused","en":"Faulty Services"},"path":"/faultyServices"}]},{"id":"settings","label":{"et":"Haldus","en":"Administration"},"path":"/settings","children":[{"label":{"et":"Kasutajad","en":"Users"},"path":"/users"},{"label":{"et":"Vestlusbot","en":"Chatbot"},"path":"/chatbot","children":[{"label":{"et":"Seaded","en":"Settings"},"path":"/chatbot/settings"},{"label":{"et":"Tervitussõnum","en":"Welcome message"},"path":"/chatbot/welcome-message"},{"label":{"et":"Välimus ja käitumine","en":"Appearance and behavior"},"path":"/chatbot/appearance"},{"label":{"et":"Erakorralised teated","en":"Emergency notices"},"path":"/chatbot/emergency-notices"}]},{"label":{"et":"Asutuse tööaeg","en":"Office opening hours"},"path":"/working-time"},{"label":{"et":"Sessiooni pikkus","en":"Session length"},"path":"/session-length"},{"label":{"et":"Sessiooni pikkus","en":"Delete Conversations"},"path":"/delete-conversations"}]},{"id":"monitoring","label":{"et":"Seire","en":"Monitoring"},"path":"/monitoring","children":[{"label":{"et":"Aktiivaeg","en":"Working hours"},"path":"/uptime"}]}]
REACT_APP_MENU_JSON=[{"id":"conversations","label":{"et":"Vestlused","en":"Conversations"},"path":"/chat","children":[{"label":{"et":"Vastamata","en":"Unanswered"},"path":"/unanswered"},{"label":{"et":"Aktiivsed","en":"Active"},"path":"/active"},{"label":{"et":"Ootel","en":"Pending"},"path":"/pending"},{"label":{"et":"Ajalugu","en":"History"},"path":"/history"}]},{"id":"training","label":{"et":"Treening","en":"Training"},"path":"/training","children":[{"label":{"et":"Treening","en":"Training"},"path":"/training","children":[{"label":{"et":"Teemad","en":"Themes"},"path":"/training/intents"},{"label":{"et":"Avalikud teemad","en":"Public themes"},"path":"/training/common-intents"},{"label":{"et":"Teemade järeltreenimine","en":"Post training themes"},"path":"/training/intents-followup-training"},{"label":{"et":"Vastused","en":"Answers"},"path":"/training/responses"},{"label":{"et":"Kasutuslood","en":"User Stories"},"path":"/training/stories"},{"label":{"et":"Konfiguratsioon","en":"Configuration"},"path":"/training/configuration"},{"label":{"et":"Vormid","en":"Forms"},"path":"/training/forms"},{"label":{"et":"Mälukohad","en":"Slots"},"path":"/training/slots"},{"label":{"et":"Automatic Teenused","en":"Automatic Services"},"path":"/auto-services"}]},{"label":{"et":"Ajaloolised vestlused","en":"Historical conversations"},"path":"/history","children":[{"label":{"et":"Ajalugu","en":"History"},"path":"/history/history"},{"label":{"et":"Pöördumised","en":"Appeals"},"path":"/history/appeal"}]},{"label":{"et":"Mudelipank ja analüütika","en":"Modelbank and analytics"},"path":"/analytics","children":[{"label":{"et":"Teemade ülevaade","en":"Overview of topics"},"path":"/analytics/overview"},{"label":{"et":"Mudelite võrdlus","en":"Comparison of models"},"path":"/analytics/models"},{"label":{"et":"Testlood","en":"testTracks"},"path":"/analytics/testcases"}]},{"label":{"et":"Treeni uus mudel","en":"Train new model"},"path":"/train-new-model"}]},{"id":"analytics","label":{"et":"Analüütika","en":"Analytics"},"path":"/analytics","children":[{"label":{"et":"Ülevaade","en":"Overview"},"path":"/overview"},{"label":{"et":"Vestlused","en":"Chats"},"path":"/chats"},{"label":{"et":"Tagasiside","en":"Feedback"},"path":"/feedback"},{"label":{"et":"Nõustajad","en":"Advisors"},"path":"/advisors"},{"label":{"et":"Avaandmed","en":"Reports"},"path":"/reports"}]},{"id":"services","label":{"et":"Teenused","en":"Services"},"path":"/services","children":[{"label":{"et":"Ülevaade","en":"Overview"},"path":"/overview"},{"label":{"et":"Uus teenus","en":"New Service"},"path":"/newService"},{"label":{"et":"Automatic Teenused","en":"Automatic Services"},"path":"/auto-services"},{"label":{"et":"Probleemsed teenused","en":"Faulty Services"},"path":"/faultyServices"}]},{"id":"settings","label":{"et":"Haldus","en":"Administration"},"path":"/settings","children":[{"label":{"et":"Kasutajad","en":"Users"},"path":"/users"},{"label":{"et":"Vestlusbot","en":"Chatbot"},"path":"/chatbot","children":[{"label":{"et":"Seaded","en":"Settings"},"path":"/chatbot/settings"},{"label":{"et":"Tervitussõnum","en":"Welcome message"},"path":"/chatbot/welcome-message"},{"label":{"et":"Välimus ja käitumine","en":"Appearance and behavior"},"path":"/chatbot/appearance"},{"label":{"et":"Erakorralised teated","en":"Emergency notices"},"path":"/chatbot/emergency-notices"}]},{"label":{"et":"Asutuse tööaeg","en":"Office opening hours"},"path":"/working-time"},{"label":{"et":"Sessiooni pikkus","en":"Session length"},"path":"/session-length"},{"label":{"et":"Vestluse Kustutamine","en":"Delete Conversations"},"path":"/delete-conversations"}]},{"id":"monitoring","label":{"et":"Seire","en":"Monitoring"},"path":"/monitoring","children":[{"label":{"et":"Aktiivaeg","en":"Working hours"},"path":"/uptime"}]}]
f
14 changes: 14 additions & 0 deletions GUI/src/components/DeletionChatOverview/DeletionChatOverview.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import 'src/styles/tools/spacing';
@import 'src/styles/tools/color';
@import 'src/styles/settings/variables/other';
@import 'src/styles/settings/variables/typography';

.full-width {
width: 100%
}

.margin-auto {
padding-right: 20px;
padding-bottom: 20px ;
margin: auto;
}
Loading

0 comments on commit a41ca7a

Please sign in to comment.