Skip to content
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 packages/go-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ err := client.TurboSign.Resend(ctx, "doc-uuid-here", []string{"recipient-uuid-1"
For complete, working examples including template anchors, advanced field types, and various workflows, see the [`examples/`](./examples/) directory:

- [`turbosign_send_simple.go`](./examples/turbosign_send_simple.go) - Send document directly with template anchors
- [`turbosign_basic.go`](./examples/turbosign_basic.go) - Create review link first, then send manually
- [`turbosign_advanced.go`](./examples/turbosign_advanced.go) - Advanced field types (checkbox, readonly, multiline text, etc.)

### Sequential Signing

Expand Down
10 changes: 5 additions & 5 deletions packages/go-sdk/cmd/manual/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ var client *turbodocx.Client
func init() {
var err error
client, err = turbodocx.NewClientWithConfig(turbodocx.ClientConfig{
APIKey: apiKey,
BaseURL: baseURL,
OrgID: orgID,
APIKey: apiKey,
BaseURL: baseURL,
OrgID: orgID,
SenderEmail: "sender@example.com", // Reply-to email for signature requests
SenderName: "Your Company Name", // Sender name shown in emails
})
if err != nil {
fmt.Printf("Failed to create client: %v\n", err)
Expand Down Expand Up @@ -136,8 +138,6 @@ func testSendSignature(ctx context.Context, pdfBytes []byte) (string, error) {
},
DocumentName: "Signing Test Document (Template Fields)",
DocumentDescription: "Testing template-based field positioning",
SenderName: "Test Sender",
SenderEmail: "sender@example.com",
CCEmails: []string{"cc@example.com"},
})

Expand Down
161 changes: 161 additions & 0 deletions packages/go-sdk/examples/turbosign_advanced.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
//go:build ignore
// +build ignore

// Example 3: Review Link - Advanced Field Types
//
// This example demonstrates advanced field types and features:
// - Multiple field types: signature, date, text, checkbox, company, title
// - Readonly fields with default values
// - Required fields
// - Multiline text fields
//
// Use this when: You need complex forms with varied input types

package main

import (
"context"
"fmt"
"os"

turbodocx "github.com/TurboDocx/SDK/packages/go-sdk"
)

func main() {
// Configure TurboDocx client
client, err := turbodocx.NewClientWithConfig(turbodocx.ClientConfig{
APIKey: getEnv("TURBODOCX_API_KEY", "your-api-key-here"),
OrgID: getEnv("TURBODOCX_ORG_ID", "your-org-id-here"),
SenderEmail: getEnv("TURBODOCX_SENDER_EMAIL", "support@yourcompany.com"),
SenderName: getEnv("TURBODOCX_SENDER_NAME", "Your Company Name"),
})
if err != nil {
fmt.Printf("Error creating client: %v\n", err)
return
}

// Read PDF file
pdfFile, err := os.ReadFile("../../ExampleAssets/advanced-contract.pdf")
if err != nil {
fmt.Printf("Error reading file: %v\n", err)
return
}

fmt.Println("Creating review link with advanced field types...\n")

ctx := context.Background()
result, err := client.TurboSign.CreateSignatureReviewLink(ctx, &turbodocx.CreateSignatureReviewLinkRequest{
File: pdfFile,
FileName: "advanced-contract.pdf",
DocumentName: "Advanced Contract",
DocumentDescription: "Contract with advanced signature field features",
Recipients: []turbodocx.Recipient{
{Name: "John Doe", Email: "john@example.com", SigningOrder: 1},
},
Fields: []turbodocx.Field{
// Signature field
{
Type: "signature",
RecipientEmail: "john@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{signature}",
Placement: "replace",
Size: &turbodocx.Size{Width: 100, Height: 30},
},
},
// Date field
{
Type: "date",
RecipientEmail: "john@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{date}",
Placement: "replace",
Size: &turbodocx.Size{Width: 75, Height: 30},
},
},
// Full name field
{
Type: "full_name",
RecipientEmail: "john@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{printed_name}",
Placement: "replace",
Size: &turbodocx.Size{Width: 100, Height: 20},
},
},
// Readonly field with default value (pre-filled)
{
Type: "company",
RecipientEmail: "john@example.com",
DefaultValue: "TurboDocx",
IsReadonly: true,
Template: &turbodocx.TemplateAnchor{
Anchor: "{company}",
Placement: "replace",
Size: &turbodocx.Size{Width: 100, Height: 20},
},
},
// Required checkbox with default checked
{
Type: "checkbox",
RecipientEmail: "john@example.com",
DefaultValue: "true",
Required: true,
Template: &turbodocx.TemplateAnchor{
Anchor: "{terms_checkbox}",
Placement: "replace",
Size: &turbodocx.Size{Width: 20, Height: 20},
},
},
// Title field
{
Type: "title",
RecipientEmail: "john@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{title}",
Placement: "replace",
Size: &turbodocx.Size{Width: 75, Height: 30},
},
},
// Multiline text field
{
Type: "text",
RecipientEmail: "john@example.com",
IsMultiline: true,
Template: &turbodocx.TemplateAnchor{
Anchor: "{notes}",
Placement: "replace",
Size: &turbodocx.Size{Width: 200, Height: 50},
},
},
},
})

