Surface Context Reference
When your app opens, Hootsuite sends data about the surface it is running in. This data arrives in the context field of appReadyResponse (and of contextUpdateResponse, if your app asks for it with requestContextUpdate()) and is available as appContext from useHootsuite().
All context fields are optional. Always handle a missing field, ignore fields you do not recognize, and narrow the type with an in check before you read a surface-specific field:
const { appContext } = useHootsuite();
const conversationId =
appContext && 'conversationId' in appContext ? appContext.conversationId : undefined;
The types below are defined in src/context/AppConnector.ts. If your app supports only one surface, you can narrow the types in src/context/AppContext.tsx.
Surfaces
The EmbeddedAppsSurfaceType enum lists the surface values the template knows about:
| Value | Context type |
|---|---|
planner (Perch, the Planner) | PlannerAppContext |
inbox (Nest, the Inbox) | InboxAppContext |
analytics* | AnalyticsAppContext |
composer* | ComposerAppContext |
amplify* | AmplifyAppContext |
* Not yet enabled for Embedded apps. These values exist in the template, but you cannot select these surfaces yet.
Hootsuite does not send the surface as a URL parameter, and useHootsuite() does not expose it. Detect the surface from the fields of appContext, for example by checking for selectedDate (Perch) or conversationId (Nest).
Perch
type PlannerAppContext = {
selectedDate?: string;
viewType?: string;
filters?: Record<string, unknown>[];
};
| Field | Type | Description |
|---|---|---|
selectedDate | string | The anchor date of the period the user is looking at, formatted YYYY-MM-DD. |
viewType | string | The current Perch view. See View types. |
filters | Filter[] | The filters applied in Perch. See Filters. |
selectedDate is an anchor date
Users cannot select a single day in Perch. selectedDate is a date inside the week or month the user is looking at, not a selected day. Which one depends on viewType.
It is a calendar date in the user's time zone, with no time and no offset. Treat it as a plain date: do not convert it to UTC or to another time zone, because that can move it to the previous or next day.
View types
viewType tells you which Perch view the user had open. These are the values you can handle:
| Value | View |
|---|---|
WEEK_CONDENSED, WEEK_EXPANDED | Week |
MONTH_COUNT_BY_POST_TYPE, MONTH_COUNT_BY_SN | Month |
LIST_VIEW, DRAFTS | List and drafts |
CONTENT, DM_AUTOMATIONS, CANVAS | Other views |
Perch can also send the values of its approval views, which start with APPROVALS. Treat any value you do not recognize as an unknown view. For the week and month views, selectedDate is inside the visible period. Do not assume it describes a period in the other views.
Where the week starts
Users choose in Perch whether their week starts on Sunday or Monday. Hootsuite does not send that choice to your app, so you cannot know which week the user sees. If your data depends on the exact week, let your users choose the first day of the week in your app, or show data for a range that does not depend on it.
Resolve the visible range
Derive the week or the month from selectedDate and viewType. This example takes the first day of the week as a parameter. Sunday (0) is the default and Monday is 1:
type CalendarDateRange = { startDate: string; endDate: string };
const toCalendarDate = (date: Date) => date.toISOString().slice(0, 10);
export function resolvePlannerRange(
selectedDate?: string,
viewType?: string,
weekStartsOn: 0 | 1 = 0
): CalendarDateRange | undefined {
if (!selectedDate || !/^\d{4}-\d{2}-\d{2}$/.test(selectedDate)) {
return undefined;
}
const anchor = new Date(`${selectedDate}T00:00:00Z`);
if (viewType?.startsWith('MONTH')) {
const start = new Date(Date.UTC(anchor.getUTCFullYear(), anchor.getUTCMonth(), 1));
const end = new Date(Date.UTC(anchor.getUTCFullYear(), anchor.getUTCMonth() + 1, 0));
return { startDate: toCalendarDate(start), endDate: toCalendarDate(end) };
}
if (viewType?.startsWith('WEEK')) {
const start = new Date(anchor);
start.setUTCDate(anchor.getUTCDate() - ((anchor.getUTCDay() - weekStartsOn + 7) % 7));
const end = new Date(start);
end.setUTCDate(start.getUTCDate() + 6);
return { startDate: toCalendarDate(start), endDate: toCalendarDate(end) };
}
return undefined;
}
The Date calls use UTC only to do calendar arithmetic on a plain date, so the result does not shift with the user's time zone.
If the function returns undefined, show a message such as "Open the week or month view in Perch to see its tasks" instead of an empty list.
Filters
filters is a list of the filters the user applied in Perch. The template types each item as Record<string, unknown>, so narrow it to this shape before you read it:
type Filter = {
type: string;
value: { type: string; value: string | number }[];
};
For example:
[
{
"type": "POST_STATUS",
"value": [
{ "type": "POST", "value": "DRAFTS" },
{ "type": "POST", "value": "SCHEDULED" }
]
},
{
"type": "SOCIAL_ACCOUNTS",
"value": [{ "type": "SOCIAL_PROFILE", "value": 123456 }]
}
]
The type of a filter is one of these:
| Filter type | Filters by | type of each value |
|---|---|---|
POST_STATUS | Post status | POST or AD |
SOCIAL_ACCOUNTS | Social accounts | SOCIAL_PROFILE |
CAMPAIGNS | Campaigns | CAMPAIGN |
TAGS | Tags | TAGS |
AUTHOR | Post author | AUTHOR |
APPROVER | Approver | APPROVER |
For POST_STATUS values of type POST, the values are DRAFTS, PENDING_APPROVAL, EXPIRED_APPROVAL, REJECTED_APPROVAL, SCHEDULED, NATIVE, SENT, SEND_FAILED_PERMANENTLY, and DISCONNECTED. Values of type AD are SCHEDULED, ACTIVE, PAUSED, COMPLETED, and WITH_ISSUES.
The list is empty when the user has no filters applied. Ignore filter types and values you do not recognize.
Context changes
Interacting with the Perch calendar currently closes the apps drawer. When the user reopens your app, it receives the context of the week they navigated to. Read the context on load and do not assume that the drawer stays open across navigation.
Nest
type InboxAppContext = {
conversationId?: string;
contactAttributes?: ContactAttribute[];
contactAttributeDefinitions?: ContactAttributeDefinition[];
};
| Field | Type | Description |
|---|---|---|
conversationId | string | The ID of the open conversation. It is missing when no conversation is selected. |
contactAttributes | ContactAttribute[] | The contact's attributes. See Contact attributes. |
contactAttributeDefinitions | ContactAttributeDefinition[] | The definitions of the attributes. See Attribute definitions. |
The template defines ContactAttribute and ContactAttributeDefinition in src/context/AppConnector.ts with the fields described below. Hootsuite can send more fields than these.
If your app needs a conversation, check conversationId and show a message such as "Open a conversation to see its details" when it is missing.
Contact attributes
Each item in contactAttributes is one piece of data about the contact:
| Field | Type | Description |
|---|---|---|
name | string | The name of the attribute, for example "Phone". |
alias | string | An alias for the attribute. It is optional: an attribute may not have one. |
value | string | The value, always as text. |
definitionId | string | The id of the attribute's definition. |
optionId | string | The option the user selected, when the attribute is a dropdown. It is optional. |
source | string | Where the value comes from: CRM, USER, MEDIUM, or SPARK. It is optional. |
Each item has other fields, such as id and version, that you normally do not need. Read name to label an attribute, and use alias only when it is present.
{
"name": "Phone",
"alias": "phone",
"value": "+1 555 0100",
"definitionId": "def_123",
"source": "CRM"
}
Attribute definitions
Each item in contactAttributeDefinitions describes an attribute that can exist for a contact, whether or not the current contact has a value for it:
| Field | Type | Description |
|---|---|---|
id | string | The ID of the definition. A contact attribute's definitionId matches it. |
name | string | The display name of the attribute. |
identifier | string | A stable identifier for the attribute. |
type | string | STANDARD, CUSTOM, or NETWORK. |
entryMethod | string | FREEFORM when users type the value, or DROPDOWN when they choose from a list. |
freeForm | object | For FREEFORM attributes: validatorType (EMAIL, PHONENUMBER, URL, NUMBER, DATE, BOOLEAN, or NONE) and charLimit. |
dropdown | object | For DROPDOWN attributes: options, a list of { id, value, displayName }, where displayName is optional. A contact attribute's optionId matches an option's id. |
enabled | boolean | Whether the attribute is in use. |
The lists can be empty. If Hootsuite cannot load the attributes, it sends empty lists, and it omits them when it has no conversation to read them from. Always handle a missing or empty list.