Skip to content

Commit

Permalink
fix(kno-5952): improve readme trigger docs (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlymar authored May 16, 2024
1 parent 9adfda5 commit 8cf3a4a
Showing 1 changed file with 63 additions and 2 deletions.
65 changes: 63 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,75 @@ fmt.Printf("user-name: %+v\n", user)
### Sending notifies (triggering workflows)
Simple trigger for one recipient by id:
```go
req := &knock.TriggerWorkflowRequest{
Workflow: "test",
Data: map[string]interface{}{
"life": "found a way",
"dinosaurs": "loose",
},
}
req.AddRecipientByID("tim")
workflow, _ := client.Workflows.Trigger(ctx, req, nil)
fmt.Printf("workflow: %+v\n", workflow)
```
Trigger with inline-identified recipient:
```go
workflow, _ := client.Workflows.Trigger(ctx, &knock.TriggerWorkflowRequest{
req := &knock.TriggerWorkflowRequest{
Workflow: "test",
Recipients: []string{"tim", "lex"},
Data: map[string]interface{}{
"life": "found a way",
"dinosaurs": "loose",
},
}
req.AddRecipientByEntity(map[string]interface{}{
"id": "dnedry",
"name": "Dennis",
"email": "[email protected]",
})
workflow, _ := client.Workflows.Trigger(ctx, req, nil)
fmt.Printf("workflow: %+v\n", workflow)
```
Trigger for multiple recipients and an object
```go
req := &knock.TriggerWorkflowRequest{
Workflow: "test",
Data: map[string]interface{}{
"life": "found a way",
"dinosaurs": "loose",
},
}

for _, r := range []string{"tim", "hammond"} {
req.AddRecipientByID(r)
}

req.AddRecipientByEntity(map[string]interface{}{
"id": "group-a",
"collection": "groups",
})
workflow, _ := client.Workflows.Trigger(ctx, req, nil)
fmt.Printf("workflow: %+v\n", workflow)
```
Trigger with idempotency key
```go
req := &knock.TriggerWorkflowRequest{
Workflow: "test",
Data: map[string]interface{}{
"life": "found a way",
"dinosaurs": "loose",
},
}
req.AddRecipientByID("tim")
workflow, _ := client.Workflows.Trigger(ctx, req, &knock.MethodOptions{
IdempotencyKey: "an-idempotency-key",
})
fmt.Printf("workflow: %+v\n", workflow)
```
Expand Down

0 comments on commit 8cf3a4a

Please sign in to comment.