if err != nil {
fmt.Printf("Error: %v\n", err)
return
}

fmt.Println("✅ Review link created!\n")
fmt.Printf("Document ID: %s\n", result.DocumentID)
fmt.Printf("Status: %s\n", result.Status)
fmt.Printf("Preview URL: %s\n", result.PreviewURL)

if result.Recipients != nil {
fmt.Println("\nRecipients:")
for _, recipient := range result.Recipients {
fmt.Printf(" %s (%s) - %s\n", recipient.Name, recipient.Email, recipient.Status)
}
}

fmt.Println("\nNext steps:")
fmt.Println("1. Review the document at the preview URL")
fmt.Println("2. Send to recipients: client.TurboSign.Send(ctx, documentId)")
}

func getEnv(key, fallback string) string {
if value := os.Getenv(key); value != "" {
return value
}
return fallback
}
140 changes: 140 additions & 0 deletions packages/go-sdk/examples/turbosign_basic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
//go:build ignore
// +build ignore

// Example 2: Review Link - Template Anchors
//
// This example creates a review link first, then sends manually.
// Uses template anchors like {signature1} and {date1} in your PDF.
//
// Use this when: You want to review the document before sending

package main

import (
"context"
"fmt"
"os"

turbodocx "github.com/TurboDocx/SDK/packages/go-sdk"
)

func main() {
// Configure TurboDocx client
client, err := turbodocx.NewClientWithConfig(turbodocx.ClientConfig{
APIKey: getEnv("TURBODOCX_API_KEY", "your-api-key-here"),
OrgID: getEnv("TURBODOCX_ORG_ID", "your-org-id-here"),
SenderEmail: getEnv("TURBODOCX_SENDER_EMAIL", "support@yourcompany.com"),
SenderName: getEnv("TURBODOCX_SENDER_NAME", "Your Company Name"),
})
if err != nil {
fmt.Printf("Error creating client: %v\n", err)
return
}

// Read PDF file
pdfFile, err := os.ReadFile("../../ExampleAssets/sample-contract.pdf")
if err != nil {
fmt.Printf("Error reading file: %v\n", err)
return
}

fmt.Println("Creating review link with template anchors...\n")

ctx := context.Background()
result, err := client.TurboSign.CreateSignatureReviewLink(ctx, &turbodocx.CreateSignatureReviewLinkRequest{
File: pdfFile,
FileName: "sample-contract.pdf",
DocumentName: "Contract Agreement",
DocumentDescription: "This document requires electronic signatures from both parties.",
Recipients: []turbodocx.Recipient{
{Name: "John Doe", Email: "john@example.com", SigningOrder: 1},
{Name: "Jane Smith", Email: "jane@example.com", SigningOrder: 2},
},
Fields: []turbodocx.Field{
// First recipient - using template anchors
{
Type: "full_name",
RecipientEmail: "john@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{name1}",
Placement: "replace",
Size: &turbodocx.Size{Width: 100, Height: 30},
},
},
{
Type: "signature",
RecipientEmail: "john@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{signature1}",
Placement: "replace",
Size: &turbodocx.Size{Width: 100, Height: 30},
},
},
{
Type: "date",
RecipientEmail: "john@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{date1}",
Placement: "replace",
Size: &turbodocx.Size{Width: 75, Height: 30},
},
},
// Second recipient
{
Type: "full_name",
RecipientEmail: "jane@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{name2}",
Placement: "replace",
Size: &turbodocx.Size{Width: 100, Height: 30},
},
},
{
Type: "signature",
RecipientEmail: "jane@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{signature2}",
Placement: "replace",
Size: &turbodocx.Size{Width: 100, Height: 30},
},
},
{
Type: "date",
RecipientEmail: "jane@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{date2}",
Placement: "replace",
Size: &turbodocx.Size{Width: 75, Height: 30},
},
},
},
})

if err != nil {
fmt.Printf("Error: %v\n", err)
return
}

fmt.Println("\n✅ Review link created!")
fmt.Printf("Document ID: %s\n", result.DocumentID)
fmt.Printf("Status: %s\n", result.Status)
fmt.Printf("Preview URL: %s\n", result.PreviewURL)

if result.Recipients != nil {
fmt.Println("\nRecipients:")
for _, recipient := range result.Recipients {
fmt.Printf(" %s (%s) - %s\n", recipient.Name, recipient.Email, recipient.Status)
}
}

fmt.Println("\nYou can now:")
fmt.Println("1. Review the document at the preview URL")
fmt.Println("2. Send to recipients using: client.TurboSign.Send(ctx, documentId)")
}

func getEnv(key, fallback string) string {
if value := os.Getenv(key); value != "" {
return value
}
return fallback
}
Loading
Loading