Fix build errors
This commit is contained in:
parent
785d0965e3
commit
d0f1c1337c
28 changed files with 268 additions and 112 deletions
|
|
@ -16,7 +16,7 @@ import TwilioLanguages from "./twilio-languages";
|
|||
|
||||
type TTSProvider = (voice: any, language: any, prompt: any) => Promise<void>;
|
||||
|
||||
const tts = async (providerId): Promise<TTSProvider> => {
|
||||
const tts = async (providerId: any): Promise<TTSProvider> => {
|
||||
const r = await fetch(
|
||||
`/api/v1/voice/twilio/text-to-speech-token/${providerId}`
|
||||
);
|
||||
|
|
@ -39,7 +39,7 @@ const tts = async (providerId): Promise<TTSProvider> => {
|
|||
outgoing: silence,
|
||||
},
|
||||
});
|
||||
device.on("ready", function (device) {
|
||||
device.on("ready", function (device: any) {
|
||||
device.connect({ language, voice, prompt });
|
||||
});
|
||||
device.on("disconnect", () => resolve());
|
||||
|
|
@ -47,7 +47,7 @@ const tts = async (providerId): Promise<TTSProvider> => {
|
|||
});
|
||||
};
|
||||
|
||||
export const TextToSpeechButton = ({ form }) => {
|
||||
export const TextToSpeechButton = ({ form }: any) => {
|
||||
const { providerId, language, voice, promptText: prompt } = form.formData;
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [ttsProvider, setTTSProvider] = useState<
|
||||
|
|
@ -90,7 +90,7 @@ export const TextToSpeechButton = ({ form }) => {
|
|||
);
|
||||
};
|
||||
|
||||
export const PromptInput = (form, ...rest) => {
|
||||
export const PromptInput = (form: any, ...rest: any[]) => {
|
||||
return (
|
||||
<TextInput
|
||||
source="promptText"
|
||||
|
|
@ -102,19 +102,23 @@ export const PromptInput = (form, ...rest) => {
|
|||
);
|
||||
};
|
||||
|
||||
const validateVoice = (args, values) => {
|
||||
const validateVoice = (args: any, values: any) => {
|
||||
if (!values.language) return "validation.language";
|
||||
if (!values.voice) return "validation.voice";
|
||||
|
||||
// @ts-expect-error
|
||||
const availableVoices = TwilioLanguages.voices[values.language];
|
||||
const found =
|
||||
availableVoices.filter((v) => v.id === values.voice).length === 1;
|
||||
availableVoices.filter((v: any) => v.id === values.voice).length === 1;
|
||||
if (!found) return "validation.voice";
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const VoiceInput = (form, ...rest) => {
|
||||
export const VoiceInput = (form: any, ...rest: any[]) => {
|
||||
// @ts-expect-error
|
||||
const voice = TwilioLanguages.voices[form.formData.language] || [];
|
||||
return (
|
||||
// @ts-expect-error
|
||||
<SelectInput
|
||||
source="voice"
|
||||
choices={voice}
|
||||
|
|
@ -125,9 +129,9 @@ export const VoiceInput = (form, ...rest) => {
|
|||
};
|
||||
|
||||
let noAvailableNumbers = false;
|
||||
let availableNumbers = [];
|
||||
let availableNumbers: any[] = [];
|
||||
|
||||
const getAvailableNumbers = async (providerId) => {
|
||||
const getAvailableNumbers = async (providerId: string) => {
|
||||
try {
|
||||
const r = await fetch(`/api/v1/voice/providers/${providerId}/freeNumbers`);
|
||||
availableNumbers = await r.json();
|
||||
|
|
@ -141,24 +145,32 @@ const getAvailableNumbers = async (providerId) => {
|
|||
}
|
||||
};
|
||||
|
||||
const sidToNumber = (sid) => {
|
||||
const sidToNumber = (sid: any) => {
|
||||
return availableNumbers
|
||||
.filter(({ id }) => id === sid)
|
||||
.map(({ name }) => name)[0];
|
||||
};
|
||||
|
||||
export const populateNumber = (data) => {
|
||||
export const populateNumber = (data: any) => {
|
||||
return {
|
||||
...data,
|
||||
number: sidToNumber(data.providerLineSid),
|
||||
};
|
||||
};
|
||||
|
||||
const hasNumbers = (args, value, values, translate, ...props) => {
|
||||
const hasNumbers = (
|
||||
args: any,
|
||||
value: any,
|
||||
values: any,
|
||||
translate: any,
|
||||
...props: any[]
|
||||
) => {
|
||||
if (noAvailableNumbers) return "validation.noAvailableNumbers";
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const AvailableNumbersInput = (form, ...rest) => {
|
||||
export const AvailableNumbersInput = (form: any, ...rest: any[]) => {
|
||||
const {
|
||||
// @ts-expect-error: non-existent property
|
||||
meta: { touched, error } = {},
|
||||
|
|
@ -181,7 +193,8 @@ export const AvailableNumbersInput = (form, ...rest) => {
|
|||
? translate("validation.noAvailableNumbers")
|
||||
: "",
|
||||
});
|
||||
if (noAvailableNumbers) notify("validation.noAvailableNumbers", "error");
|
||||
if (noAvailableNumbers)
|
||||
notify("validation.noAvailableNumbers", { type: "error" });
|
||||
setLoading(false);
|
||||
}
|
||||
}, [form && form.formData ? form.formData.providerId : undefined]);
|
||||
|
|
@ -278,19 +291,21 @@ export const AsyncSelectInput = (choiceLoader: () => Promise<any[]>, label, sour
|
|||
export const VoiceLineSelectInput = AsyncSelectInput(getVoiceLineChoices, "Voice Line", "backendId", "validation.noVoiceLines" )
|
||||
*/
|
||||
|
||||
export const VoiceLineSelectInput = (source: string) => () => (
|
||||
<ReferenceInput
|
||||
label="Voice Line"
|
||||
source={source}
|
||||
reference="voiceLines"
|
||||
validate={[required()]}
|
||||
>
|
||||
<SelectInput optionText="number" />
|
||||
</ReferenceInput>
|
||||
);
|
||||
export const VoiceLineSelectInput = (source: string) => () =>
|
||||
(
|
||||
<ReferenceInput
|
||||
label="Voice Line"
|
||||
source={source}
|
||||
reference="voiceLines"
|
||||
validate={[required()]}
|
||||
>
|
||||
<SelectInput optionText="number" />
|
||||
</ReferenceInput>
|
||||
);
|
||||
|
||||
export const VoiceLineField = (source: string) => () => (
|
||||
<ReferenceField label="Voice Line" source={source} reference="voiceLines">
|
||||
<TextField source="number" />
|
||||
</ReferenceField>
|
||||
);
|
||||
export const VoiceLineField = (source: string) => () =>
|
||||
(
|
||||
<ReferenceField label="Voice Line" source={source} reference="voiceLines">
|
||||
<TextField source="number" />
|
||||
</ReferenceField>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue