-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kno-5952): improve readme trigger docs (#33)
- Loading branch information
Showing
1 changed file
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
``` | ||
|