forked from theopenconversationkit/tock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGASelectBuilders.kt
More file actions
91 lines (84 loc) · 2.85 KB
/
Copy pathGASelectBuilders.kt
File metadata and controls
91 lines (84 loc) · 2.85 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright (C) 2017/2025 SNCF Connect & Tech
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ai.tock.bot.connector.ga
import ai.tock.bot.connector.ga.model.GAIntent
import ai.tock.bot.connector.ga.model.response.GAExpectedIntent
import ai.tock.bot.connector.ga.model.response.GASelectItem
import ai.tock.bot.connector.ga.model.response.GASimpleSelect
import ai.tock.bot.definition.IntentAware
import ai.tock.bot.definition.Parameters
import ai.tock.bot.definition.StoryStep
import ai.tock.bot.definition.StoryStepDef
import ai.tock.bot.engine.Bus
import ai.tock.bot.engine.I18nTranslator
/**
* Provides a [GAExpectedIntent] with a [GASimpleSelect].
*/
fun I18nTranslator.expectedIntentForSimpleSelect(items: List<GASelectItem>): GAExpectedIntent {
return GAExpectedIntent(
GAIntent.option,
optionValueSpec(
simpleSelect = GASimpleSelect(items)
)
)
}
/**
* Provides a [GASelectItem] with [String] parameters.
*/
fun <T : Bus<T>> T.selectItem(
title: CharSequence,
targetIntent: IntentAware,
vararg parameters: Pair<String, String>
): GASelectItem = selectItem<T>(title, targetIntent, null, null, *parameters)
/**
* Provides a [GASelectItem] with option title and [String] parameters.
*/
fun <T : Bus<T>> T.selectItem(
title: CharSequence,
targetIntent: IntentAware,
optionTitle: CharSequence? = null,
vararg parameters: Pair<String, String>
): GASelectItem = selectItem(title, targetIntent, null, optionTitle, *parameters)
/**
* Provides a [GASelectItem] with option title, [StoryStep] and [Parameters] parameters.
*/
fun <T : Bus<T>> T.selectItem(
title: CharSequence,
targetIntent: IntentAware,
step: StoryStepDef,
optionTitle: CharSequence? = null,
parameters: Parameters
): GASelectItem = selectItem(title, targetIntent, step, optionTitle, *parameters.toArray())
/**
* Provides a [GASelectItem] with option title, [StoryStep] and [String] parameters.
*/
fun <T : Bus<T>> T.selectItem(
title: CharSequence,
targetIntent: IntentAware,
step: StoryStepDef? = null,
optionTitle: CharSequence? = null,
vararg parameters: Pair<String, String>
): GASelectItem {
return GASelectItem(
optionInfo(
title,
targetIntent,
step,
*parameters
),
optionTitle?.let { translate(it).toString() }
)
}