-
Couldn't load subscription status.
- Fork 111
Docs for content page and CRUD operations for context #983
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
8d75fc6
Docs for content page and CRUD operations for context
Aviatorscode2 8e14aa2
Docs for context
Aviatorscode2 937af0e
change page description
Aviatorscode2 8e5201d
Update content/docs/platform/workflow/contexts.mdx
Aviatorscode2 6b0a85a
Update content/docs/platform/workflow/contexts.mdx
Aviatorscode2 50e4d96
Update content/docs/platform/workflow/contexts.mdx
Aviatorscode2 b3cec4c
Update content/docs/platform/workflow/contexts.mdx
Aviatorscode2 8defd4b
Update content/docs/platform/workflow/contexts.mdx
Aviatorscode2 3ffe7ac
Update based on feedback
Aviatorscode2 6fb394e
Update context based on Adam's feedback
Aviatorscode2 6a609bf
Add new update
Aviatorscode2 7ddb7f7
Update content/docs/platform/workflow/contexts.mdx
Aviatorscode2 fb7392f
Update content/docs/platform/workflow/contexts.mdx
Aviatorscode2 a6ec1aa
Update content/docs/platform/workflow/contexts.mdx
Aviatorscode2 82ca9c0
Content for the context page in the workflow section
Aviatorscode2 e4f3589
Docs for the inbox with context page
Aviatorscode2 74b5e91
Update the JS and React SDK guide
Aviatorscode2 e6538dc
Update content/docs/platform/workflow/contexts/index.mdx
Aviatorscode2 a92cebf
Update content/docs/platform/inbox/configuration/inbox-with-context.mdx
Aviatorscode2 5949cd6
Update content/docs/platform/workflow/contexts/manage-contexts.mdx
Aviatorscode2 0dc510b
Fixed code errors
Aviatorscode2 7347e70
Merge branch 'MRK-1074' of https://github.com/novuhq/docs into MRK-1074
Aviatorscode2 5f64a99
Update docs for workflow trigger and Inbox to not upsert context but …
Aviatorscode2 db5e4a1
Add contexts image
Aviatorscode2 f6705f2
Update code block
Aviatorscode2 5634e12
fix: PR suggestions and issues
jainpawan21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,257 @@ | ||
| --- | ||
| pageTitle: 'Contexts' | ||
| title: 'Contexts' | ||
| description: 'Learn how to create and manage Contexts to reuse metadata across your notification workflows.' | ||
| icon: 'Package' | ||
| --- | ||
|
|
||
| Contexts are flexible, user-defined data objects that help you organize and personalize your notifications. They let you attach metadata (such as tenant, region, or app details) and enable contextual behavior to workflows, notifications, and other entities across Novu. | ||
|
|
||
| In simple terms, a Context acts like an extended version of the payload. While the payload exists only for the duration of a single workflow execution, Contexts are persistent and can be reused across multiple workflows or API calls. This makes them ideal for multi-tenant environments, dynamic branding, and use cases where notifications depend on shared or reusable data. | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <Callout type='warn'>You can pass a maximum of 5 contexts per workflow trigger and the serialized `data` object for each context is limited to 64KB.</Callout> | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## How Context works | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Without Context, you might have to create two different subscribers or use workarounds with subscriber ID prefixes to differentiate the notifications. | ||
|
|
||
| ```javascript | ||
| // Problem: How does Novu know which app is sending the notification? | ||
|
|
||
| // Notion Email notification | ||
| await novu.trigger('new-email-received', { | ||
| to: '[email protected]', | ||
| payload: { title: 'You have 1 new email' } | ||
| }); | ||
|
|
||
| // Notion Calendar notification | ||
| await novu.trigger('new-calendar-event', { | ||
| to: '[email protected]', | ||
| payload: { title: 'You have a new meeting invite' } | ||
| }); | ||
| ``` | ||
|
|
||
| With Context, you can provide this metadata directly in the trigger. This allows you to use a single workflow and subscriber entity, while dynamically changing content or logic based on the context. | ||
|
|
||
| ```javascript | ||
| // Solution: Pass an 'app' context to differentiate triggers. | ||
|
|
||
| // Notion Email notification | ||
| await novu.trigger('new-email-received', { | ||
| to: '[email protected]', | ||
| payload: { title: 'You have 1 new email' }, | ||
| context: { | ||
| app: 'notion-email', | ||
| branding: { | ||
| logo: "url_for_email_logo.png" | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| // Notion Calendar notification | ||
| await novu.trigger('new-calendar-event', { | ||
| to: '[email protected]', | ||
| payload: { title: 'You have a new meeting invite' }, | ||
| context: { | ||
| app: 'notion-calendar', | ||
| branding: { | ||
| logo: "url_for_calendar_logo.png" | ||
| } | ||
| } | ||
| }); | ||
| ``` | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Here are some ways context can be used: | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - 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. | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Shared Chat Credentials: For chat providers like Slack or MS Teams, store workspace-level credentials (e.g., 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. | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - 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. | ||
| - 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. | ||
|
|
||
| ## How to use Contexts | ||
|
|
||
| Once a context is created, you can access its properties anywhere variables are supported, such as in template editors or condition steps. | ||
|
|
||
| 1. Accessing Context data in templates | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| If a context with this data is created: | ||
|
|
||
| ```json | ||
| context: { | ||
| tenant: { | ||
| id: 'acme-corp', | ||
| data: { | ||
| name: 'Acme Corporation', | ||
| plan: 'enterprise' | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| You can access the `name` and `plan` in your in-app email, SMS, or push template like this: | ||
|
|
||
| ```html | ||
| <p>Welcome, new user from {{context.tenant.data.name}}!</p> | ||
| <p>Your account is on the {{context.tenant.data.plan}} plan.</p> | ||
| ``` | ||
| Or | ||
|
|
||
| ```text | ||
| Welcome, new user from {{context.tenant.data.name}}! | ||
| Your account is on the {{context.tenant.data.plan}} plan. | ||
| ``` | ||
|
|
||
| 2. Using Context in Conditions | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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`. | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|  | ||
|
|
||
| ## Managing Context | ||
|
|
||
| Novu provides two wasy to manage contexts, either through the Novu dashboard or using the API. | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Create Context | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
|
|
||
| #### Dashboard | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Use the dashboard to manually define contexts that represent key business entities. | ||
|
|
||
| 1. Log in to the Novu dashboard | ||
| 2. Click **Contexts** on the sidebar. | ||
| 3. Click **Create context**. | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 4. Fill in the following fields: | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - **Identifier**: A unique identifier within that type (for example, acme-corp). | ||
| - **Context type**: A category such as tenant, app, or region. | ||
| - **Custom data (JSON)**: An optional JSON object that contains metadata, such as branding, plan, or region details. | ||
| 5. Click **Create context** to save the context. | ||
|
|
||
| #### API | ||
|
|
||
| Novu provides an API to create a context. If a context with the same `type:id` combination already exists, the request will fail. | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| POST /v2/contexts | ||
| { | ||
| "type": "tenant", | ||
| "id": "acme-corp", | ||
| "data": { | ||
| "name": "Acme Corporation", | ||
| "plan": "enterprise" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| #### Just-in-Time | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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, Novu automatically creates it before running the workflow. | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ``` | ||
| await novu.trigger('welcome-email', { | ||
| to: '[email protected]', | ||
| payload: { userName: 'John' }, | ||
| context: { | ||
| tenant: 'acme-corp', // Created automatically if it doesn’t exist | ||
| app: 'jira' | ||
| } | ||
| }); | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ### Update a Context | ||
|
|
||
| You can update a context’s data payload at any time. The context `type` and `id` remain immutable. | ||
|
|
||
| #### Dashboard | ||
|
|
||
| 1. Log in to the Novu dashboard. | ||
| 2. Click **Contexts** on the sidebar. | ||
| 3. Click on the context you wish to edit, frrom the context list on the Context page. | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 4. Modify its data object in the UI. | ||
| 5. Click **Save changes**. | ||
|
|
||
| #### API | ||
|
|
||
| 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. | ||
|
|
||
| ```bash | ||
| PATCH /v2/contexts/tenant/acme-corp | ||
| { | ||
| "data": { | ||
| "plan": "premium", | ||
| "region": "us-east" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Retrieve a single Context | ||
|
|
||
| You can retrieve a context to verify its data, confirm its creation, or inspect the metadata it holds. | ||
|
|
||
| #### Dashboard | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 1. Log in to the Novu dashboard | ||
| 2. Click **Contexts** on the sidebar to view the list of all existing contexts. | ||
| 3. Click any context entry to see its details. | ||
|
|
||
| #### API | ||
|
|
||
| Novu provides an API to retrieve a single, specific context by providing its `type` and `id` in the URL. | ||
|
|
||
| ``` | ||
| GET /v2/contexts/:type/:id | ||
| ``` | ||
|
|
||
| Here is an example: | ||
| ``` | ||
| GET /v2/contexts/tenant/acme-corp | ||
| ``` | ||
|
|
||
| ### List or Search Contexts | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| You can list all contexts in your environment or search for specific ones by context type or ID. | ||
|
|
||
| #### Dashboard | ||
|
|
||
| 1. Log in to the Novu dashboard | ||
| 2. Click **Contexts** on the sidebar to view all contexts. | ||
| 3. Use the search bar to filter by context type or ID. | ||
Aviatorscode2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### API | ||
|
|
||
| Novu provides an API that lists or searches available contexts. Use pagination and search parameters to retrieve subsets efficiently. | ||
|
|
||
| ``` | ||
| GET /v2/contexts | ||
| GET /v2/contexts?search=acme | ||
| ``` | ||
|
|
||
| ### Delete a Context | ||
|
|
||
| Delete a context if it’s no longer needed. This action permanently removes the context from your Novu environment. | ||
|
|
||
| <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> | ||
|
|
||
| #### Dashboard | ||
|
|
||
| 1. Log in to the Novu dashboard. | ||
| 2. Click **Contexts** on the sidebar. | ||
| 3. Click on the **...** icon on the row of the context you want to remove. | ||
| 4. Click **Delete context**, a menu will appear. | ||
| 5. Click **Delete context**. | ||
|
|
||
| #### API | ||
|
|
||
| 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. | ||
|
|
||
| ``` | ||
| DELETE /v2/contexts/:type/:id | ||
| ``` | ||
|
|
||
| Here is an example: | ||
|
|
||
| ``` | ||
| DELETE /v2/contexts/tenant/acme-corp | ||
| ``` | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.