본문으로 건너뛰기

Environment

The sdk.env object provides contextual data about the execution environment of a server-side function in MonoChat. It contains key information such as the active tenant, public settings, user metadata, and optionally, session or flow context.

This data allows server-side logic to adapt dynamically based on who is executing the function, in which tenant, and under what flow or session context.


Properties​

PropertyTypeDescription
tenantobjectThe current tenant in which the function is executing.
customAppInstanceIdstringID of the app instance, if the function belongs to a custom app.
publicSettingsobjectPublic configuration settings shared across all tenants.
userobjectThe user (with default field selection) who triggered the function.
sessionobjectThe session object, if executed within a session context.
customFlowInstanceobjectThe current flow instance, if part of a flow execution.

💡 Some fields like session or customFlowInstance are only available if their IDs are included in the function payload.


Example​

CustomFunction(async function ({ sdk }, reject, resolve) {
const user = sdk.env.user
const tenant = sdk.env.tenant
const session = sdk.env.session

sdk.utils.logger.info({payload: {result: 'Triggered by:', user?.profile?.firstname}})
sdk.utils.logger.info({payload: {result: 'Tenant slug:', tenant.slug}})
sdk.utils.logger.info({payload: {result: 'Session ID:', session?._id}})

resolve()
})

Notes​

  • The environment is prepared asynchronously before your function runs.
  • Only selected fields of the user document are exposed (for security and performance).
  • If sessionId or customFlowInstanceId is included in the payload, they are resolved and included in sdk.env.