github.com/aavshr/aws-sdk-go@v1.41.3/service/lexmodelbuildingservice/examples_test.go (about) 1 // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 3 package lexmodelbuildingservice_test 4 5 import ( 6 "fmt" 7 "strings" 8 "time" 9 10 "github.com/aavshr/aws-sdk-go/aws" 11 "github.com/aavshr/aws-sdk-go/aws/awserr" 12 "github.com/aavshr/aws-sdk-go/aws/session" 13 "github.com/aavshr/aws-sdk-go/service/lexmodelbuildingservice" 14 ) 15 16 var _ time.Duration 17 var _ strings.Reader 18 var _ aws.Config 19 20 func parseTime(layout, value string) *time.Time { 21 t, err := time.Parse(layout, value) 22 if err != nil { 23 panic(err) 24 } 25 return &t 26 } 27 28 // To get information about a bot 29 // 30 // This example shows how to get configuration information for a bot. 31 func ExampleLexModelBuildingService_GetBot_shared00() { 32 svc := lexmodelbuildingservice.New(session.New()) 33 input := &lexmodelbuildingservice.GetBotInput{ 34 Name: aws.String("DocOrderPizza"), 35 VersionOrAlias: aws.String("$LATEST"), 36 } 37 38 result, err := svc.GetBot(input) 39 if err != nil { 40 if aerr, ok := err.(awserr.Error); ok { 41 switch aerr.Code() { 42 case lexmodelbuildingservice.ErrCodeNotFoundException: 43 fmt.Println(lexmodelbuildingservice.ErrCodeNotFoundException, aerr.Error()) 44 case lexmodelbuildingservice.ErrCodeLimitExceededException: 45 fmt.Println(lexmodelbuildingservice.ErrCodeLimitExceededException, aerr.Error()) 46 case lexmodelbuildingservice.ErrCodeInternalFailureException: 47 fmt.Println(lexmodelbuildingservice.ErrCodeInternalFailureException, aerr.Error()) 48 case lexmodelbuildingservice.ErrCodeBadRequestException: 49 fmt.Println(lexmodelbuildingservice.ErrCodeBadRequestException, aerr.Error()) 50 default: 51 fmt.Println(aerr.Error()) 52 } 53 } else { 54 // Print the error, cast err to awserr.Error to get the Code and 55 // Message from an error. 56 fmt.Println(err.Error()) 57 } 58 return 59 } 60 61 fmt.Println(result) 62 } 63 64 // To get a list of bots 65 // 66 // This example shows how to get a list of all of the bots in your account. 67 func ExampleLexModelBuildingService_GetBots_shared00() { 68 svc := lexmodelbuildingservice.New(session.New()) 69 input := &lexmodelbuildingservice.GetBotsInput{ 70 MaxResults: aws.Int64(5), 71 NextToken: aws.String(""), 72 } 73 74 result, err := svc.GetBots(input) 75 if err != nil { 76 if aerr, ok := err.(awserr.Error); ok { 77 switch aerr.Code() { 78 case lexmodelbuildingservice.ErrCodeNotFoundException: 79 fmt.Println(lexmodelbuildingservice.ErrCodeNotFoundException, aerr.Error()) 80 case lexmodelbuildingservice.ErrCodeLimitExceededException: 81 fmt.Println(lexmodelbuildingservice.ErrCodeLimitExceededException, aerr.Error()) 82 case lexmodelbuildingservice.ErrCodeInternalFailureException: 83 fmt.Println(lexmodelbuildingservice.ErrCodeInternalFailureException, aerr.Error()) 84 case lexmodelbuildingservice.ErrCodeBadRequestException: 85 fmt.Println(lexmodelbuildingservice.ErrCodeBadRequestException, aerr.Error()) 86 default: 87 fmt.Println(aerr.Error()) 88 } 89 } else { 90 // Print the error, cast err to awserr.Error to get the Code and 91 // Message from an error. 92 fmt.Println(err.Error()) 93 } 94 return 95 } 96 97 fmt.Println(result) 98 } 99 100 // To get a information about an intent 101 // 102 // This example shows how to get information about an intent. 103 func ExampleLexModelBuildingService_GetIntent_shared00() { 104 svc := lexmodelbuildingservice.New(session.New()) 105 input := &lexmodelbuildingservice.GetIntentInput{ 106 Name: aws.String("DocOrderPizza"), 107 Version: aws.String("$LATEST"), 108 } 109 110 result, err := svc.GetIntent(input) 111 if err != nil { 112 if aerr, ok := err.(awserr.Error); ok { 113 switch aerr.Code() { 114 case lexmodelbuildingservice.ErrCodeNotFoundException: 115 fmt.Println(lexmodelbuildingservice.ErrCodeNotFoundException, aerr.Error()) 116 case lexmodelbuildingservice.ErrCodeLimitExceededException: 117 fmt.Println(lexmodelbuildingservice.ErrCodeLimitExceededException, aerr.Error()) 118 case lexmodelbuildingservice.ErrCodeInternalFailureException: 119 fmt.Println(lexmodelbuildingservice.ErrCodeInternalFailureException, aerr.Error()) 120 case lexmodelbuildingservice.ErrCodeBadRequestException: 121 fmt.Println(lexmodelbuildingservice.ErrCodeBadRequestException, aerr.Error()) 122 default: 123 fmt.Println(aerr.Error()) 124 } 125 } else { 126 // Print the error, cast err to awserr.Error to get the Code and 127 // Message from an error. 128 fmt.Println(err.Error()) 129 } 130 return 131 } 132 133 fmt.Println(result) 134 } 135 136 // To get a list of intents 137 // 138 // This example shows how to get a list of all of the intents in your account. 139 func ExampleLexModelBuildingService_GetIntents_shared00() { 140 svc := lexmodelbuildingservice.New(session.New()) 141 input := &lexmodelbuildingservice.GetIntentsInput{ 142 MaxResults: aws.Int64(10), 143 NextToken: aws.String(""), 144 } 145 146 result, err := svc.GetIntents(input) 147 if err != nil { 148 if aerr, ok := err.(awserr.Error); ok { 149 switch aerr.Code() { 150 case lexmodelbuildingservice.ErrCodeNotFoundException: 151 fmt.Println(lexmodelbuildingservice.ErrCodeNotFoundException, aerr.Error()) 152 case lexmodelbuildingservice.ErrCodeLimitExceededException: 153 fmt.Println(lexmodelbuildingservice.ErrCodeLimitExceededException, aerr.Error()) 154 case lexmodelbuildingservice.ErrCodeInternalFailureException: 155 fmt.Println(lexmodelbuildingservice.ErrCodeInternalFailureException, aerr.Error()) 156 case lexmodelbuildingservice.ErrCodeBadRequestException: 157 fmt.Println(lexmodelbuildingservice.ErrCodeBadRequestException, aerr.Error()) 158 default: 159 fmt.Println(aerr.Error()) 160 } 161 } else { 162 // Print the error, cast err to awserr.Error to get the Code and 163 // Message from an error. 164 fmt.Println(err.Error()) 165 } 166 return 167 } 168 169 fmt.Println(result) 170 } 171 172 // To get information about a slot type 173 // 174 // This example shows how to get information about a slot type. 175 func ExampleLexModelBuildingService_GetSlotType_shared00() { 176 svc := lexmodelbuildingservice.New(session.New()) 177 input := &lexmodelbuildingservice.GetSlotTypeInput{ 178 Name: aws.String("DocPizzaCrustType"), 179 Version: aws.String("$LATEST"), 180 } 181 182 result, err := svc.GetSlotType(input) 183 if err != nil { 184 if aerr, ok := err.(awserr.Error); ok { 185 switch aerr.Code() { 186 case lexmodelbuildingservice.ErrCodeNotFoundException: 187 fmt.Println(lexmodelbuildingservice.ErrCodeNotFoundException, aerr.Error()) 188 case lexmodelbuildingservice.ErrCodeLimitExceededException: 189 fmt.Println(lexmodelbuildingservice.ErrCodeLimitExceededException, aerr.Error()) 190 case lexmodelbuildingservice.ErrCodeInternalFailureException: 191 fmt.Println(lexmodelbuildingservice.ErrCodeInternalFailureException, aerr.Error()) 192 case lexmodelbuildingservice.ErrCodeBadRequestException: 193 fmt.Println(lexmodelbuildingservice.ErrCodeBadRequestException, aerr.Error()) 194 default: 195 fmt.Println(aerr.Error()) 196 } 197 } else { 198 // Print the error, cast err to awserr.Error to get the Code and 199 // Message from an error. 200 fmt.Println(err.Error()) 201 } 202 return 203 } 204 205 fmt.Println(result) 206 } 207 208 // To get a list of slot types 209 // 210 // This example shows how to get a list of all of the slot types in your account. 211 func ExampleLexModelBuildingService_GetSlotTypes_shared00() { 212 svc := lexmodelbuildingservice.New(session.New()) 213 input := &lexmodelbuildingservice.GetSlotTypesInput{ 214 MaxResults: aws.Int64(10), 215 NextToken: aws.String(""), 216 } 217 218 result, err := svc.GetSlotTypes(input) 219 if err != nil { 220 if aerr, ok := err.(awserr.Error); ok { 221 switch aerr.Code() { 222 case lexmodelbuildingservice.ErrCodeNotFoundException: 223 fmt.Println(lexmodelbuildingservice.ErrCodeNotFoundException, aerr.Error()) 224 case lexmodelbuildingservice.ErrCodeLimitExceededException: 225 fmt.Println(lexmodelbuildingservice.ErrCodeLimitExceededException, aerr.Error()) 226 case lexmodelbuildingservice.ErrCodeInternalFailureException: 227 fmt.Println(lexmodelbuildingservice.ErrCodeInternalFailureException, aerr.Error()) 228 case lexmodelbuildingservice.ErrCodeBadRequestException: 229 fmt.Println(lexmodelbuildingservice.ErrCodeBadRequestException, aerr.Error()) 230 default: 231 fmt.Println(aerr.Error()) 232 } 233 } else { 234 // Print the error, cast err to awserr.Error to get the Code and 235 // Message from an error. 236 fmt.Println(err.Error()) 237 } 238 return 239 } 240 241 fmt.Println(result) 242 } 243 244 // To create a bot 245 // 246 // This example shows how to create a bot for ordering pizzas. 247 func ExampleLexModelBuildingService_PutBot_shared00() { 248 svc := lexmodelbuildingservice.New(session.New()) 249 input := &lexmodelbuildingservice.PutBotInput{ 250 AbortStatement: &lexmodelbuildingservice.Statement{ 251 Messages: []*lexmodelbuildingservice.Message{ 252 { 253 Content: aws.String("I don't understand. Can you try again?"), 254 ContentType: aws.String("PlainText"), 255 }, 256 { 257 Content: aws.String("I'm sorry, I don't understand."), 258 ContentType: aws.String("PlainText"), 259 }, 260 }, 261 }, 262 ChildDirected: aws.Bool(true), 263 ClarificationPrompt: &lexmodelbuildingservice.Prompt{ 264 MaxAttempts: aws.Int64(1), 265 Messages: []*lexmodelbuildingservice.Message{ 266 { 267 Content: aws.String("I'm sorry, I didn't hear that. Can you repeat what you just said?"), 268 ContentType: aws.String("PlainText"), 269 }, 270 { 271 Content: aws.String("Can you say that again?"), 272 ContentType: aws.String("PlainText"), 273 }, 274 }, 275 }, 276 Description: aws.String("Orders a pizza from a local pizzeria."), 277 IdleSessionTTLInSeconds: aws.Int64(300), 278 Intents: []*lexmodelbuildingservice.Intent{ 279 { 280 IntentName: aws.String("DocOrderPizza"), 281 IntentVersion: aws.String("$LATEST"), 282 }, 283 }, 284 Locale: aws.String("en-US"), 285 Name: aws.String("DocOrderPizzaBot"), 286 ProcessBehavior: aws.String("SAVE"), 287 } 288 289 result, err := svc.PutBot(input) 290 if err != nil { 291 if aerr, ok := err.(awserr.Error); ok { 292 switch aerr.Code() { 293 case lexmodelbuildingservice.ErrCodeConflictException: 294 fmt.Println(lexmodelbuildingservice.ErrCodeConflictException, aerr.Error()) 295 case lexmodelbuildingservice.ErrCodeLimitExceededException: 296 fmt.Println(lexmodelbuildingservice.ErrCodeLimitExceededException, aerr.Error()) 297 case lexmodelbuildingservice.ErrCodeInternalFailureException: 298 fmt.Println(lexmodelbuildingservice.ErrCodeInternalFailureException, aerr.Error()) 299 case lexmodelbuildingservice.ErrCodeBadRequestException: 300 fmt.Println(lexmodelbuildingservice.ErrCodeBadRequestException, aerr.Error()) 301 case lexmodelbuildingservice.ErrCodePreconditionFailedException: 302 fmt.Println(lexmodelbuildingservice.ErrCodePreconditionFailedException, aerr.Error()) 303 default: 304 fmt.Println(aerr.Error()) 305 } 306 } else { 307 // Print the error, cast err to awserr.Error to get the Code and 308 // Message from an error. 309 fmt.Println(err.Error()) 310 } 311 return 312 } 313 314 fmt.Println(result) 315 } 316 317 // To create an intent 318 // 319 // This example shows how to create an intent for ordering pizzas. 320 func ExampleLexModelBuildingService_PutIntent_shared00() { 321 svc := lexmodelbuildingservice.New(session.New()) 322 input := &lexmodelbuildingservice.PutIntentInput{ 323 ConclusionStatement: &lexmodelbuildingservice.Statement{ 324 Messages: []*lexmodelbuildingservice.Message{ 325 { 326 Content: aws.String("All right, I ordered you a {Crust} crust {Type} pizza with {Sauce} sauce."), 327 ContentType: aws.String("PlainText"), 328 }, 329 { 330 Content: aws.String("OK, your {Crust} crust {Type} pizza with {Sauce} sauce is on the way."), 331 ContentType: aws.String("PlainText"), 332 }, 333 }, 334 ResponseCard: aws.String("foo"), 335 }, 336 ConfirmationPrompt: &lexmodelbuildingservice.Prompt{ 337 MaxAttempts: aws.Int64(1), 338 Messages: []*lexmodelbuildingservice.Message{ 339 { 340 Content: aws.String("Should I order your {Crust} crust {Type} pizza with {Sauce} sauce?"), 341 ContentType: aws.String("PlainText"), 342 }, 343 }, 344 }, 345 Description: aws.String("Order a pizza from a local pizzeria."), 346 FulfillmentActivity: &lexmodelbuildingservice.FulfillmentActivity{ 347 Type: aws.String("ReturnIntent"), 348 }, 349 Name: aws.String("DocOrderPizza"), 350 RejectionStatement: &lexmodelbuildingservice.Statement{ 351 Messages: []*lexmodelbuildingservice.Message{ 352 { 353 Content: aws.String("Ok, I'll cancel your order."), 354 ContentType: aws.String("PlainText"), 355 }, 356 { 357 Content: aws.String("I cancelled your order."), 358 ContentType: aws.String("PlainText"), 359 }, 360 }, 361 }, 362 SampleUtterances: []*string{ 363 aws.String("Order me a pizza."), 364 aws.String("Order me a {Type} pizza."), 365 aws.String("I want a {Crust} crust {Type} pizza"), 366 aws.String("I want a {Crust} crust {Type} pizza with {Sauce} sauce."), 367 }, 368 Slots: []*lexmodelbuildingservice.Slot{ 369 { 370 Description: aws.String("The type of pizza to order."), 371 Name: aws.String("Type"), 372 Priority: aws.Int64(1), 373 SampleUtterances: []*string{ 374 aws.String("Get me a {Type} pizza."), 375 aws.String("A {Type} pizza please."), 376 aws.String("I'd like a {Type} pizza."), 377 }, 378 SlotConstraint: aws.String("Required"), 379 SlotType: aws.String("DocPizzaType"), 380 SlotTypeVersion: aws.String("$LATEST"), 381 ValueElicitationPrompt: &lexmodelbuildingservice.Prompt{ 382 MaxAttempts: aws.Int64(1), 383 Messages: []*lexmodelbuildingservice.Message{ 384 { 385 Content: aws.String("What type of pizza would you like?"), 386 ContentType: aws.String("PlainText"), 387 }, 388 { 389 Content: aws.String("Vegie or cheese pizza?"), 390 ContentType: aws.String("PlainText"), 391 }, 392 { 393 Content: aws.String("I can get you a vegie or a cheese pizza."), 394 ContentType: aws.String("PlainText"), 395 }, 396 }, 397 }, 398 }, 399 { 400 Description: aws.String("The type of pizza crust to order."), 401 Name: aws.String("Crust"), 402 Priority: aws.Int64(2), 403 SampleUtterances: []*string{ 404 aws.String("Make it a {Crust} crust."), 405 aws.String("I'd like a {Crust} crust."), 406 }, 407 SlotConstraint: aws.String("Required"), 408 SlotType: aws.String("DocPizzaCrustType"), 409 SlotTypeVersion: aws.String("$LATEST"), 410 ValueElicitationPrompt: &lexmodelbuildingservice.Prompt{ 411 MaxAttempts: aws.Int64(1), 412 Messages: []*lexmodelbuildingservice.Message{ 413 { 414 Content: aws.String("What type of crust would you like?"), 415 ContentType: aws.String("PlainText"), 416 }, 417 { 418 Content: aws.String("Thick or thin crust?"), 419 ContentType: aws.String("PlainText"), 420 }, 421 }, 422 }, 423 }, 424 { 425 Description: aws.String("The type of sauce to use on the pizza."), 426 Name: aws.String("Sauce"), 427 Priority: aws.Int64(3), 428 SampleUtterances: []*string{ 429 aws.String("Make it {Sauce} sauce."), 430 aws.String("I'd like {Sauce} sauce."), 431 }, 432 SlotConstraint: aws.String("Required"), 433 SlotType: aws.String("DocPizzaSauceType"), 434 SlotTypeVersion: aws.String("$LATEST"), 435 ValueElicitationPrompt: &lexmodelbuildingservice.Prompt{ 436 MaxAttempts: aws.Int64(1), 437 Messages: []*lexmodelbuildingservice.Message{ 438 { 439 Content: aws.String("White or red sauce?"), 440 ContentType: aws.String("PlainText"), 441 }, 442 { 443 Content: aws.String("Garlic or tomato sauce?"), 444 ContentType: aws.String("PlainText"), 445 }, 446 }, 447 }, 448 }, 449 }, 450 } 451 452 result, err := svc.PutIntent(input) 453 if err != nil { 454 if aerr, ok := err.(awserr.Error); ok { 455 switch aerr.Code() { 456 case lexmodelbuildingservice.ErrCodeConflictException: 457 fmt.Println(lexmodelbuildingservice.ErrCodeConflictException, aerr.Error()) 458 case lexmodelbuildingservice.ErrCodeLimitExceededException: 459 fmt.Println(lexmodelbuildingservice.ErrCodeLimitExceededException, aerr.Error()) 460 case lexmodelbuildingservice.ErrCodeInternalFailureException: 461 fmt.Println(lexmodelbuildingservice.ErrCodeInternalFailureException, aerr.Error()) 462 case lexmodelbuildingservice.ErrCodeBadRequestException: 463 fmt.Println(lexmodelbuildingservice.ErrCodeBadRequestException, aerr.Error()) 464 case lexmodelbuildingservice.ErrCodePreconditionFailedException: 465 fmt.Println(lexmodelbuildingservice.ErrCodePreconditionFailedException, aerr.Error()) 466 default: 467 fmt.Println(aerr.Error()) 468 } 469 } else { 470 // Print the error, cast err to awserr.Error to get the Code and 471 // Message from an error. 472 fmt.Println(err.Error()) 473 } 474 return 475 } 476 477 fmt.Println(result) 478 } 479 480 // To Create a Slot Type 481 // 482 // This example shows how to create a slot type that describes pizza sauces. 483 func ExampleLexModelBuildingService_PutSlotType_shared00() { 484 svc := lexmodelbuildingservice.New(session.New()) 485 input := &lexmodelbuildingservice.PutSlotTypeInput{ 486 Description: aws.String("Available pizza sauces"), 487 EnumerationValues: []*lexmodelbuildingservice.EnumerationValue{ 488 { 489 Value: aws.String("red"), 490 }, 491 { 492 Value: aws.String("white"), 493 }, 494 }, 495 Name: aws.String("PizzaSauceType"), 496 } 497 498 result, err := svc.PutSlotType(input) 499 if err != nil { 500 if aerr, ok := err.(awserr.Error); ok { 501 switch aerr.Code() { 502 case lexmodelbuildingservice.ErrCodeConflictException: 503 fmt.Println(lexmodelbuildingservice.ErrCodeConflictException, aerr.Error()) 504 case lexmodelbuildingservice.ErrCodeLimitExceededException: 505 fmt.Println(lexmodelbuildingservice.ErrCodeLimitExceededException, aerr.Error()) 506 case lexmodelbuildingservice.ErrCodeInternalFailureException: 507 fmt.Println(lexmodelbuildingservice.ErrCodeInternalFailureException, aerr.Error()) 508 case lexmodelbuildingservice.ErrCodeBadRequestException: 509 fmt.Println(lexmodelbuildingservice.ErrCodeBadRequestException, aerr.Error()) 510 case lexmodelbuildingservice.ErrCodePreconditionFailedException: 511 fmt.Println(lexmodelbuildingservice.ErrCodePreconditionFailedException, aerr.Error()) 512 default: 513 fmt.Println(aerr.Error()) 514 } 515 } else { 516 // Print the error, cast err to awserr.Error to get the Code and 517 // Message from an error. 518 fmt.Println(err.Error()) 519 } 520 return 521 } 522 523 fmt.Println(result) 524 }