Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
sethkor committed Sep 25, 2020
2 parents b1bfa8c + 9715654 commit 07265b3
Show file tree
Hide file tree
Showing 18 changed files with 404 additions and 376 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ Commands:
Adds or updates an intent
put-bot --name=NAME [<flags>] <file>
Adds or updates a bo
Adds or updates a bot
export [<flags>]
Export existing AWS Lex configs and write to workspace
```
## Getting lexbelt
Easiest way to install if you're on a Mac or Linux (amd64 or arm64) is to use [Homebrew](https://brew.sh/)
Expand All @@ -51,8 +54,7 @@ For other platforms take a look at the releases in Github. I build binaries for

Let me know if you would like a particular os/arch binary regularly built.

Lexbelt wants your lex workspace to look like the following:

Lexbelt expects your workspace to look like this:
```
your-lex-workspace
├──slots
Expand Down
42 changes: 11 additions & 31 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"log"
"os"
"path/filepath"
"time"
Expand All @@ -11,59 +10,40 @@ import (
"github.com/aws/aws-sdk-go/service/lexmodelbuildingservice"
)

type botYaml struct {
LexBot *lexmodelbuildingservice.PutBotInput `locationName:"lexBot" type:"structure"`
}

func publishBot(svc *lexmodelbuildingservice.LexModelBuildingService, name string) string {

getResult, err := svc.CreateBotVersion(&lexmodelbuildingservice.CreateBotVersionInput{
Name: aws.String(name),
})

checkError(err)

return *getResult.Version
}

