Freshworks CLI

Freshworks Command-Line Interface (CLI) enables you to build, test, and package apps to publish them in Marketplace.

As soon as you install the CLI, type fdk to display the supported commands.

The following options are also avaliable.

  • For information about a specific command, run the following command. $ fdk COMMAND (-h | --help)
  • To obtain detailed logs, run the following command. $ NODE_DEBUG=fdk fdk COMMAND
Version update lifecycle

When you run the Freshworks CLI commands, if no version update check has run in the last 24 hours, the FDK:

  1. Checks whether a new FDK version is available.
  2. If a new version is available and if you are not on the latest version, displays an update prompt that enables you to move to the latest version.
  3. Keeps track of the update check time.

Option to skip update checks

To prevent the FDK from checking for version updates, you can use the --skip-update-check option, along with the CLI commands, as follows:

$ fdk <-u or --skip-update-check> <COMMAND> Examples
$ fdk --skip-update-check create $ fdk -u run As a result of using the --skip-update-check option, the update prompt is not displayed.
Create

The command creates an app in the specified directory, based on the default app template. If no directory is specified, the app is created in the current directory.

$ fdk create [--app-dir DIR] [--products PRODUCT]

Options Usage
--app-dir Specify the absolute or relative path to the project directory.
--products Specify the product for which the app is created. If not specified, you will be prompted to select a product.

Example 1
To create a Freshchat app in the current directory, run the following command. $ fdk create --products freshchat The current directory should be empty.

Output
A new Freshchat app is created from the your_first_app template with the following files.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<current_app_directory> ├── README.md ├── app │ ├── index.html │ ├── scripts │ │ └── app.js │ └── styles │ ├── images │ │ └── icon.svg │ └── style.css ├── config │ └── iparams.json └── manifest.json 5 directories, 7 files
EXPAND ↓

Example 2
Run any of the following commands to create default Freshchat sample app directories and files in the myfirstapp directory. $ fdk create --app-dir ./myfirstapp $ fdk create --app-dir /Users/user/myfirstapp The output will be the same as Example 1.

Generate

This command is used to generate app files with a specific template for an existing app that was created by using the create command.

  • After you create an app, run the following command. $ fdk generate The list of the following files is displayed.
    • oauth_config.json: Contains the configuration parameters, such as client_id, client_secret, authorize_url, token_url, and account/agent scope, required for OAuth-based authentication.
    • iparams.json: Contains the installation parameters, such as iparam name and type of iparam, whose values are set when the app is installed.
    • iparams.html: Contains the html code to build the Custom Installation page. You can enter the page title, select the product css to link, and choose to add jquery, fresh_client.js, and iparam.js and iparam.css.
    • server.js: Contains the event registration and callback methods. You need to enter the names of the events and callback functions.
    • manifest.json: Contains app information such as version, product, location, and so on. You need to select the product and app location.
  • Select a file and enter the appropriate parameter values. The corresponding file is generated based on the values.
Run

This command is used to start the local server in order to test your app.

$ fdk run [--app-dir DIR]

Options Short-hand notation Usage Description
--app-dir -d General syntax:
1
2
$fdk run -d <DIR> $fdk run –app-dir <DIR>
<DIR> is the directory path to the folder containing the app that is tested locally through the fdk run command.
Example: $ fdk run -d /user/myFirstApp
Specifies the directory path to the folder that contains the app that is tested locally.
--skip-validation -V General syntax:
1
2
$fdk run -V <Validation-type> $fdk run --skip-validation <Validation-type>
<Validation-type> is the type of validation check that is skipped.
Example: $ fdk run -V lint
Skips specific validation checks. The errors associated with the validation, if any, are not displayed when the app is tested locally.

Once you exit testing, the CLI will print a summary of how extensive your testing was. The following coverage summary shows an example of thorough testing.

1
2
3
4
5
6
======================= Coverage summary ======================== Statements : 98.18% ( 54/55 ) Branches : 100% ( 4/4 ) Functions : 84.62% ( 22/26 ) Lines : 98.18% ( 54/55 ) =================================================================

Note:
Each component in the coverage summary should be at least 80% for apps to be submitted for the App Review process.

Example 1
To run the command from the app project directory, type: $ fdk run

Output

Starting local testing server at http://*:10001/
Append "dev=true" to your Freshchat account URL to start testing
e.g. https://web.freshchat.com/a/1234/inbox/1/0/conversation/9876?dev=true
Quit the server with Control-C.

Example 2
To run the command from a different directory, type: $ fdk run --app-dir /Users/user/myfirstapp The output will be the same as Example 1.

Configurable parameter
$ [REQUEST_TIMEOUT=<timeout in milliseconds>] fdk run

Parameter Usage
REQUEST_TIMEOUT Specify the time in milliseconds after which a Request Method call times out during local testing.
Example: REQUEST_TIMEOUT=10000 fdk run Minimum value: 5000
Maximum value: 10000

Note: If you specify a REQUEST_TIMEOUT value that breaches the min or max limits, the timeout is defaulted to the min or max value and a warning message is displayed.

Validate

Note: Ensure to install or update to the latest FDK version.

This command validates whether the app code is error free. If there are errors in the code, corresponding violations are displayed after the command is run.

$ fdk validate [--app-dir DIR] [--fix]

Options Short-hand notation Usage Description
--app-dir -d General syntax:
1
2
$fdk validate -d <DIR> $fdk validate --app-dir <DIR>
<DIR> is the directory path to the folder containing the app files that are validated for errors.
Example: $ fdk validate -d /user/myFirstApp
Specifies the directory path to the folder that contains the app that is validated.
--fix -f General syntax:
1
2
$fdk validate -f $fdk validate –fix
Example: $ fdk validate -f -d /users/myFristApp
When validating an app, the option fixes all lint errors for which auto-fix support is available.
--skip-validation -V General syntax:
1
2
$fdk validate -V <Validation-type> $fdk validate --skip-validation <Validation-type>
<Validation-type> is the type of validation check that is skipped.
Example: $ fdk pack -V lint
Skips specific validation checks. The errors associated with the validation, if any, are not displayed when the app is validated

The latest FDK version requires Node.js 14 or later versions. If you run the fdk validate command to validate an app built using an earlier (major) Node.js version and if your current Node.js runtime environment is 14 or later, the FDK displays a warning message and a prompt asking whether you want to continue. If you continue with the validation, the FDK:

  1. Deletes the existing coverage folder. The folder contains the results of the fdk run command that is used to set up the local server and test an app.

  2. Deletes the node_modules folder. The folder contains the npm dependencies (specified in manifest.json) that are installed when the fdk run command is run.

  3. Includes or updates the engines attribute in manifest.json. The updated engines.node and engines.fdk values reflect the Node.js and FDK versions on which the app is validated.

After a successful validation, ensure to retest the app by using the fdk run command. The retesting generates the coverage folder and the coverage summary that is required to pack your app for submission.

If there is a minor Node.js version mismatch between the version used to build the app and the current Node.js runtime version, the FDK automatically updates manifest.json > engines.node to reflect the Node.js version on which the app is validated.

Pack

Note: Before packing, ensure to validate the app; resolve all Node.js version mismatch issues, if any.

The pack command creates an app package file that can be submitted for the app review process.

$ fdk pack [--app-dir DIR]

Options Short-hand notation Usage Description
--app-dir -d General syntax:
1
2
$fdk pack -d <DIR> $fdk pack --app-dir <DIR>
<DIR> is the directory path to the folder containing the app files that are packed for Marketplace review.
Example: $ fdk pack -d /user/myFirstApp
Specifies the directory path to the folder that contains the app that is packed.
--skip-validation -V General syntax:
1
2
$fdk pack -V <Validation-type> $fdk pack --skip-validation <Validation-type>
<Validation-type> is the type of validation check that is skipped.
Example: $ fdk pack -V lint
Skips specific validation checks. The errors associated with the validation, if any, are not displayed when the app is packed.

The command displays the Node.js and FDK versions that are used when packing the app.

After you run the pack command, a dist/<app_directory>.zip file is generated. To publish the app in Freshworks Marketplace, upload the generated file in the Freshchat Developer portal.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Sauls-Macbook-Pro:~ user$ tree myfirstapp/ myfirstapp/ ├── README.md ├── app │ ├── app.js │ ├── freshchat_logo.png │ ├── icon.svg │ ├── logo.png │ ├── style.css │ └── template.html ├── config │ ├── iparam_test_data.json │ └── iparams.json ├── dist │ └── myfirstapp.zip └── manifest.json 3 directories, 11 files
EXPAND ↓

Example 1
To pack the app files located in the app project directory, run the following command. $ fdk pack

Output

App packed successfully at /dist/<current_app_directory>.zip
Upload this file to the marketplace by following the instructions at https://developers.freshchat.com/v2/docs/freshchat-apps/

Example 2
To pack the app project files located in the myfirstapp directory, run the following command. $ fdk pack --app-dir /Users/user/myfirstapp

Output

App packed successfully at /dist/myfirstapp.zip
Upload this file to the marketplace by following the instructions at https://developers.freshchat.com/v2/docs/freshchat-apps/

Version

This command prints the installed and latest CLI versions. $ fdk version

Output

Installed: 6.8.0
Latest: 6.9.4
To install the latest version type "npm install https://dl.freshdev.io/cli/fdk.tgz -g"

Test

The FDK includes a testing framework (currently in beta) to help test serverless apps. This enables you to write and maintain unit tests as part of app files. The test command runs these unit tests. $ fdk test

For information on how to use the testing framework and the output of the test command, see the Testing Framework documentation.