-
Notifications
You must be signed in to change notification settings - Fork 39
/
BotRequest.kt
88 lines (77 loc) · 2.29 KB
/
BotRequest.kt
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
package com.justai.jaicf.api
/**
* A base interface for every request to the JAICF bot.
*
* @property type the type of request from [BotRequestType]
* @property clientId a user's identifier that is unique for the channel from where the request was received
* @property input an input string that should be processed as a user's request (may contain text query, event or recognised intent)
*
* @see BotRequestType
*/
interface BotRequest {
val type: BotRequestType
val clientId: String
val input: String
}
/**
* The type of request.
*/
enum class BotRequestType {
QUERY, EVENT, INTENT
}
abstract class MutableBotRequest(input: String) : BotRequest {
private var inputValue = input
override val input: String
get() = inputValue
internal fun setInput(input: String) {
inputValue = input
}
}
/**
* The request that contains a raw text query.
* Every activator that handles query requests should use this class or create an own subclass.
*/
open class QueryBotRequest(
override val clientId: String,
input: String
) : MutableBotRequest(input) {
override val type = BotRequestType.QUERY
}
/**
* The request that contains an event.
* Every activator that handles event requests should use this class or create an own subclass.
*/
open class EventBotRequest(
override val clientId: String,
input: String
) : MutableBotRequest(input) {
override val type = BotRequestType.EVENT
}
/**
* The request that contains a recognised intent.
* Every activator that handles intent requests should use this class or create an own subclass.
*/
open class IntentBotRequest(
override val clientId: String,
input: String
) : MutableBotRequest(input) {
override val type = BotRequestType.INTENT
}
/**
* Indicates if request has a raw text query.
* @return true if request has a raw text query
*/
fun BotRequest.hasQuery() =
this.type == BotRequestType.QUERY && input.isNotBlank()
/**
* Indicates if request has an event.
* @return true if request has an event
*/
fun BotRequest.hasEvent() =
this.type == BotRequestType.EVENT && input.isNotBlank()
/**
* Indicates if request has a recognised intent.
* @return true if request has a recognised intent
*/
fun BotRequest.hasIntent() =
this.type == BotRequestType.INTENT && input.isNotBlank()