-
Notifications
You must be signed in to change notification settings - Fork 0
/
slots.ts
47 lines (45 loc) 路 1.51 KB
/
slots.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { randomElement } from './helpers'
import { Slot } from 'wolf-core'
import { StorageLayerType } from '../../src';
// Import info from Wolf abilities
import { UserState } from './abilities'
export const slots = [
{
name: 'alarmName',
query: () => { return 'What is the name of the alarm?' },
retry: (submittedValue, convoStorageLayer, turnCount) => {
const phrase = [`Please try a new name (attempt: ${turnCount})`, `Try harder.. (attempt: ${turnCount})`]
if (turnCount > phrase.length - 1) {
return phrase[phrase.length - 1]
}
return phrase[turnCount]
},
validate: (value) => {
if (value.toLowerCase() === 'hao') {
return { isValid: false, reason: `${value} is not a good alarm name.` }
}
return { isValid: true, reason: null }
},
onFill: (value) => `ok! name is set to ${value}.`
},
{
name: 'alarmTime',
query: () => { return 'What is the time you want to set?' },
retry: (submittedValue, convoStorageLayer, turnCount) => {
const phrases: string[] = ['let\'s try again', 'what is the time you want to set?']
return randomElement(phrases)
},
validate: (value: string) => {
if (!value.toLowerCase().endsWith('pm') && !value.toLowerCase().endsWith('am')) {
return {
isValid: false,
reason: 'Needs to set PM or AM',
}
}
return {
isValid: true
}
},
onFill: (value) => `ok! time is set to ${value}.`
}
] as Slot<StorageLayerType<UserState>>[]