Intents from postgress

To bring data’s from postgress to drop-down or any other custom components we use actions and pass it as a a payload. How can we retrieve intents from postgress database or store intents in our postgress database instead of storing it inside the bot ?

Hey @pry181192!

I understand that you would like to retrieve intents from the Botpress database.
You can achieve this using the ghost module from the Botpress SDK.

Here is an example action that will fetch and read intents from the Botpress database:

function action(bp: typeof sdk, event: sdk.IO.IncomingEvent, args: any, { user, temp, session } = event.state) {
  /** Your code starts below */

  /**
   * Reads intents for a given bot
   */
  const myAction = async () => {
    // We list all intent files
    const intentFileNames = await bp.ghost.forBot(event.botId).directoryListing('intents', '*.json')

    // We read each intent file individually
    intentFileNames.forEach(async intentFileName => {
      const intent = await bp.ghost.forBot(event.botId).readFileAsObject('intents', intentFileName)
      console.log(JSON.stringify(intent))

      // Do what you want with the intents here
    })
  }

  return myAction()

  /** Your code ends here */
}

Hope this helps!