Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
141 lines
4.1 KiB
TypeScript
141 lines
4.1 KiB
TypeScript
import { ILivechatAgentStatus } from '@rocket.chat/core-typings';
|
|
import type {
|
|
AtLeast,
|
|
ILivechatDepartment,
|
|
IOmnichannelRoom,
|
|
IOmnichannelRoomExtraData,
|
|
IOmnichannelRoomInfo,
|
|
IOmnichannelSource,
|
|
IUser,
|
|
SelectedAgent,
|
|
InquiryWithAgentInfo,
|
|
ILivechatInquiryRecord,
|
|
} from '@rocket.chat/core-typings';
|
|
import { LivechatContacts, LivechatDepartmentAgents, LivechatVisitors, Users } from '@rocket.chat/models';
|
|
import { makeFunction } from '@rocket.chat/patch-injection';
|
|
|
|
import { setUserStatusLivechat } from './utils';
|
|
import { sendToCRM } from '../../hooks/omnichannel/sendToCRM';
|
|
import { settings } from '../../settings';
|
|
import { callbacks } from '../callbacks';
|
|
import { notifyOnLivechatDepartmentAgentChangedByDepartmentId } from '../notifyListener';
|
|
|
|
export async function afterAgentUserActivated(user: IUser) {
|
|
if (!user.roles.includes('livechat-agent')) {
|
|
throw new Error('invalid-user-role');
|
|
}
|
|
callbacks.runAsync('livechat.onNewAgentCreated', user._id);
|
|
}
|
|
|
|
export async function afterAgentAdded<T extends AtLeast<IUser, '_id'>>(user: T): Promise<T> {
|
|
await setUserStatusLivechat(user._id, user.status !== 'offline' ? ILivechatAgentStatus.AVAILABLE : ILivechatAgentStatus.NOT_AVAILABLE);
|
|
callbacks.runAsync('livechat.onNewAgentCreated', user._id);
|
|
|
|
return user;
|
|
}
|
|
|
|
export async function afterRemoveAgent(user: AtLeast<IUser, '_id' | 'username'>) {
|
|
await callbacks.run('livechat.afterAgentRemoved', { agent: user });
|
|
return true;
|
|
}
|
|
|
|
export async function afterDepartmentArchived(department: AtLeast<ILivechatDepartment, '_id' | 'businessHourId'>) {
|
|
await LivechatDepartmentAgents.disableAgentsByDepartmentId(department._id);
|
|
|
|
void notifyOnLivechatDepartmentAgentChangedByDepartmentId(department._id);
|
|
|
|
await callbacks.run('livechat.afterDepartmentArchived', department);
|
|
}
|
|
|
|
export async function afterDepartmentUnarchived(department: AtLeast<ILivechatDepartment, '_id' | 'businessHourId'>) {
|
|
await LivechatDepartmentAgents.enableAgentsByDepartmentId(department._id);
|
|
|
|
void notifyOnLivechatDepartmentAgentChangedByDepartmentId(department._id);
|
|
}
|
|
|
|
export const checkDefaultAgentOnNewRoom = makeFunction(
|
|
async (defaultAgent?: SelectedAgent, _params?: { visitorId?: string; source?: IOmnichannelSource }) => defaultAgent,
|
|
);
|
|
|
|
export const beforeDelegateAgent = async (
|
|
agent: SelectedAgent | undefined,
|
|
{ department }: { department?: string } = {},
|
|
): Promise<SelectedAgent | null | undefined> => {
|
|
if (agent) {
|
|
return agent;
|
|
}
|
|
|
|
if (!settings.get('Livechat_assign_new_conversation_to_bot')) {
|
|
return null;
|
|
}
|
|
|
|
if (department) {
|
|
return LivechatDepartmentAgents.getNextBotForDepartment(department);
|
|
}
|
|
|
|
return Users.getNextBotAgent();
|
|
};
|
|
|
|
export const beforeNewRoom = makeFunction(
|
|
async (roomInfo: IOmnichannelRoomInfo, _extraData?: IOmnichannelRoomExtraData): Promise<Partial<IOmnichannelRoom>> => roomInfo,
|
|
);
|
|
|
|
export const onNewRoom = makeFunction(async (room: IOmnichannelRoom) => {
|
|
const {
|
|
_id,
|
|
v: { _id: guestId },
|
|
source,
|
|
contactId,
|
|
} = room;
|
|
|
|
const lastChat = {
|
|
_id,
|
|
ts: new Date(),
|
|
};
|
|
|
|
await Promise.all([
|
|
LivechatVisitors.setLastChatById(guestId, lastChat),
|
|
contactId
|
|
? LivechatContacts.updateLastChatById(
|
|
contactId,
|
|
{
|
|
visitorId: guestId,
|
|
source,
|
|
},
|
|
lastChat,
|
|
)
|
|
: undefined,
|
|
]);
|
|
|
|
if (settings.get('Livechat_webhook_on_start')) {
|
|
await sendToCRM('LivechatSessionStart', room);
|
|
}
|
|
});
|
|
|
|
export const afterTakeInquiry = makeFunction(
|
|
async ({ room }: { inquiry: InquiryWithAgentInfo; room: IOmnichannelRoom; agent: { agentId: string; username: string } }) => {
|
|
if (!settings.get('Livechat_webhook_on_chat_taken')) {
|
|
return;
|
|
}
|
|
await sendToCRM('LivechatSessionTaken', room);
|
|
},
|
|
);
|
|
|
|
export const afterInquiryQueued = makeFunction(async (_inquiry: ILivechatInquiryRecord) => {
|
|
return void 0;
|
|
});
|
|
|
|
export const afterRoomQueued = makeFunction((room: IOmnichannelRoom) => {
|
|
if (!settings.get('Livechat_webhook_on_chat_queued')) {
|
|
return;
|
|
}
|
|
|
|
return sendToCRM('LivechatSessionQueued', room);
|
|
});
|
|
|
|
export const beforeRouteChat = makeFunction(
|
|
async (inquiry: ILivechatInquiryRecord, _agent?: SelectedAgent | null): Promise<ILivechatInquiryRecord | null | undefined> => {
|
|
return inquiry;
|
|
},
|
|
);
|