Skip to main content

Context

Some widgets only make sense in a particular context — for example, a contact-details widget needs a contactId in the URL to have anything to show. Context rules let a widget declare which URL query (search) params it depends on, and the platform uses them to decide when the widget is offered in the Composer's Micro App Library. These params can be required or optional depending on the rule type.

Configuring context

Context is configured in widget-config.json, in the contextRules object under widgetDetails:

{
"widgetDetails": {
"contextRules": {
"type": "dynamic",
"keys": ["contactId", "branchId"]
}
}
}

type selects the matching behavior; keys lists the query params (or patterns) the widget cares about.

Rule types

dynamic

The widget appears if any of the listed params are present — or if none of them are.

{
"contextRules": {
"type": "dynamic",
"keys": ["contactId", "branchId"]
}
}

Appears in the Composer menu when the URL is /dashboard?contactId=…, /dashboard?branchId=…, or a plain /dashboard with none of them.

strict

The widget appears only if all listed params are present.

{
"contextRules": {
"type": "strict",
"keys": ["contactId"]
}
}

Appears only when the URL contains /dashboard?contactId=….

none

The default. The widget doesn't depend on search params and is always available.

{
"contextRules": {
"type": "none"
}
}

Regular expressions

For broader matching, a key can be a regular expression instead of an exact param name:

{
"contextRules": {
"type": "strict",
"keys": ["/^phone/i"]
}
}

Matches /dashboard?phoneNumber=…, /dashboard?phoneNum=…, /dashboard?phoneUser=…, and any other param starting with "phone" (case-insensitive).