Sanity App SDK
    Preparing search index...

    Function defineIntent

    • Creates a properly typed intent definition for registration with the backend.

      This utility function provides TypeScript support and validation for intent declarations. It is also used in the CLI if intents are declared as bare objects in an intents file.

      Parameters

      • intent: Intent

        The intent definition object

      Returns Intent

      The same intent object with proper typing

      // Specific filter for a document type
      const viewGeopointInMapApp = defineIntent({
      id: 'viewGeopointInMapApp',
      action: 'view',
      title: 'View a geopoint in the map app',
      description: 'This lets you view a geopoint in the map app',
      filters: [
      {
      projectId: 'travel-project',
      dataset: 'production',
      types: ['geopoint']
      }
      ]
      })

      export default viewGeopointInMapApp

      If your intent is asynchronous, resolve the promise before defining / returning the intent

      async function createAsyncIntent() {
      const currentProject = await asyncProjectFunction()
      const currentDataset = await asyncDatasetFunction()

      return defineIntent({
      id: 'dynamicIntent',
      action: 'view',
      title: 'Dynamic Intent',
      description: 'Intent with dynamically resolved values',
      filters: [
      {
      projectId: currentProject, // Resolved value
      dataset: currentDataset, // Resolved value
      types: ['document']
      }
      ]
      })
      }

      const intent = await createAsyncIntent()
      export default intent