-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sharon Nam
authored and
Sharon Nam
committed
Dec 13, 2023
1 parent
fcc4d74
commit 7243b74
Showing
3 changed files
with
275 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package schema | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/provider/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" | ||
) | ||
|
||
func MessageGroupsBlock(ctx context.Context) schema.ListNestedBlock { | ||
messageNBO := schema.NestedBlockObject{ | ||
Blocks: map[string]schema.Block{ | ||
"custom_playload": schema.ListNestedBlock{ | ||
Validators: []validator.List{ | ||
listvalidator.SizeAtMost(1), | ||
}, | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[CustomPayload](ctx), | ||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"value": schema.StringAttribute{ | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"image_response_card": schema.ListNestedBlock{ | ||
Validators: []validator.List{ | ||
listvalidator.SizeAtMost(1), | ||
}, | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[ImageResponseCard](ctx), | ||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"image_url": schema.StringAttribute{ | ||
Optional: true, | ||
}, | ||
"subtitle": schema.StringAttribute{ | ||
Optional: true, | ||
}, | ||
"title": schema.StringAttribute{ | ||
Required: true, | ||
}, | ||
}, | ||
Blocks: map[string]schema.Block{ | ||
"button": schema.ListNestedBlock{ | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[Button](ctx), | ||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"text": schema.StringAttribute{ | ||
Required: true, | ||
}, | ||
"value": schema.StringAttribute{ | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"plain_text_message": schema.ListNestedBlock{ | ||
Validators: []validator.List{ | ||
listvalidator.SizeAtMost(1), | ||
}, | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[PlainTextMessage](ctx), | ||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"value": schema.StringAttribute{ | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"ssml_message": schema.ListNestedBlock{ | ||
Validators: []validator.List{ | ||
listvalidator.SizeAtMost(1), | ||
}, | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[SSMLMessage](ctx), | ||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"value": schema.StringAttribute{ | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
return schema.ListNestedBlock{ | ||
Validators: []validator.List{ | ||
listvalidator.SizeAtLeast(1), | ||
}, | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[MessageGroup](ctx), | ||
NestedObject: schema.NestedBlockObject{ | ||
Blocks: map[string]schema.Block{ | ||
"message": schema.ListNestedBlock{ | ||
Validators: []validator.List{ | ||
listvalidator.SizeBetween(1, 1), | ||
}, | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[Message](ctx), | ||
NestedObject: messageNBO, | ||
}, | ||
"variations": schema.ListNestedBlock{ | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[Message](ctx), | ||
NestedObject: messageNBO, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type CustomPayload struct { | ||
Value types.String `tfsdk:"value"` | ||
} | ||
|
||
type ImageResponseCard struct { | ||
Title types.String `tfsdk:"title"` | ||
Button fwtypes.ListNestedObjectValueOf[Button] `tfsdk:"buttons"` | ||
ImageURL types.String `tfsdk:"image_url"` | ||
Subtitle types.String `tfsdk:"subtitle"` | ||
} | ||
|
||
type Button struct { | ||
Text types.String `tfsdk:"text"` | ||
Value types.String `tfsdk:"value"` | ||
} | ||
|
||
type PlainTextMessage struct { | ||
Value types.String `tfsdk:"value"` | ||
} | ||
|
||
type SSMLMessage struct { | ||
Value types.String `tfsdk:"value"` | ||
} | ||
type MessageGroup struct { | ||
Message fwtypes.ListNestedObjectValueOf[Message] `tfsdk:"message"` | ||
Variations fwtypes.ListNestedObjectValueOf[Message] `tfsdk:"variations"` | ||
} | ||
|
||
type Message struct { | ||
CustomPayload fwtypes.ListNestedObjectValueOf[CustomPayload] `tfsdk:"custom_payload"` | ||
ImageResponseCard fwtypes.ListNestedObjectValueOf[ImageResponseCard] `tfsdk:"image_response_card"` | ||
PlainTextMessage fwtypes.ListNestedObjectValueOf[PlainTextMessage] `tfsdk:"plain_text_message"` | ||
SSMLMessage fwtypes.ListNestedObjectValueOf[SSMLMessage] `tfsdk:"ssml_message"` | ||
} |
124 changes: 124 additions & 0 deletions
124
internal/service/lexv2models/schema/prompt_specification.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package schema | ||
|
||
import ( | ||
"context" | ||
|
||
awstypes "github.com/aws/aws-sdk-go-v2/service/lexmodelsv2/types" | ||
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/provider/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-provider-aws/internal/enum" | ||
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" | ||
) | ||
|
||
func PromptSpecificationBlock(ctx context.Context) schema.ListNestedBlock { | ||
return schema.ListNestedBlock{ | ||
Validators: []validator.List{ | ||
listvalidator.SizeBetween(1, 1), | ||
}, | ||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"max_retries": schema.Int64Attribute{ | ||
Required: true, | ||
}, | ||
"allow_interrupt": schema.BoolAttribute{ | ||
Optional: true, | ||
}, | ||
"message_selection_strategy": schema.StringAttribute{ | ||
Optional: true, | ||
Validators: []validator.String{ | ||
enum.FrameworkValidate[awstypes.MessageSelectionStrategy](), | ||
}, | ||
}, | ||
"prompt_attempts_specification": schema.MapAttribute{ | ||
Optional: true, | ||
ElementType: types.ObjectType{ | ||
AttrTypes: map[string]attr.Type{ | ||
"allow_input_types": types.ObjectType{ | ||
AttrTypes: map[string]attr.Type{ | ||
"allow_audio_input": types.BoolType, | ||
"allow_dtmf_input": types.BoolType, | ||
}, | ||
}, | ||
"allow_interrupts": types.BoolType, | ||
"audio_and_dtmf_input_specification": types.ObjectType{ | ||
AttrTypes: map[string]attr.Type{ | ||
"start_timeout_ms": types.Int64Type, | ||
"audio_specification": types.ObjectType{ | ||
AttrTypes: map[string]attr.Type{ | ||
"end_timeout_ms": types.Int64Type, | ||
"max_length_ms": types.Int64Type, | ||
}, | ||
}, | ||
"dtmf_specification": types.ObjectType{ | ||
AttrTypes: map[string]attr.Type{ | ||
"deletion_character": types.StringType, | ||
"end_character": types.StringType, | ||
"end_timeout_ms": types.Int64Type, | ||
"max_length": types.Int64Type, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"text_input_specification": types.ObjectType{ | ||
AttrTypes: map[string]attr.Type{ | ||
"start_timeout_ms": types.Int64Type, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Blocks: map[string]schema.Block{ | ||
"message_groups": MessageGroupsBlock(ctx), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type PromptSpecification struct { | ||
MaxRetries types.Int64 `tfsdk:"max_retries"` | ||
MessageGroup fwtypes.ListNestedObjectValueOf[MessageGroup] `tfsdk:"message_groups"` | ||
AllowInterrupt types.Bool `tfsdk:"allow_interrupt"` | ||
MessageSelectionStrategy fwtypes.StringEnum[awstypes.MessageSelectionStrategy] `tfsdk:"message_selection_strategy"` | ||
PromptAttemptsSpecification fwtypes.ObjectMapValueOf[PromptAttemptSpecification] `tfsdk:"prompt_attempts_specification"` | ||
} | ||
|
||
type PromptAttemptSpecification struct { | ||
AllowedInputTypes fwtypes.ListNestedObjectValueOf[AllowedInputTypes] `tfsdk:"allowed_input_types"` | ||
AllowInterrupt types.Bool `tfsdk:"allow_interrupt"` | ||
AudioAndDTMFInputSpecification fwtypes.ListNestedObjectValueOf[AudioAndDTMFInputSpecification] `tfsdk:"audio_and_dtmf_input_specification"` | ||
TextInputSpecification fwtypes.ListNestedObjectValueOf[TextInputSpecification] `tfsdk:"text_input_specification"` | ||
} | ||
|
||
type DTMFSpecification struct { | ||
DeletionCharacter types.String `tfsdk:"deletion_character"` | ||
EndCharacter types.String `tfsdk:"end_character"` | ||
EndTimeoutMs types.Int64 `tfsdk:"end_timeout_ms"` | ||
MaxLength types.Int64 `tfsdk:"max_length"` | ||
} | ||
|
||
type TextInputSpecification struct { | ||
StartTimeoutMs types.Int64 `tfsdk:"start_timeout_ms"` | ||
} | ||
|
||
type AllowedInputTypes struct { | ||
AllowAudioInput types.Bool `tfsdk:"allow_audio_input"` | ||
AllowDTMFInput types.Bool `tfsdk:"allow_dtmf_input"` | ||
} | ||
|
||
type AudioAndDTMFInputSpecification struct { | ||
StartTimeoutMs types.Int64 `tfsdk:"start_timeout_ms"` | ||
AudioSpecification fwtypes.ListNestedObjectValueOf[AudioSpecification] `tfsdk:"audio_specification"` | ||
DTMFSpecification fwtypes.ListNestedObjectValueOf[DTMFSpecification] `tfsdk:"dtmf_specification"` | ||
} | ||
|
||
type AudioSpecification struct { | ||
EndTimeoutMs types.Int64 `tfsdk:"end_timeout_ms"` | ||
MaxLengthMs types.Int64 `tfsdk:"max_length_ms"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters