External Events

The idea behind external events is to have the app invoke a handler whenever something desired happens in the 3rd party systems. For example, if a payment fails with a payment provider, we can have a ticket created automatically in Freshdesk.

Webhooks are URL endpoints that can help us solve these problems. The 3rd party payments provider performs the payments with a mechanism that whenever the payment fails it makes a HTTP request with POST method to an webhook endpoint which intern invokes the Handler function.

On Freshworks Developer Platform, you will need to

  • Generate a Webhook URL endpoint by invoking a generateTargetUrl() function.
  • Send the URL to the 3rd party system to have it remember the Webhook URL. Usually, apps perform this action onAppInstall
  • App will wait to invoke onExternalEventHandler until the 3rd party notifies the app. That's by sending an HTTP POST request to the Webhook URL.
server/server.js file
  onInstallHandler: async function (payload) {
    try {
      const webhook = await generateTargetUrl();
      console.log(webhook)
    }catch(e) {
      console.error(e)
    }
  },
  onExternalEventHandler: async function (payload) {
    console.log("Webhook payload",payload)
  }

And in the next section, we will build the webhook capability for our app using App Setup event and External event.