Skip to content

Commit

Permalink
CSA active but Chatbot Inactive (turned-off) (buerokratt#993)
Browse files Browse the repository at this point in the history
* Enhanced Active status change

* Added Scroll Ability to card

* Added enhancments to bot unavailable flow

* Added bulk notifications
  • Loading branch information
1AhmedYasser authored Nov 20, 2024
1 parent 7c9c646 commit ffe88d1
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 35 deletions.
12 changes: 12 additions & 0 deletions DSL/DMapper/hbs/return_open_chats_messages.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{{#each data}}
{
"channelId": "{{chatBaseId}}",
"timestamp": "{{getISODate}}",
"payload": {
"type": "message",
"messageId": "{{baseId}}"
}
}{{#unless @last}},{{/unless}}
{{/each}}
]
17 changes: 17 additions & 0 deletions DSL/DMapper/hbs/return_open_chats_notifications.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{{#each data}}
{
"index": {
"_index": "notifications"
}
},
{
"channelId": "{{chatBaseId}}",
"timestamp": "{{getISODate}}",
"payload": {
"type": "message",
"messageId": "{{baseId}}"
}
}{{#unless @last}},{{/unless}}
{{/each}}
]
3 changes: 2 additions & 1 deletion DSL/Resql/insert-message-content-by-customer-support-id.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ WHERE chat_base_id IN (SELECT base_id
WHERE id IN (SELECT max(id) FROM chat GROUP BY base_id)
AND customer_support_id = :customerSupportId
AND ended IS null)
AND id IN (SELECT max(id) FROM message GROUP BY chat_base_id);
AND id IN (SELECT max(id) FROM message GROUP BY chat_base_id)
RETURNING id, chat_base_id, base_id;
17 changes: 8 additions & 9 deletions DSL/Ruuter.private/DSL/POST/bots/active.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ setConfigurationValue:
value: ${isActive}
result: setConfigurationResult

check_if_bot_is_active:
switch:
- condition: ${isActive === 'true' || isActive === true}
next: return_result
next: insertChatAndMessageWhenBotNotActive

insertChatAndMessageWhenBotNotActive:
call: http.post
args:
url: "[#CHATBOT_RUUTER_PRIVATE_INTERNAL]/internal/chat-and-message-when-bot-is-not-active"
result: insertChatAndMessageWhenBotNotActiveResult

getConfigurationValue:
call: http.post
args:
url: "[#CHATBOT_RESQL]/get-configuration"
body:
key: "is_bot_active"
result: res
next: return_result

return_result:
return: ${res.response.body[0]?.value}
return: ${isActive}
status: 200
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,58 @@ assignBotName:
assign:
botName: ${bot_name_res.response.body[0].value}

endOldBotChats:
get_organization_base_config:
call: http.post
args:
url: "[#CHATBOT_RESQL]/insert-chat-ended-by-last-message-datetime"
body:
authorId: ${botName}
authorRole: "buerokratt"
content: "Teie vestlus antakse üle nõustajale."
currentDatetime: ${new Date().toISOString()}
currentStatus: "OPEN"
event: "inactive-chat-ended"
interval: "2 hours"
newStatus: "ENDED"
targetUser: "end-user"
result: end_old_bot_chats_res

insertMessageContent:
url: "[#CHATBOT_RESQL]/get-organization-base-config"
result: org_base_config_res
next: assign_organization_base_config

assign_organization_base_config:
assign:
base_config: ${org_base_config_res.response.body[0]}

notify_chats_and_return_chats_and_messages:
call: http.post
args:
url: "[#CHATBOT_RESQL]/insert-message-content-by-customer-support-id"
body:
customerSupportId: ${botName}
authorId: ${botName}
authorRole: "buerokratt"
content: "Teie vestlus antakse üle nõustajale."
event: ""
content: ${base_config.outsideWorkingHoursMessage}
event: "${base_config.outsideWorkingHoursAskForContacts === 'true' ? 'unavailable_organization_ask_contacts' : 'unavailable_organization'}"
created: ${new Date().toISOString()}
result: insert_message_content_res
result: res

insertChatCustomerSupport:
map_open_chats_messages:
call: http.post
args:
url: "[#CHATBOT_RESQL]/insert-chat-customer-support-by-customer-support-id"
url: "[#CHATBOT_DMAPPER]/hbs/chat-bot/return_open_chats_messages"
headers:
type: json
body:
customerSupportId: ${botName}
result: insert_chat_customer_support_res
data: ${res.response.body}
result: open_chat_messages_res

map_open_chats_notifications:
call: http.post
args:
url: "[#CHATBOT_DMAPPER]/hbs/chat-bot/return_open_chats_notifications"
headers:
type: json
body:
data: ${res.response.body}
result: open_chat_notifications_res

notify_end_users:
template: messages/notify-all
requestType: templates
body:
chats: ${open_chat_messages_res.response.body}
notifications: ${open_chat_notifications_res.response.body}
result: notification_res

return_result:
return: "success"
return: "Success"
next: end
20 changes: 20 additions & 0 deletions DSL/Ruuter.private/DSL/TEMPLATES/messages/notify-all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
clear_notifications:
call: http.post
args:
url: "[#CHATBOT_OPENSEARCH]/notifications/_delete_by_query?conflicts=proceed"
body:
query:
terms:
channelId: ${incoming.body.chats.map(chat => chat.channelId)}
result: clear_res

notify:
call: http.post
args:
url: "[#CHATBOT_NOTIFICATIONS]/bulk-notifications"
body:
operations: ${incoming.body.notifications}
result: notify_res

return_result:
return: "Notification sent"
4 changes: 4 additions & 0 deletions GUI/src/components/Card/Card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
}
}

&--scrollable {
overflow-y: auto;
}

&__header,
&__body,
&__footer {
Expand Down
4 changes: 3 additions & 1 deletion GUI/src/components/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type CardProps = {
borderless?: boolean;
isHeaderLight?: boolean;
isBodyDivided?: boolean;
isScrollable?: boolean;
};

const Card: FC<PropsWithChildren<CardProps>> = ({
Expand All @@ -17,10 +18,11 @@ const Card: FC<PropsWithChildren<CardProps>> = ({
borderless,
isHeaderLight,
isBodyDivided,
isScrollable = false,
children,
}) => {
return (
<div className={clsx('card', { 'card--borderless': borderless })}>
<div className={clsx('card', { 'card--borderless': borderless, 'card--scrollable': isScrollable })}>
{header && (
<div className={`card__header ${isHeaderLight ? 'white' : ''}`}>
{header}
Expand Down
1 change: 1 addition & 0 deletions GUI/src/pages/Settings/SettingsWorkingTime/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const SettingsWorkingTime: FC = () => {
key={key}
isHeaderLight={true}
isBodyDivided={true}
isScrollable={true}
footer={
<Track justify="end">
<Button onClick={handleFormSubmit}>{t('global.save')}</Button>
Expand Down
5 changes: 5 additions & 0 deletions notification-server/src/openSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ async function searchNotification({ channelId, connectionId, sender }) {
}
}

async function sendBulkNotification({ operations }) {
await client.bulk({ body: operations });
}

async function markAsSent({ _index, _id }, connectionId) {
await client.update({
index: _index,
Expand Down Expand Up @@ -145,4 +149,5 @@ module.exports = {
enqueueChatId,
dequeueChatId,
findChatIdOrder,
sendBulkNotification
};
11 changes: 10 additions & 1 deletion notification-server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
buildNotificationSearchInterval,
buildQueueCounter,
} = require("./addOns");
const { enqueueChatId, dequeueChatId } = require("./openSearch");
const { enqueueChatId, dequeueChatId, sendBulkNotification } = require("./openSearch");
const { addToTerminationQueue, removeFromTerminationQueue } = require("./terminationQueue");
const helmet = require("helmet");
const cookieParser = require("cookie-parser");
Expand Down Expand Up @@ -38,6 +38,15 @@ app.get("/sse/queue/:id", (req, res) => {
});
});

app.post("/bulk-notifications", async (req, res) => {
try {
await sendBulkNotification(req.body);
res.status(200).json({ response: 'sent successfully' });
} catch {
res.status(500).json({ response: 'error' });
}
});

app.post("/enqueue", async (req, res) => {
try{
await enqueueChatId(req.body.id);
Expand Down

0 comments on commit ffe88d1

Please sign in to comment.