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 support for template option 'initial_open' #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,10 @@ Here's the output of the example linked above, which generates a message with 2
}
}

### Transmission Options

Transmission options can be used to control various settings on the transmission you're building, and can be used to override
some account-level settings (such as open tracking).

[Options example](options/options.go)

44 changes: 44 additions & 0 deletions examples/options/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"encoding/json"
"fmt"
sp "github.com/SparkPost/gosparkpost"
"os"
)

func main() {
content := sp.Content{
From: "[email protected]",
Subject: "transmission options example message",
Text: "This is a transmissions options example",
}

initialOpenTracking := false
openTracking := true
clickTracking := true
options := sp.TmplOptions{
InitialOpenTracking: &initialOpenTracking,
OpenTracking: &openTracking,
ClickTracking: &clickTracking,
}

txOptions := &sp.TxOptions{
TmplOptions: options,
IPPool: "my-ip-pool",
}

tx := &sp.Transmission{
Recipients: []sp.Recipient{{Address: "[email protected]"}},
}
tx.Content = content
tx.Options = txOptions

jsonBytes, err := json.Marshal(tx)
if err != nil {
panic(err)
}
fmt.Fprintln(os.Stdout, string(jsonBytes))

}

7 changes: 4 additions & 3 deletions templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ type From struct {
// TmplOptions specifies settings to apply to this Template.
// These settings may be overridden in the Transmission API call.
type TmplOptions struct {
OpenTracking *bool `json:"open_tracking,omitempty"`
ClickTracking *bool `json:"click_tracking,omitempty"`
Transactional *bool `json:"transactional,omitempty"`
InitialOpenTracking *bool `json:"initial_open,omitempty"`
OpenTracking *bool `json:"open_tracking,omitempty"`
ClickTracking *bool `json:"click_tracking,omitempty"`
Transactional *bool `json:"transactional,omitempty"`
}

// PreviewOptions contains the required subsitution_data object to
Expand Down
4 changes: 4 additions & 0 deletions transmissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func TestTransmissionOptions(t *testing.T) {
&sp.TxOptions{},
[]byte(`"options":{}`),
},
{
&sp.TxOptions{TmplOptions: sp.TmplOptions{InitialOpenTracking: new(bool)}},
[]byte(`"options":{"initial_open":false}`),
},
{
&sp.TxOptions{InlineCSS: new(bool), PerformSubstitutions: new(bool)},
[]byte(`"options":{"inline_css":false,"perform_substitutions":false}`),
Expand Down