-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.go
101 lines (79 loc) · 2.26 KB
/
bot.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
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
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"os"
"path/filepath"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/lexmodelbuildingservice"
)
func putBot(svc *lexmodelbuildingservice.LexModelBuildingService, file string, name string, poll int, publish *string) {
var myBot lexmodelbuildingservice.PutBotInput
readAndUnmarshal(file, &myBot)
if publish != nil {
//publish each intent
separator := string(os.PathSeparator)
basePath := filepath.Dir(file) + separator + ".." + separator
for _, v := range myBot.Intents {
intentVersion, err := putIntent(svc, basePath+"intents"+separator+*v.IntentName+filepath.Ext(file), true)
checkError(err)
v.IntentVersion = aws.String(intentVersion)
}
}
if name != "" {
myBot.Name = &name
}
getResult, err := svc.GetBot(&lexmodelbuildingservice.GetBotInput{
Name: myBot.Name,
VersionOrAlias: aws.String("$LATEST"),
})
checkError(err)
myBot.Checksum = getResult.Checksum
if publish != nil {
myBot.CreateVersion = aws.Bool(true)
}
putResult, err := svc.PutBot(&myBot)
checkError(err)
//loop and poll the status
if !*dontWait || publish != nil {
currentStatus := *putResult.Status
fmt.Print(currentStatus)
for {
if currentStatus == "READY" {
fmt.Println()
getAliasResult, err := svc.GetBotAlias(&lexmodelbuildingservice.GetBotAliasInput{
Name: publish,
BotName: myBot.Name,
})
checkError(err)
_, err = svc.PutBotAlias(&lexmodelbuildingservice.PutBotAliasInput{
Name: publish,
BotName: myBot.Name,
BotVersion: putResult.Version,
Checksum: getAliasResult.Checksum,
})
checkError(err)
fmt.Printf("Bot %s was published as version %s and alias \"%s\".\n",
*myBot.Name,
*putResult.Version,
*publish)
break
} else if currentStatus == "FAILED" {
fmt.Printf("\n%s\n", *getResult.FailureReason)
break
}
time.Sleep(time.Duration(poll) * time.Second)
getResult, err = svc.GetBot(&lexmodelbuildingservice.GetBotInput{
Name: myBot.Name,
VersionOrAlias: aws.String("$LATEST"),
})
checkError(err)
if currentStatus != *getResult.Status {
currentStatus = *getResult.Status
fmt.Printf("\n" + currentStatus)
} else {
fmt.Print(".")
}
}
}
}