feat: workflow auto translation (#27087)
* feat: workflow auto translation * tests: add unit tests * refactor: tests and workflow * fix: type err * fix: type err * fix: remove redundant index on WorkflowStepTranslation The @@index on [workflowStepId, field, targetLocale] duplicates the @@unique constraint on the same columns. A unique index already provides efficient lookups, so the separate @@index adds storage overhead and write latency without benefit. Addresses Cubic AI review feedback (confidence 9/10). Co-Authored-By: unknown <> * fix: correct locale mapping when translation API returns null Map translations with their corresponding locales before filtering to preserve correct locale-to-translation associations. Previously, filtering out null translations would reindex the array, causing incorrect locale mappings when any translation in the batch failed. Also fixes pre-existing lint warnings: - Move exports to end of file - Add explicit return type to processTranslations - Replace ternary with if-else for upsertMany selection Co-Authored-By: [email protected] <[email protected]> * fix: address review feedback for workflow auto-translation - Add change detection before creating translation tasks - Rename userLocale to sourceLocale in task props for clarity - Show source language in UI with new translation key - Extract SUPPORTED_LOCALES to shared translationConstants.ts - Fix locale mapping bug in translateEventTypeData.ts - Add WhatsApp translation support - Abstract translation lookup into shared translationLookup.ts helper - Restore if-else readability for SCANNING_WORKFLOW_STEPS Co-authored-by: Udit Takkar <[email protected]> Co-Authored-By: unknown <> * fix: update test to use sourceLocale instead of userLocale Co-Authored-By: unknown <> * refactor: feedback * fix: handle first time * fix: tests * fix: tests * fix: address Cubic AI review feedback (confidence 9/10 issues) - WhatsApp translation: Apply variable substitution using getSMSMessageWithVariables and clear contentSid when using translated body to ensure Twilio uses the translated text instead of the original template - update.handler.ts: Change sourceLocale assignment from ?? to || for consistency with tasker payload behavior (line 481) - ITranslationService.ts: Rename methods from plural to singular naming: - getWorkflowStepTranslations -> getWorkflowStepTranslation - getEventTypeTranslations -> getEventTypeTranslation Updated all call sites and tests accordingly Co-Authored-By: unknown <> * fix: address Cubic AI review feedback (confidence 9/10+ issues) - Fix getSMSMessageWithVariables to handle WHATSAPP_ATTENDEE action for locale and timezone (confidence 9/10) - Remove WhatsApp translation feature that set contentSid to undefined since Twilio ignores body parameter for WhatsApp and requires pre-approved Message Templates (confidence 10/10) Co-Authored-By: unknown <> * fix: translatio * Add tests: packages/features/eventTypeTranslation/repositories/EventTypeTranslationRepository.test.ts Generated by Paragon from proposal for PR #27087 * Add tests: packages/features/tasker/tasks/translateWorkflowStepData.test.ts Generated by Paragon from proposal for PR #27087 * chore: nit * chore: verfied atg * fix: set sourceLocale for new steps, add shouldDirty to checkbox, remove spec docs - Set sourceLocale fallback in addedSteps mapping to fix stale detection mismatch - Add { shouldDirty: true } to autoTranslateEnabled checkbox onChange - Remove specs/workflow-translation/ directory (planning docs, not for repo) Co-authored-by: Udit Takkar <[email protected]> Co-Authored-By: unknown <> * chore: add specs back * fix: type error * fix: type error * fix: type err * fix: tests * refactor: feedback * fix: type err * refactor --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
53 files changed
+2241
-149
No files matched your search
@@ -178,6 +178,8 @@ export default function WorkflowDetailsPage(props: Props) {
|
||||
verifiedAt: SCANNING_WORKFLOW_STEPS ? null : new Date(),
|
||||
agentId: null,
|
||||
inboundAgentId: null,
|
||||
autoTranslateEnabled: false,
|
||||
sourceLocale: null,
|
||||
};
|
||||
steps?.push(step);
|
||||
form.setValue("steps", steps);
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
import { type TFunction } from "i18next";
|
||||
import type { TFunction } from "i18next";
|
||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
import { useEffect, useRef, useState, useCallback } from "react";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import type { UseFormReturn } from "react-hook-form";
|
||||
import { Controller, useWatch } from "react-hook-form";
|
||||
import "react-phone-number-input/style.css";
|
||||
|
||||
import type { RetellAgentWithDetails } from "@calcom/features/calAIPhone/providers/retellAI";
|
||||
import { Dialog } from "@calcom/features/components/controlled-dialog";
|
||||
import PhoneInput from "@calcom/web/components/phone-input";
|
||||
import {
|
||||
isSMSAction,
|
||||
isWhatsappAction,
|
||||
getTemplateBodyForAction,
|
||||
shouldScheduleEmailReminder,
|
||||
isSMSOrWhatsappAction,
|
||||
hasCalAIAction,
|
||||
isCalAIAction,
|
||||
isFormTrigger,
|
||||
hasCalAIAction,
|
||||
isSMSAction,
|
||||
isSMSOrWhatsappAction,
|
||||
isWhatsappAction,
|
||||
shouldScheduleEmailReminder,
|
||||
} from "@calcom/features/ee/workflows/lib/actionHelperFunctions";
|
||||
import { DYNAMIC_TEXT_VARIABLES } from "@calcom/features/ee/workflows/lib/constants";
|
||||
import {
|
||||
@@ -27,6 +26,7 @@ import {
|
||||
import emailRatingTemplate from "@calcom/features/ee/workflows/lib/reminders/templates/emailRatingTemplate";
|
||||
import emailReminderTemplate from "@calcom/features/ee/workflows/lib/reminders/templates/emailReminderTemplate";
|
||||
import type { FormValues } from "@calcom/features/ee/workflows/lib/types";
|
||||
import PhoneInput from "@calcom/web/components/phone-input";
|
||||
import "@calcom/features/ee/workflows/style/styles.css";
|
||||
import { SENDER_ID, SENDER_NAME } from "@calcom/lib/constants";
|
||||
import { formatPhoneNumber } from "@calcom/lib/formatPhoneNumber";
|
||||
@@ -48,7 +48,7 @@ import { trpc } from "@calcom/trpc/react";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { Badge, InfoBadge } from "@calcom/ui/components/badge";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { DialogContent, DialogFooter, DialogClose } from "@calcom/ui/components/dialog";
|
||||
import { DialogClose, DialogContent, DialogFooter } from "@calcom/ui/components/dialog";
|
||||
import {
|
||||
Dropdown,
|
||||
DropdownItem,
|
||||
@@ -56,26 +56,26 @@ import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@calcom/ui/components/dropdown";
|
||||
import { AddVariablesDropdown } from "@calcom/ui/components/editor";
|
||||
import { Editor } from "@calcom/ui/components/editor";
|
||||
import { CheckboxField } from "@calcom/ui/components/form";
|
||||
import { EmailField } from "@calcom/ui/components/form";
|
||||
import { TextArea } from "@calcom/ui/components/form";
|
||||
import { Input } from "@calcom/ui/components/form";
|
||||
import { Label } from "@calcom/ui/components/form";
|
||||
import { TextField } from "@calcom/ui/components/form";
|
||||
import { Select } from "@calcom/ui/components/form";
|
||||
import { MultiSelectCheckbox } from "@calcom/ui/components/form";
|
||||
import { AddVariablesDropdown, Editor } from "@calcom/ui/components/editor";
|
||||
import type { MultiSelectCheckboxesOptionType as Option } from "@calcom/ui/components/form";
|
||||
import {
|
||||
CheckboxField,
|
||||
EmailField,
|
||||
Input,
|
||||
Label,
|
||||
MultiSelectCheckbox,
|
||||
Select,
|
||||
TextArea,
|
||||
TextField,
|
||||
} from "@calcom/ui/components/form";
|
||||
import { CircleHelpIcon, InfoIcon, PhoneIcon } from "@coss/ui/icons";
|
||||
import { SkeletonText } from "@calcom/ui/components/skeleton";
|
||||
import { showToast } from "@calcom/ui/components/toast";
|
||||
import { useHasPaidPlan, useHasActiveTeamPlan } from "@calcom/web/modules/billing/hooks/useHasPaidPlan";
|
||||
|
||||
import { useHasActiveTeamPlan, useHasPaidPlan } from "@calcom/web/modules/billing/hooks/useHasPaidPlan";
|
||||
import { AgentConfigurationSheet }from "./agent-configuration/AgentConfigurationSheet";
|
||||
import { TestPhoneCallDialog } from "./TestPhoneCallDialog";
|
||||
import { TimeTimeUnitInput } from "./TimeTimeUnitInput";
|
||||
import { WebCallDialog } from "./WebCallDialog";
|
||||
import { AgentConfigurationSheet } from "./agent-configuration/AgentConfigurationSheet";
|
||||
|
||||
type User = RouterOutputs["viewer"]["me"]["get"];
|
||||
|
||||
@@ -477,7 +477,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
const verifyEmailCodeMutation = trpc.viewer.workflows.verifyEmailCode.useMutation({
|
||||
onSuccess: (isVerified) => {
|
||||
showToast(isVerified ? t("verified_successfully") : t("wrong_code"), "success");
|
||||
setEmailVerified(true);
|
||||
setEmailVerified(isVerified);
|
||||
if (
|
||||
step &&
|
||||
form?.formState?.errors?.steps &&
|
||||
@@ -800,6 +800,15 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
form.setValue(`steps.${step.stepNumber - 1}.agentId`, null);
|
||||
}
|
||||
|
||||
if (
|
||||
val.value !== WorkflowActions.EMAIL_ATTENDEE &&
|
||||
val.value !== WorkflowActions.SMS_ATTENDEE
|
||||
) {
|
||||
form.setValue(`steps.${step.stepNumber - 1}.autoTranslateEnabled`, false, {
|
||||
shouldDirty: true,
|
||||
});
|
||||
}
|
||||
|
||||
form.setValue(`steps.${step.stepNumber - 1}.sendTo`, null);
|
||||
form.clearErrors(`steps.${step.stepNumber - 1}.sendTo`);
|
||||
form.setValue(`steps.${step.stepNumber - 1}.action`, val.value, {
|
||||
@@ -1433,6 +1442,49 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{(step.action === WorkflowActions.EMAIL_ATTENDEE ||
|
||||
step.action === WorkflowActions.SMS_ATTENDEE) && (
|
||||
<div className="mt-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Controller
|
||||
name={`steps.${step.stepNumber - 1}.autoTranslateEnabled`}
|
||||
control={form.control}
|
||||
render={() => (
|
||||
<CheckboxField
|
||||
disabled={props.readOnly || !props.user.organizationId}
|
||||
defaultChecked={
|
||||
form.getValues(`steps.${step.stepNumber - 1}.autoTranslateEnabled`) || false
|
||||
}
|
||||
description={t("auto_translate_for_attendees")}
|
||||
descriptionClassName="ml-0"
|
||||
onChange={(e) =>
|
||||
form.setValue(
|
||||
`steps.${step.stepNumber - 1}.autoTranslateEnabled`,
|
||||
e.target.checked,
|
||||
{ shouldDirty: true }
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
{!props.user.organizationId && (
|
||||
<Badge variant="gray" size="sm">
|
||||
{t("upgrade_to_organizations")}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
{props.user.organizationId &&
|
||||
form.watch(`steps.${step.stepNumber - 1}.autoTranslateEnabled`) && (
|
||||
<p className="text-subtle ml-6 mt-1 text-xs">
|
||||
{t("auto_translate_source_language_hint", {
|
||||
language: new Intl.DisplayNames([i18n.language], { type: "language" }).of(
|
||||
props.user.locale || "en"
|
||||
),
|
||||
})}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{!props.readOnly && (
|
||||
<div className="ml-1 mt-2">
|
||||
<button type="button" onClick={() => setIsAdditionalInputsDialogOpen(true)}>
|
||||
|
||||
Reference in new issue
Block a user