App Setup Events

App Setup events let your app execute handlers when the app is being installed, uninstalled or updated.

In this tutorial, we will focus on onAppInstall and onAppUninstall events.

In platform version 3.0, when creating the app with fdk create and serverless-starter-template this creates a boilerplace code for onAppInstall and onAppUninstall events.

  • The exports will allow your code defined to be available in the scope of the platform.
  • exports is assigned with an object with events and handlers as it's properties.
  • The events key is associated with an array of objects where each object is an event Name associated with the callback name. In the above example, { event: 'onAppInstall', callback: 'onInstallHandler' } and { event: 'onAppUninstall', callback: 'onUninstallHandler' }
  • The function handler can be defined as desired. In the current case, we are simply logging payload. An argument passed to the parameter of the handler to let the handler have access to information it may need when the app installs and uninstalls respectively.
  • Finally invoke renderData() platform method that must be used at the end of the handler. This lets the app to either let the installation to proceed or halt to throw an error message if needed.

Now, let's run the app to understand the code and how it executes.

fdk run
Starting local testing server at http://*:10001/    
Append 'dev=true' to your current host URL to start testing    
     
e.g:     
  https://domain.freshdesk.com/a/tickets/1?dev=true

Quit the server with Control-C.

To simulate product, app setup, and external events, visit - http://localhost:10001/web/test

When Simulate button is clicked, the terminal running fdk would log the console.info message from the event handler when onAppInstall and onAppUninstall events are simulated.

Populating test data with events found in the app
onAppInstallHandler invoked with following data: 
 {
  timestamp: 1496400354326,
  event: 'onAppInstall',
  region: 'US',
  iparams: {},
  currentHost: {
    endpoint_urls: { freshdesk: 'https://devrel.freshdesk.com' },
    subscribed_modules: [ 'support_ticket' ]
  }
}