fix: minor adjustments

This commit is contained in:
Mohamed Marrouchi 2024-09-29 09:33:41 +01:00
parent 4248df0f67
commit 2ef011ed8e
7 changed files with 43 additions and 17 deletions

View File

@ -8,7 +8,7 @@
*/
import { ApiProperty, PartialType } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';
import { IsBoolean, IsNotEmpty, IsOptional, IsString } from 'class-validator';
export class ContextVarCreateDto {
@ApiProperty({ description: 'Context var label', type: String })
@ -22,6 +22,8 @@ export class ContextVarCreateDto {
name: string;
@ApiProperty({ description: 'Is context var permanent', type: Boolean })
@IsOptional()
@IsBoolean()
permanent?: boolean;
}

View File

@ -70,11 +70,12 @@ export class BotService {
event.getSenderForeignId(),
);
// Process message : Replace tokens with context data and then send the message
const recipient = event.getSender();
const envelope: StdOutgoingEnvelope =
await this.blockService.processMessage(
block,
context,
event.getSender().context,
recipient.context,
fallback,
conservationId,
);
@ -88,7 +89,6 @@ export class BotService {
this.eventEmitter.emit('hook:stats:entry', 'all_messages', 'All Messages');
// Trigger sent message event
const recipient = event.getSender();
const sentMessage: MessageCreateDto = {
mid: response && 'mid' in response ? response.mid : '',
message: envelope.message,

View File

@ -21,14 +21,19 @@ export class ContextVarService extends BaseService<ContextVar> {
super(repository);
}
/**
* Retrieves a mapping of context variable names to their corresponding `ContextVar` objects for a given block.
*
* @param {Block | BlockFull} block - The block containing the capture variables to retrieve context variables for.
* @returns {Promise<Record<string, ContextVar>>} A promise that resolves to a record mapping context variable names to `ContextVar` objects.
*/
async getContextVarsByBlock(
block: Block | BlockFull,
): Promise<Record<string, ContextVar>> {
return (
await this.find({
name: { $in: block.capture_vars.map((cv) => cv.context_var) },
})
).reduce((acc, cv) => {
const vars = await this.find({
name: { $in: block.capture_vars.map(({ context_var }) => context_var) },
});
return vars.reduce((acc, cv) => {
acc[cv.name] = cv;
return acc;
}, {});

View File

@ -7,9 +7,16 @@
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import { Dialog, DialogActions, DialogContent } from "@mui/material";
import {
Dialog,
DialogActions,
DialogContent,
FormControlLabel,
FormHelperText,
Switch,
} from "@mui/material";
import { FC, useEffect } from "react";
import { useForm } from "react-hook-form";
import { Controller, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import DialogButtons from "@/app-components/buttons/DialogButtons";
@ -58,6 +65,7 @@ export const ContextVarDialog: FC<ContextVarDialogProps> = ({
setValue,
handleSubmit,
formState: { errors },
control,
} = useForm<IContextVarAttributes>({
defaultValues: { name: data?.name || "", label: data?.label || "" },
});
@ -129,6 +137,19 @@ export const ContextVarDialog: FC<ContextVarDialogProps> = ({
InputLabelProps={{ shrink: true }}
/>
</ContentItem>
<ContentItem>
<Controller
name="permanent"
control={control}
render={({ field }) => (
<FormControlLabel
control={<Switch {...field} checked={field.value} />}
label={t("label.permanent")}
/>
)}
/>
<FormHelperText>{t("help.permanent")}</FormHelperText>
</ContentItem>
</ContentContainer>
</DialogContent>
<DialogActions>

View File

@ -699,7 +699,8 @@
"supported_message_type_others": "Only generic template messages are supported.",
"notification_type_regular": "Sound/Vibration",
"notification_type_silent_push": "On-screen notification only",
"notification_type_no_push": "No notification"
"notification_type_no_push": "No notification",
"permanent": "When enabled, the variable value will be stored in the subscriber's profile and retained for future conversations."
},
"charts": {
"messages": "Messages",

View File

@ -697,7 +697,8 @@
"supported_message_type_others": "Seuls les messages de modèle générique sont pris en charge.",
"notification_type_regular": "Son/Vibration",
"notification_type_silent_push": "Notification à l'écran uniquement",
"notification_type_no_push": "Aucune notification"
"notification_type_no_push": "Aucune notification",
"permanent": "Lorsqu'elle est activée, cette variable sera stockée dans le profil de l'abonné(e) et conservée pour les futures conversations."
},
"charts": {
"messages": "Messages",

View File

@ -19,11 +19,7 @@ export interface IContextVarAttributes {
export interface IContextVarStub
extends IBaseSchema,
OmitPopulate<IContextVarAttributes, EntityType.CONTEXT_VAR> {
name: string;
label: string;
permanent: boolean;
}
OmitPopulate<IContextVarAttributes, EntityType.CONTEXT_VAR> {}
export interface IContextVar extends IContextVarStub, IFormat<Format.BASIC> {}