Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add email route #1448

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/resources/routing_email_route.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ resource "genesyscloud_routing_email_route" "support-route" {

### Optional

- `allow_multiple_actions` (Boolean) Control if multiple actions are allowed on this route. When true the disconnect has to be done manually. When false a conversation will be disconnected by the system after every action.
- `auto_bcc` (Block Set) The recipients that should be automatically blind copied on outbound emails associated with this route. This should not be set if reply_email_address is specified. (see [below for nested schema](#nestedblock--auto_bcc))
- `flow_id` (String) The flow to use for processing the email. This should not be set if a queue_id is specified.
- `from_email` (String) The sender email to use for outgoing replies. This should not be set if reply_email_address is specified.
- `history_inclusion` (String) The configuration to indicate how the history of a conversation has to be included in a draft. Defaults to `Optional`.
- `language_id` (String) The language to use for routing.
- `priority` (Number) The priority to use for routing.
- `queue_id` (String) The queue to route the emails to. This should not be set if a flow_id is specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ func readRoutingEmailRoute(ctx context.Context, d *schema.ResourceData, meta int
resourcedata.SetNillableValue(d, "pattern", route.Pattern)
resourcedata.SetNillableReference(d, "queue_id", route.Queue)
resourcedata.SetNillableValue(d, "priority", route.Priority)
resourcedata.SetNillableValue(d, "history_inclusion", route.HistoryInclusion)
resourcedata.SetNillableReference(d, "language_id", route.Language)
resourcedata.SetNillableValue(d, "from_name", route.FromName)
resourcedata.SetNillableValue(d, "from_email", route.FromEmail)
resourcedata.SetNillableReference(d, "flow_id", route.Flow)
resourcedata.SetNillableValueWithInterfaceArrayWithFunc(d, "auto_bcc", route.AutoBcc, flattenAutoBccEmailAddress)
resourcedata.SetNillableReference(d, "spam_flow_id", route.SpamFlow)
resourcedata.SetNillableValue(d, "allow_multiple_actions", route.AllowMultipleActions)

if route.Skills != nil {
_ = d.Set("skill_ids", util.SdkDomainEntityRefArrToSet(*route.Skills))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package routing_email_route

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"terraform-provider-genesyscloud/genesyscloud/provider"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -103,6 +104,18 @@ func ResourceRoutingEmailRoute() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"history_inclusion": {
Description: "The configuration to indicate how the history of a conversation has to be included in a draft.",
Type: schema.TypeString,
Optional: true,
Default: "Optional",
ValidateFunc: validation.StringInSlice([]string{"Include", "Exclude", "Optional"}, true),
},
"allow_multiple_actions": {
Description: "Control if multiple actions are allowed on this route. When true the disconnect has to be done manually. When false a conversation will be disconnected by the system after every action.",
Type: schema.TypeBool,
Optional: true,
},
"reply_email_address": {
Description: "The route to use for email replies. This should not be set if from_email or auto_bcc are specified.",
Type: schema.TypeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,28 @@ import (

func TestAccResourceRoutingEmailRoute(t *testing.T) {
var (
domainResourceLabel = "routing-domain1"
domainId = fmt.Sprintf("terraformroutes.%s.com", strings.Replace(uuid.NewString(), "-", "", -1))
queueResourceLabel = "email-queue"
queueName = "Terraform Email Queue-" + uuid.NewString()
langResourceLabel = "email-lang"
langName = "tflang" + uuid.NewString()
skillResourceLabel = "test-skill1"
skillName = "Terraform Skill" + uuid.NewString()
routeResourceLabel1 = "email-route1"
routeResourceLabel2 = "email-route2"
routePattern1 = "terraform1"
routePattern2 = "terraform2"
routePattern3 = "terraform3"
fromEmail1 = "terraform1@test.com"
fromEmail2 = "terraform2@test.com"
fromName1 = "John Terraform"
fromName2 = "Jane Terraform"
priority1 = "1"
bccEmail1 = "test1@" + domainId
bccEmail2 = "test2@" + domainId
domainResourceLabel = "routing-domain1"
domainId = fmt.Sprintf("terraformroutes.%s.com", strings.Replace(uuid.NewString(), "-", "", -1))
queueResourceLabel = "email-queue"
queueName = "Terraform Email Queue-" + uuid.NewString()
langResourceLabel = "email-lang"
langName = "tflang" + uuid.NewString()
skillResourceLabel = "test-skill1"
skillName = "Terraform Skill" + uuid.NewString()
routeResourceLabel1 = "email-route1"
routeResourceLabel2 = "email-route2"
routePattern1 = "terraform1"
routePattern2 = "terraform2"
routePattern3 = "terraform3"
fromEmail1 = "terraform1@test.com"
fromEmail2 = "terraform2@test.com"
fromName1 = "John Terraform"
fromName2 = "Jane Terraform"
priority1 = "1"
bccEmail1 = "test1@" + domainId
bccEmail2 = "test2@" + domainId
allowMultipleActions = "true"
historyInclusion = "Include"
)

CleanupRoutingEmailDomains()
Expand All @@ -65,6 +67,8 @@ func TestAccResourceRoutingEmailRoute(t *testing.T) {
routePattern1,
fromName1,
fmt.Sprintf("from_email = \"%s\"", fromEmail1),
fmt.Sprintf("allow_multiple_actions = \"%s\"", allowMultipleActions),
fmt.Sprintf("history_inclusion = \"%s\"", historyInclusion),
generateRoutingAutoBcc(fromName1, bccEmail1),
),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -74,6 +78,8 @@ func TestAccResourceRoutingEmailRoute(t *testing.T) {
resource.TestCheckResourceAttr("genesyscloud_routing_email_route."+routeResourceLabel1, "from_email", fromEmail1),
resource.TestCheckResourceAttr("genesyscloud_routing_email_route."+routeResourceLabel1, "auto_bcc.0.name", fromName1),
resource.TestCheckResourceAttr("genesyscloud_routing_email_route."+routeResourceLabel1, "auto_bcc.0.email", bccEmail1),
resource.TestCheckResourceAttr("genesyscloud_routing_email_route."+routeResourceLabel1, "allow_multiple_actions", allowMultipleActions),
resource.TestCheckResourceAttr("genesyscloud_routing_email_route."+routeResourceLabel1, "history_inclusion", historyInclusion),
),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ and unmarshal data into formats consumable by Terraform and/or Genesys Cloud.
// getRoutingEmailRouteFromResourceData maps data from schema ResourceData object to a platformclientv2.Inboundroute
func getRoutingEmailRouteFromResourceData(d *schema.ResourceData) platformclientv2.Inboundroute {
id := d.Id()
return platformclientv2.Inboundroute{
inboundRoute := platformclientv2.Inboundroute{
Id: &id,
Pattern: platformclientv2.String(d.Get("pattern").(string)),
Queue: util.BuildSdkDomainEntityRef(d, "queue_id"),
Expand All @@ -32,6 +32,14 @@ func getRoutingEmailRouteFromResourceData(d *schema.ResourceData) platformclient
AutoBcc: buildAutoBccEmailAddresses(d),
SpamFlow: util.BuildSdkDomainEntityRef(d, "spam_flow_id"),
}

if d.Get("history_inclusion") != "" {
inboundRoute.HistoryInclusion = platformclientv2.String(d.Get("history_inclusion").(string))
}
if d.Get("allow_multiple_actions") != "" {
inboundRoute.AllowMultipleActions = platformclientv2.Bool(d.Get("allow_multiple_actions").(bool))
}
return inboundRoute
}

// Build Functions
Expand Down Expand Up @@ -166,11 +174,14 @@ func GenerateRoutingEmailRouteResource(
pattern string,
fromName string,
otherAttrs ...string) string {
return fmt.Sprintf(`resource "genesyscloud_routing_email_route" "%s" {
hh := fmt.Sprintf(`resource "genesyscloud_routing_email_route" "%s" {
domain_id = %s
pattern = "%s"
from_name = "%s"
%s
}
`, resourceLabel, domainID, pattern, fromName, strings.Join(otherAttrs, "\n"))

fmt.Println(hh)
return hh
}
Loading