2
0
Files
bot/packages/schemas/features/blocks/logic/setVariable.ts
Baptiste Arnaud 1ca742fc0b (setVariable) Add "Environment name" value in Set variable block (#850)
Closes #848
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
### Summary by CodeRabbit

- New Feature: Added "Environment name" as a new value type in the
SetVariable function, allowing users to distinguish between 'web' and
'whatsapp' environments.
- Refactor: Simplified session state handling in `resumeWhatsAppFlow.ts`
for improved code clarity.
- Refactor: Updated `startWhatsAppSession.ts` to include an initial
session state with WhatsApp contact and expiry timeout, enhancing
session management.
- Bug Fix: Improved null handling in `executeSetVariable.ts` for
'Contact name' and 'Phone number', preventing potential issues with
falsy values.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2023-09-26 09:50:20 +02:00

49 lines
1.2 KiB
TypeScript

import { z } from 'zod'
import { blockBaseSchema } from '../baseSchemas'
import { LogicBlockType } from './enums'
export const valueTypes = [
'Custom',
'Empty',
'Environment name',
'User ID',
'Now',
'Today',
'Yesterday',
'Tomorrow',
'Random ID',
'Moment of the day',
'Map item with same index',
'Phone number',
'Contact name',
] as const
export const hiddenTypes = ['Today']
export const setVariableOptionsSchema = z.object({
variableId: z.string().optional(),
expressionToEvaluate: z.string().optional(),
isCode: z.boolean().optional(),
type: z.enum(valueTypes).optional(),
mapListItemParams: z
.object({
baseItemVariableId: z.string().optional(),
baseListVariableId: z.string().optional(),
targetListVariableId: z.string().optional(),
})
.optional(),
isExecutedOnClient: z.boolean().optional(),
})
export const setVariableBlockSchema = blockBaseSchema.merge(
z.object({
type: z.enum([LogicBlockType.SET_VARIABLE]),
options: setVariableOptionsSchema,
})
)
export const defaultSetVariablesOptions: SetVariableOptions = {}
export type SetVariableBlock = z.infer<typeof setVariableBlockSchema>
export type SetVariableOptions = z.infer<typeof setVariableOptionsSchema>