| Developers Guide

| Developers Guide

  • Docs
  • API
  • Help
  • Blog

›Tutorials

Notes on Versions Released

  • Migrating & Updating
  • Updating to New Releases

Getting Started

  • Introduction
  • Installation
  • Quick Start

Main Concepts

  • Overview
  • Glossary
  • CMS
  • Dialog Engine
  • Actions & Hooks
  • Memory
  • Modules
  • NLU
  • Emulator

Advanced Guides

  • Debug
  • Configuration
  • Authentication Methods
  • Custom Module
  • Performances
  • Hosting
  • Version Control
  • Development Pipelines
  • Clustering

Channels

  • Website Embedding
  • Facebook Messenger
  • Telegram
  • Microsoft Teams
  • Converse API
  • Slack
  • Smooch (Sunshine Conversations)
  • FAQ

Tutorials

  • Deploying a cluster on Digital Ocean
  • How to act on an intent
  • Acting Proactively
  • Using Carousel Postback
  • How to use Slot Skill
  • How to use Call API Skill
  • Calling an API in a Custom Action
  • Shortlinks
  • Connecting your bot with your existing backend
  • Supported databases
  • Timeouts
  • Human in the loop
  • Jump To
  • Inter-bot Communication / Delegation
  • Contextual FAQ
  • Authenticate a user against a 3rd Party OAuth
  • Listening for file changes
  • Using a 3rd party NLU
  • Using the UiPath integration for Botpress

Pro Edition

  • About
  • Licensing
  • Configuring RBAC
  • Monitoring & Alerting
  • Bot Pipelines
  • Internationalization

Listening for file changes

You may find yourself having to write custom logic when a Botpress file has been changed in Botpress. For example, you could listen for changes to the QnA files to automatically launch a translation worker to translate the QnA to multiple languages.

The Botpress File System (Ghost) exposes a way to listen for file changes for that purpose. In this example we will watch for NLU changes inside any bot.

Example

Let's create a Hook inside the <data_dir>/global/hooks/after_bot_mount called listen_nlu.js and put the following code inside it:

const listener = bp.ghost.forBot(botId).onFileChanged(file => {
  if (
    file.toLowerCase().startsWith(`data/bots/${botId}/intents/`) ||
    file.toLowerCase().startsWith(`data/bots/${botId}/entities/`)
  ) {
    bp.logger.info('NLU Data has changed: ' + file)
  }
})

setTimeout(() => {
  // Example of how to stop listening after 1m
  listener.remove()
}, 60 * 1000)
← Authenticate a user against a 3rd Party OAuthUsing a 3rd party NLU →
| Developers Guide
Docs
Getting Started (or other categories)Guides (or other categories)API Reference (or other categories)
Community
User ShowcaseStack OverflowProject ChatTwitter
More
BlogGitHubStar
Facebook Open Source
Copyright © 2021 Botpress Inc.