mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: minor adjustments
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}, {});
|
||||
|
||||
Reference in New Issue
Block a user