-
Notifications
You must be signed in to change notification settings - Fork 10
/
intent.go
64 lines (54 loc) · 1.13 KB
/
intent.go
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
package model
import (
"github.com/dueros/bot-sdk-go/bot/data"
)
type Intent struct {
data data.Intent
Name string
ConfirmationStatus string
}
func NewIntent(intent data.Intent) *Intent {
return &Intent{
data: intent,
Name: intent.Name,
ConfirmationStatus: intent.ConfirmationStatus,
}
}
// 根据槽位名获取槽位
func (this *Intent) GetSlot(name string) *data.Slot {
slot, ok := this.data.Slots[name]
if ok {
return &slot
}
return nil
}
// 根据槽位名获取槽位对应的值
func (this *Intent) GetSlotValue(name string) string {
slot := this.GetSlot(name)
if slot != nil {
return slot.Value
}
return ""
}
// 根据槽位名获取槽位对应的状态
func (this *Intent) GetSlotStatus(name string) string {
slot := this.GetSlot(name)
if slot != nil {
return slot.ConfirmationStatus
}
return ""
}
// 设置槽位的值
func (this *Intent) SetSlotValue(name string, value string) bool {
slot := this.GetSlot(name)
if slot != nil {
slot.Value = value
return true
} else {
// TODO new a slot
}
return false
}
func (this *Intent) GetData() data.Intent {
return this.data
}