func putBot(svc *lexmodelbuildingservice.LexModelBuildingService, file string, name string, poll int, publish *string) {

var myBot botYaml
var myBot lexmodelbuildingservice.PutBotInput
readAndUnmarshal(file, &myBot)

if myBot.LexBot == nil {
log.Fatal("Yaml file is not as expected, please check your syntax.")
}

if publish != nil {
//publish each intent
separator := string(os.PathSeparator)
basePath := filepath.Dir(file) + separator + ".." + separator
for _, v := range myBot.LexBot.Intents {
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.LexBot.Name = &name
myBot.Name = &name
}

getResult, err := svc.GetBot(&lexmodelbuildingservice.GetBotInput{
Name: myBot.LexBot.Name,
Name: myBot.Name,
VersionOrAlias: aws.String("$LATEST"),
})

checkError(err)

myBot.LexBot.Checksum = getResult.Checksum
myBot.Checksum = getResult.Checksum

if publish != nil {
myBot.LexBot.CreateVersion = aws.Bool(true)
myBot.CreateVersion = aws.Bool(true)
}

putResult, err := svc.PutBot(myBot.LexBot)
putResult, err := svc.PutBot(&myBot)

checkError(err)

Expand All @@ -78,20 +58,20 @@ func putBot(svc *lexmodelbuildingservice.LexModelBuildingService, file string, n

getAliasResult, err := svc.GetBotAlias(&lexmodelbuildingservice.GetBotAliasInput{
Name: publish,
BotName: myBot.LexBot.Name,
BotName: myBot.Name,
})

checkError(err)
_, err = svc.PutBotAlias(&lexmodelbuildingservice.PutBotAliasInput{
Name: publish,
BotName: myBot.LexBot.Name,
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.LexBot.Name,
*myBot.Name,
*putResult.Version,
*publish)

Expand All @@ -104,7 +84,7 @@ func putBot(svc *lexmodelbuildingservice.LexModelBuildingService, file string, n
time.Sleep(time.Duration(poll) * time.Second)

getResult, err = svc.GetBot(&lexmodelbuildingservice.GetBotInput{
Name: myBot.LexBot.Name,
Name: myBot.Name,
VersionOrAlias: aws.String("$LATEST"),
})

Expand Down
56 changes: 27 additions & 29 deletions examples/json/bots/OrderFlowersBot.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
{
"lexBot" : {
"intents": [
"intents": [
{
"intentVersion": "$LATEST",
"intentName": "OrderFlowers"
}
],
"name": "OrderFlowersBot",
"locale": "en-US",
"abortStatement": {
"messages": [
{
"intentVersion": "$LATEST",
"intentName": "OrderFlowers"
"content": "Sorry, I'm not able to assist at this time",
"contentType": "PlainText"
}
],
"name": "OrderFlowersBot",
"locale": "en-US",
"abortStatement": {
"messages": [
{
"content": "Sorry, I'm not able to assist at this time",
"contentType": "PlainText"
}
]
},
"clarificationPrompt": {
"maxAttempts": 2,
"messages": [
{
"content": "I didn't understand you, what would you like to do?",
"contentType": "PlainText"
}
]
},
"voiceId": "Salli",
"childDirected": false,
"idleSessionTTLInSeconds": 600,
"description": "Bot to order flowers on the behalf of a user"
}
]
},
"clarificationPrompt": {
"maxAttempts": 2,
"messages": [
{
"content": "I didn't understand you, what would you like to do?",
"contentType": "PlainText"
}
]
},
"voiceId": "Salli",
"childDirected": false,
"idleSessionTTLInSeconds": 600,
"description": "Bot to order flowers on the behalf of a user"
}
34 changes: 16 additions & 18 deletions examples/json/intents/AskTime.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
{
"lexIntent" : {
"name": "AskTime",
"description": "Intent to ask what the time is",
"version": "1",
"sampleUtterances": [
"Whats the time",
"What time is it",
"Time please",
"Time"
],
"slots": [],
"fulfillmentActivity": {
"codeHook": {
"uri": "arn:aws:lambda:ap-southeast-2:293499315857:function:LexLambdaSampleFulfilment",
"messageVersion": "1.0"
},
"type": "CodeHook"
}
"name": "AskTime",
"description": "Intent to ask what the time is",
"version": "1",
"sampleUtterances": [
"Whats the time",
"What time is it",
"Time please",
"Time"
],
"slots": [],
"fulfillmentActivity": {
"codeHook": {
"uri": "arn:aws:lambda:ap-southeast-2:293499315857:function:LexLambdaSampleFulfilment",
"messageVersion": "1.0"
},
"type": "CodeHook"
}
}
152 changes: 75 additions & 77 deletions examples/json/intents/OrderFlowers.json
Original file line number Diff line number Diff line change
@@ -1,84 +1,82 @@
{
"lexIntent" : {
"name": "OrderFlowers",
"description": "Intent to order a bouquet of flowers for pick up",
"sampleUtterances": [
"I would like to pick up flowers",
"I would like to order some flowers"
],
"slots": [
{
"slotType": "FlowerTypes",
"name": "FlowerType",
"slotConstraint": "Required",
"valueElicitationPrompt": {
"maxAttempts": 2,
"messages": [
{
"content": "What type of flowers would you like to order?",
"contentType": "PlainText"
}
]
},
"priority": 1,
"slotTypeVersion": "$LATEST",
"sampleUtterances": [
"I would like to order {FlowerType}"
],
"description": "The type of flowers to pick up"
},
{
"slotType": "AMAZON.DATE",
"name": "PickupDate",
"slotConstraint": "Required",
"valueElicitationPrompt": {
"maxAttempts": 2,
"messages": [
{
"content": "What day do you want the {FlowerType} to be picked up?",
"contentType": "PlainText"
}
]
},
"priority": 2,
"description": "The date to pick up the flowers"
"name": "OrderFlowers",
"description": "Intent to order a bouquet of flowers for pick up",
"sampleUtterances": [
"I would like to pick up flowers",
"I would like to order some flowers"
],
"slots": [
{
"slotType": "FlowerTypes",
"name": "FlowerType",
"slotConstraint": "Required",
"valueElicitationPrompt": {
"maxAttempts": 2,
"messages": [
{
"content": "What type of flowers would you like to order?",
"contentType": "PlainText"
}
]
},
{
"slotType": "AMAZON.TIME",
"name": "PickupTime",
"slotConstraint": "Required",
"valueElicitationPrompt": {
"maxAttempts": 2,
"messages": [
{
"content": "Pick up the {FlowerType} at what time on {PickupDate}?",
"contentType": "PlainText"
}
]
},
"priority": 3,
"description": "The time to pick up the flowers"
}
],
"confirmationPrompt": {
"maxAttempts": 2,
"messages": [
{
"content": "Okay, your {FlowerType} will be ready for pickup by {PickupTime} on {PickupDate}. Does this sound okay?",
"contentType": "PlainText"
}
]
"priority": 1,
"slotTypeVersion": "$LATEST",
"sampleUtterances": [
"I would like to order {FlowerType}"
],
"description": "The type of flowers to pick up"
},
"rejectionStatement": {
"messages": [
{
"content": "Okay, I will not place your order.",
"contentType": "PlainText"
}
]
{
"slotType": "AMAZON.DATE",
"name": "PickupDate",
"slotConstraint": "Required",
"valueElicitationPrompt": {
"maxAttempts": 2,
"messages": [
{
"content": "What day do you want the {FlowerType} to be picked up?",
"contentType": "PlainText"
}
]
},
"priority": 2,
"description": "The date to pick up the flowers"
},
"fulfillmentActivity": {
"type": "ReturnIntent"
{
"slotType": "AMAZON.TIME",
"name": "PickupTime",
"slotConstraint": "Required",
"valueElicitationPrompt": {
"maxAttempts": 2,
"messages": [
{
"content": "Pick up the {FlowerType} at what time on {PickupDate}?",
"contentType": "PlainText"
}
]
},
"priority": 3,
"description": "The time to pick up the flowers"
}
],
"confirmationPrompt": {
"maxAttempts": 2,
"messages": [
{
"content": "Okay, your {FlowerType} will be ready for pickup by {PickupTime} on {PickupDate}. Does this sound okay?",
"contentType": "PlainText"
}
]
},
"rejectionStatement": {
"messages": [
{
"content": "Okay, I will not place your order.",
"contentType": "PlainText"
}
]
},
"fulfillmentActivity": {
"type": "ReturnIntent"
}
}
Loading

0 comments on commit 07265b3

Please sign in to comment.