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;
}, {});