⚡ (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 -->
This commit is contained in:
@@ -77,9 +77,11 @@ const getExpressionToEvaluate =
|
||||
(options: SetVariableBlock['options']): string | null => {
|
||||
switch (options.type) {
|
||||
case 'Contact name':
|
||||
return state.whatsApp?.contact.name ?? ''
|
||||
case 'Phone number':
|
||||
return `"${state.whatsApp?.contact.phoneNumber}"` ?? ''
|
||||
return state.whatsApp?.contact.name ?? null
|
||||
case 'Phone number': {
|
||||
const phoneNumber = state.whatsApp?.contact.phoneNumber
|
||||
return phoneNumber ? `"${state.whatsApp?.contact.phoneNumber}"` : null
|
||||
}
|
||||
case 'Now':
|
||||
case 'Today':
|
||||
return 'new Date().toISOString()'
|
||||
@@ -112,6 +114,9 @@ const getExpressionToEvaluate =
|
||||
if(now.getHours() >= 18) return 'evening'
|
||||
if(now.getHours() >= 22 || now.getHours() < 6) return 'night'`
|
||||
}
|
||||
case 'Environment name': {
|
||||
return state.whatsApp ? 'whatsapp' : 'web'
|
||||
}
|
||||
case 'Custom':
|
||||
case undefined: {
|
||||
return options.expressionToEvaluate ?? null
|
||||
|
||||
Reference in New Issue
Block a user