Skip to content

Commit 6fb394e

Browse files
committed
Update context based on Adam's feedback
1 parent 3ffe7ac commit 6fb394e

File tree

3 files changed

+50
-25
lines changed

3 files changed

+50
-25
lines changed

content/docs/platform/workflow/contexts.mdx

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In simple terms, a context acts like an extended version of the payload. While t
1111

1212
<Callout type='warn'>You can pass a maximum of five contexts per workflow trigger and the serialized `data` object for each context is limited to 64KB.</Callout>
1313

14-
## How Context works
14+
## How context works
1515

1616
Imagine you have a single subscriber entity, `[email protected]`, who uses two different applications you offer: "Notion Email" and "Notion Calendar". You want to send notifications specific to each application.
1717

@@ -65,12 +65,12 @@ await novu.trigger('new-calendar-event', {
6565

6666
Here are some ways context can be used:
6767

68-
- **Multi-tenancy and App Routing**: Use a tenant or app context to dynamically alter notification content, branding, or logic for different customers or applications from a single workflow.
69-
- **Shared Chat Credentials**: For chat providers like Slack or MS Teams, store workspace-level credentials (for example, a bot token) in a context. This allows multiple subscribers within that workspace to receive notifications without each subscriber needing to store the shared token.
70-
- **A/B Testing**: Pass a campaign identifier in a context (for example, campaign: 'new-welcome-email-v2'). Use this in a condition step to split users into different notification paths and measure which performs better.
71-
- **Data Residency and Compliance**: Use a region context to tag notifications with their origin. This can help in applying data retention policies or filtering data for compliance audits.
68+
- **Multi-tenancy and app routing**: Use a tenant or app context to dynamically alter notification content, branding, or logic for different customers or applications from a single workflow.
69+
- **Shared chat credentials**: For chat providers like Slack or MS Teams, store workspace-level credentials (for example, a bot token) in a context. This allows multiple subscribers within that workspace to receive notifications without each subscriber needing to store the shared token.
70+
- **A/B testing**: Pass a campaign identifier in a context (for example, campaign: 'new-welcome-email-v2'). Use this in a condition step to split users into different notification paths and measure which performs better.
71+
- **Data residency and compliance**: Use a region context to tag notifications with their origin. This can help in applying data retention policies or filtering data for compliance audits.
7272

73-
## How to use Contexts
73+
## How to use contexts
7474

7575
Once a context is created, you can access its properties anywhere variables are supported, such as in template editors or condition steps.
7676

@@ -103,20 +103,45 @@ Once a context is created, you can access its properties anywhere variables are
103103
Your account is on the {{context.tenant.data.plan}} plan.
104104
```
105105

106-
* Using Context in Conditions
106+
* Using context in step conditions
107107

108108
You can use context variables in the **Step conditions** tab of a workflow step to add conditional logic to your notifications. For example, only send a "Feature X is now enabled" email if `context.tenant.data.plan` is `enterprise`.
109109
![Context step conditions](/images/workflows/context-step-conditions.png)
110110

111-
## Managing Context
111+
## Viewing and debugging contexts
112+
113+
Once you start using contexts in your workflows, Novu provides full observability so you can monitor and debug your context usage after a workflow has been triggered.
114+
115+
### Searching for workflow runs
116+
117+
You can filter your workflow runs to find all executions associated with a specific context.
118+
119+
1. Navigate to the **Activity Feed** in your Novu dashboard.
120+
2. Select the **Workflow Runs** tab.
121+
3. In the search bar, click **Context** and enter the context `type` and `id` using the format `type:id`.
122+
123+
![Searching for workflow runs](/images/workflows/search-context-activityfeed.png)
124+
125+
### Verifying the resolved context
126+
127+
To confirm that Novu received and processed your context data correctly, you can inspect the API traces for a specific run.
128+
129+
1. From the **Activity Feed**, select the relevant workflow run from the list in the **Requests** tab.
130+
2. In the workflow run details, go to the **API Traces** tab.
131+
132+
Here, you will see the full context object that was resolved and attached to that specific workflow execution.
133+
134+
![Verifying the resolved context](/images/workflows/resolved-context.png)
135+
136+
## Manage context
112137

113138
Novu provides two ways to manage contexts, either through the Novu dashboard or using the API.
114139

115-
### Creating a Context
140+
### Create a Context
116141

117142
You can create a new context via Novu dashboard or API, when you want to register reusable metadata. After creation, this context becomes available to all workflows and templates within your environment.
118143

119-
#### Create a Context from the dashboard
144+
#### Create a context via dashboard
120145

121146
Use the dashboard to manually define contexts that represent key business entities.
122147

@@ -129,7 +154,7 @@ Use the dashboard to manually define contexts that represent key business entiti
129154
- **Custom data (JSON)**: An optional JSON object that contains metadata, such as branding, plan, or region details.
130155
5. Click **Create context** to save the context.
131156

132-
#### Create a Context using the API
157+
#### Create a context via API
133158

134159
Novu provides an API to create a context. If a context with the same `type:id` combination already exists, then the request will fail.
135160

@@ -145,7 +170,7 @@ POST /v2/contexts
145170
}
146171
```
147172

148-
#### Create a Context using the API (Just-in-time)
173+
#### Create a context via API (Just-in-time)
149174

150175
Contexts can also be created automatically when you trigger a workflow that includes a new context object. If the specified `type:id` doesn’t exist, then Novu automatically creates it before running the workflow.
151176

@@ -160,19 +185,19 @@ await novu.trigger('welcome-email', {
160185
});
161186
```
162187

163-
### Updating a Context
188+
### Update a context
164189

165190
You can update a context’s data payload at any time. The context `type` and `id` remain immutable.
166191

167-
#### Update a Context from the dashboard
192+
#### Update a context via dashboard
168193

169194
1. Log in to the Novu dashboard.
170195
2. Click **Contexts** on the sidebar.
171196
3. Click on the context you wish to edit from the context list on the Context page.
172197
4. Modify its data object in the UI.
173198
5. Click **Save changes**.
174199

175-
#### Update a Context using the API
200+
#### Update a context via API
176201

177202
Novu provides an API to update an existing context. The `data` object is replaced entirely during updates (not merged). Include all fields you want to retain.
178203

@@ -186,17 +211,17 @@ PATCH /v2/contexts/tenant/acme-corp
186211
}
187212
```
188213

189-
### Retrieving a single Context
214+
### Retrieve a single context
190215

191216
You can retrieve a context to verify its data, confirm its creation, or inspect the metadata it holds.
192217

193-
#### Retrieve a Context from the dashboard
218+
#### Retrieve a context via dashboard
194219

195220
1. Log in to the Novu dashboard
196221
2. Click **Contexts** on the sidebar to view the list of all existing contexts.
197222
3. Click any context entry to see its details.
198223

199-
#### Retrieve a Context using the API
224+
#### Retrieve a context via API
200225

201226
Novu provides an API to retrieve a single, specific context by providing its `type` and `id` in the URL.
202227

@@ -209,17 +234,17 @@ Here is an example:
209234
GET /v2/contexts/tenant/acme-corp
210235
```
211236

212-
### Listing or searching for Contexts
237+
### List or search for contexts
213238

214239
You can list all contexts in your environment or search for specific ones by context type or ID.
215240

216-
#### List or search Contexs from the dashboard
241+
#### List or search for contexs via dashboard
217242

218243
1. Log in to the Novu dashboard
219244
2. Click **Contexts** on the sidebar to view all contexts.
220245
3. Use the search bar to filter by context type or ID.
221246

222-
#### List or search Contexs using the API
247+
#### List or search for contexs via API
223248

224249
Novu provides an API that lists or searches available contexts. Use pagination and search parameters to retrieve subsets efficiently.
225250

@@ -228,21 +253,21 @@ GET /v2/contexts
228253
GET /v2/contexts?search=acme
229254
```
230255

231-
### Deleting a Context
256+
### Delete a context
232257

233258
Delete a context if it’s no longer needed. This action permanently removes the context from your Novu environment.
234259

235260
<Callout type='warn'>This action cannot be undone, so ensure the context is no longer required by any active or historical workflows you might need to analyze.</Callout>
236261

237-
#### Delete a Context from the dashboard
262+
#### Delete a context via dashboard
238263

239264
1. Log in to the Novu dashboard.
240265
2. Click **Contexts** on the sidebar.
241266
3. Click on the **...** icon on the row of the context you want to remove.
242267
4. Click **Delete context**, a menu will appear.
243268
5. Click **Delete context**.
244269

245-
#### Delete a Context using the API
270+
#### Delete a context via API
246271

247272
Novu provides an API that you can use to delete a context. Once deleted, the context will no longer be available for use in new workflow executions.
248273

@@ -254,4 +279,4 @@ Here is an example:
254279

255280
```
256281
DELETE /v2/contexts/tenant/acme-corp
257-
```
282+
```
521 KB
Loading
345 KB
Loading

0 commit comments

Comments
 (0)