Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into new/…
Browse files Browse the repository at this point in the history
…modalRegions

* 'develop' of github.com:RocketChat/Rocket.Chat:
  regression: Timestamp missing milliseconds (#31963)
  regression: Livechat offline color not being applied (#31962)
  feat: Use external service for triggers (#31268)
  • Loading branch information
gabriellsh committed Mar 12, 2024
2 parents 196256f + 9408ec8 commit 2e592b1
Show file tree
Hide file tree
Showing 40 changed files with 1,721 additions and 467 deletions.
7 changes: 7 additions & 0 deletions .changeset/rich-rocks-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@rocket.chat/meteor': minor
'@rocket.chat/core-typings': minor
'@rocket.chat/livechat': minor
---

Added new Livechat trigger action "Send message (external service)"
18 changes: 12 additions & 6 deletions apps/meteor/app/livechat/server/api/lib/livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
IOmnichannelRoom,
SelectedAgent,
} from '@rocket.chat/core-typings';
import { License } from '@rocket.chat/license';
import { EmojiCustom, LivechatTrigger, LivechatVisitors, LivechatRooms, LivechatDepartment } from '@rocket.chat/models';
import { Random } from '@rocket.chat/random';
import { Meteor } from 'meteor/meteor';
Expand All @@ -21,12 +22,17 @@ export function online(department: string, skipSettingCheck = false, skipFallbac

async function findTriggers(): Promise<Pick<ILivechatTrigger, '_id' | 'actions' | 'conditions' | 'runOnce'>[]> {
const triggers = await LivechatTrigger.findEnabled().toArray();
return triggers.map(({ _id, actions, conditions, runOnce }) => ({
_id,
actions,
conditions,
runOnce,
}));
const hasLicense = License.hasModule('livechat-enterprise');
const premiumActions = ['use-external-service'];

return triggers
.filter(({ actions }) => hasLicense || actions.some((c) => !premiumActions.includes(c.name)))
.map(({ _id, actions, conditions, runOnce }) => ({
_id,
actions,
conditions,
runOnce,
}));
}

async function findDepartments(
Expand Down
74 changes: 74 additions & 0 deletions apps/meteor/client/views/omnichannel/triggers/ConditionForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import type { SelectOption } from '@rocket.chat/fuselage';
import { Field, FieldGroup, FieldLabel, FieldRow, NumberInput, Select, TextInput } from '@rocket.chat/fuselage';
import { useUniqueId } from '@rocket.chat/fuselage-hooks';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentProps } from 'react';
import React, { useMemo } from 'react';
import type { Control } from 'react-hook-form';
import { Controller, useWatch } from 'react-hook-form';

import type { TriggersPayload } from './EditTrigger';

type ConditionFormType = ComponentProps<typeof Field> & {
index: number;
control: Control<TriggersPayload>;
};

export const ConditionForm = ({ control, index, ...props }: ConditionFormType) => {
const conditionFieldId = useUniqueId();
const t = useTranslation();
const conditionName = useWatch({ control, name: `conditions.${index}.name` });

const placeholders: { [conditionName: string]: string } = useMemo(
() => ({
'page-url': t('Enter_a_regex'),
'time-on-site': t('Time_in_seconds'),
}),
[t],
);

const conditionOptions: SelectOption[] = useMemo(
() => [
['page-url', t('Visitor_page_URL')],
['time-on-site', t('Visitor_time_on_site')],
['chat-opened-by-visitor', t('Chat_opened_by_visitor')],
['after-guest-registration', t('After_guest_registration')],
],
[t],
);

const conditionValuePlaceholder = placeholders[conditionName];

return (
<FieldGroup {...props}>
<Field>
<FieldLabel htmlFor={conditionFieldId}>{t('Condition')}</FieldLabel>
<FieldRow>
<Controller
name={`conditions.${index}.name`}
control={control}
render={({ field }) => (
<Select {...field} id={conditionFieldId} options={conditionOptions} placeholder={t('Select_an_option')} />
)}
/>
</FieldRow>

{conditionValuePlaceholder && (
<FieldRow>
<Controller
name={`conditions.${index}.value`}
control={control}
render={({ field }) => {
if (conditionName === 'time-on-site') {
return <NumberInput {...field} placeholder={conditionValuePlaceholder} />;
}

return <TextInput {...field} placeholder={conditionValuePlaceholder} />;
}}
/>
</FieldRow>
)}
</Field>
</FieldGroup>
);
};
Loading

0 comments on commit 2e592b1

Please sign in to comment.