Skip to content

Commit

Permalink
add email route
Browse files Browse the repository at this point in the history
  • Loading branch information
HemanthDogiparthi12 committed Jan 3, 2025
1 parent 3d6ad18 commit f8232b2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
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,16 @@ func getRoutingEmailRouteFromResourceData(d *schema.ResourceData) platformclient
AutoBcc: buildAutoBccEmailAddresses(d),
SpamFlow: util.BuildSdkDomainEntityRef(d, "spam_flow_id"),
}

if d.Get("history_inclusion") != "" {
fmt.Println("reached")
fmt.Printf("%v ", platformclientv2.String(d.Get("history_inclusion").(string)))
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 +176,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
}

0 comments on commit f8232b2

Please sign in to comment.