Overview

The Freshworks app development platform includes a serverless environment to enable you to create apps that run in response to events such as Freshteam product, app setup, and external events. Serverless computing involves servers, but they are abstracted away from developers.

To use this feature, all you need to do is configure an event listener and the callback method. When the event occurs, the callback method is executed on a server.

Use Cases
Data Synchronization

Events, such as employee create and update, can be used to synchronize data across multiple products. For example, every time an employee is created or updated in your CRM, the same employee can be created or updated in your Freshteam account in real time.

Alerts and Notifications

This feature can also be used to apply custom logic to alerts and notifications. You can receive notifications through the desired channel (email, chat, SMS) when app or external events occur.

Server Method Invocation

The server method invocation allows code in server.js to be executed in response to front-end events. This feature enables you to use node libraries (that only run on the backend) or hide sensitive information.

Note:
1. The serverless component of the app is executed in sandbox mode where some methods, such as setTimeout and setInterval, cannot be used.
2. The app must complete its execution within 20 seconds or it will timeout.

Create

To create a new serverless app, run the following command. $ fdk create --products freshteam --template your_first_serverless_app The current directory should be empty.

Output
A new app is successfully created based on the your_first_serverless_app template with the following files.

1
2
3
4
5
6
7
8
9
10
11
12
13
├── README.md ├── config │   ├── iparam_test_data.json │   └── iparams.json ├── manifest.json └── server ├── lib │   └── handle-response.js ├── server.js └── test_data └──onEmployeeCreate.json 4 directories, 7 files
EXPAND ↓

Folder/File Description
README.md Developers can outline additional instructions or specifications here.
server/ Contains files and folders related to the serverless component of the app. JS files in this folder must follow the ES6 standard.
server/lib Contains an external library with methods that can be used in server.js. require("./lib/handle-response"); Here, handle-response is a lib file in the project-folder/server/lib/ directory.
server/server.js Contains event registration and callback methods.
server/test_data Includes files that contain a sample payload for each event which will be used during local testing.
config/ Contains installation parameters files.
config/iparams.json Contains all the parameters that users need to specify/set when they install the app. For more information on installation parameters and related APIs, see Installation Parameters.
config/iparam_test_data.json Developers can specify parameter values here to test the app in their local setup.
manifest.json Contains details such as the platform version the app uses, product to which the app belongs, event declarations for the app, the Node.js and FDK versions used to build, test, validate, and pack the app, and npm packages that the app uses (dependencies).
Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{ "platform-version": "2.2", "product": { "freshteam": { "events": { "<eventName>": { "handler": "<eventCallbackMethod>" }, "<eventName>": { "handler": "<eventCallbackMethod>" } } } }, "engines": { "node": "12.22.6", "fdk": "7.0.0" }, "whitelisted-domains": [ "https://www.google.com" ] }
EXPAND ↓

For product events, <eventName> is the appropriate product event name. For app setup events, <eventName> is onAppInstall or onAppUninstall. For external events, <eventName> is onExternalEvent. For scheduled events, <eventName> is onScheduledEvent.

Dependencies

These are npm packages that can be used in the server.js file and server/lib folder files as per your requirement. For example, you can use the utility methods in the underscore package or easily make HTTP calls with the request package.

Note:
1. If you are using Windows, see the prerequisites section to ensure that your computer is set up correctly.
2. All popular npm packages (at least 50 downloads) are supported.

To use npm packages, follow these steps.

  1. List the packages in the manifest file with their corresponding versions as shown.
  2. manifest.json Copied Copy
    1
    2
    3
    "dependencies": { "underscore": "1.8.3" },
  3. You can now load the dependencies by including the require() method in the server.js file. Use this method in the first call and not inside functions.
  4. Copied Copy
    1
    2
    var _ = require("underscore"); _.first([5, 4, 3, 2, 1]);

    Here, underscore is the package that is loaded when this method is invoked from server.js.

    Local Libraries

    You can use local libraries which contain helper methods in your server.js file to make your code modular and maintainable. You can load the local library from the server/lib directory by using the require() method in the server.js file.

    server.js Copied Copy
    1
    var handler = require("./lib/handle-response");

    Here, handle-response is a library file in the server/lib directory.

    Note: The FDK’s testing framework (beta) enables you to create automated unit tests for serverless apps. For information on how to write and run tests, see the Testing Framework documentation.

Sample Apps
  • Your First Serverless App - Prints a "Hello {requester name}" message in the terminal window when a new ticket is created.
  • Serverless Request App - Sends an API request to HTTPbin.org and prints the response in the terminal window when a new ticket is created.
  • JIRA External Events App - Uses external events to create an outbound email ticket in Freshdesk when an issue of type “bug” is created in JIRA.
  • Asana Serverless+OAuth App - Sends serverless requests using an OAuth token to create an Asana task for every Freshdesk ticket.
  • Ticket Merger - Merges tickets created by the same requester within a configurable time window.
Test the App
Notes:
  • To test a serverless app, use the latest version of Chrome.

  • As testing is only a simulation of events, actual data or record associated with the event is not created in the back-end. To create actual data and then test your event, publish your app as a custom app and test the events manually.

  • Ensure that the JSON files that contain the sample payloads to test events, are available at <app's root directory>/server/test_data.

To simulate an event and test your app:

  1. From the command line, navigate to the directory that contains the app related files and run the following command.$ fdk run

  2. In the address bar of the browser, enter https://localhost:10001/web/test. A dialog box is displayed.

  3. Click Select an event. The list of all events configured in the server.js file is displayed.

    Note: To test app setup events, select onAppInstall or onAppUninstall. To test external events, select onExternalEvent. To test scheduled events, select onScheduledEvent. To test a product event, select the corresponding product event’s name. To test the default serverless app created based on the your_first_serverless_app template, select onEmployeeCreate.
  4. Select an event. The corresponding payload is displayed. To test a different scenario other than the default, edit the payload.

  5. Click Simulate. If the event is successfully simulated, the Simulate button changes to a Success button. If the event simulation fails because of invalid payload data, the Simulate button changes to a Failed button. Modify the payload appropriately and click Simulate.