Product events are events such as ticket creation, ticket updation, conversation creation, and so on, that occur in the product on which your app is deployed. You can enable product events to trigger your app, call a corresponding callback function, and execute the app logic.
To do this,
From your app’s root directory, navigate to the manifest.json file.
Subscribe to an event by configuring an event listener: Include the events attribute under modules.<module_name>, specifying the product-event's name and the corresponding callback methods as follows:
manifest.json"events": { "<productEventName>": { "handler": "<eventCallbackMethod>" } }When the event occurs, the corresponding event listener invokes the callback method and passes a standard payload to the method.
Navigate to the server.js file. In the exports block, enter the callback function definition as follows:
Sample server.jsexports = { // args is a JSON block containing the payload information // args["iparam"] will contain the installation parameter values //eventCallbackMethod is the call-back function name specified in manifest.json eventCallbackMethod: function(args) { console.log("Logging arguments from the event: " + JSON.stringify(payload)); }};
- The serverless component of the app is executed in a sandbox mode where some methods, such as setTimeout and setInterval, cannot be used.
- The default app execution timeout is 20 seconds. If the request timeout is increased to 20, 25, or 30 seconds, the app execution timeout is extended to 40 seconds.
When building a common module app, you must specify at least one other module in the app manifest. The other module(s) specified determine the product where the common module app is deployed. An app built for the common module can react to product-specific events associated with the other module(s) that are included in the app manifest.
To know more about these events,
- In the left navigation pane of this document, from the Module drop-down box, select the module that you intend to use along with the common module. The documentation corresponding to the selected module is displayed.
- From the left-navigation pane, navigate to the Serverless apps > Product events topic.
Payload attributes
When a product event occurs, an event-specific payload is passed to the callback method.
The payload is a JSON object with the following attributes.
- app_settingsobject
Information pertaining to the app settings as a JSON object of key-value pairs.
If your app does not use the app settings functionality, an empty JSON object is returned. - currentHostobject
A global app, with module-specific app logic, can be deployed on various Freshworks products.
currentHost contains information pertaining to the Freshworks product on which the app is currently running.- subscribed_modulesarray of strings
All modules that the app user has subscribed to and present in the app manifest.
- endpoint_urlsobject
Product name and account url (domain name) of the host where the app can access the product resources, specified as a key (product name) - value (account URL) pairs.
You can use the domain name to construct api calls that can access product resources. - product_typesobject
Information pertaining to the product where the app is currently running.
- freshservicestring
Name of the variant of the product.
Possible values:
- ITSM: For Freshservice and Freshservice for Business Teams products
- MSP: For Freshservice for MSPs product
- workspacesobject
Information pertaining to the workspace for which the app is installed. When you specify installation scope in your app manifest, this attribute will be retrieved as a part of the currentHost object in the payload.
To learn more about the workspace or client level installation, see Configure app installation scope.Note:In the manifest, along with the common module, you should include at least one of the service modules(service_ticket, service_change, service_asset, service_user) in order to specify the installation object for the app.
- freshserviceobject
Information pertaining to the product for which the workspace is available.
- idinteger
Identifier of the workspace or client for which the app is installed.
Note:This attribute is returned as a part of the currentHost payload at runtime and also in product events, external events, scheduled events, app setup events, and SMI payloads.
- dataobject
Event-specific data, specified as a JSON object of key:value pairs.
- eventstring
Name of the product event.
- iparamsobject
Installation parameters specified as a JSON object of <parameter name>: <parameter value> pairs.
- regionstring
Region where the account is deployed.
Possible values: US, EUN, EUC, AUS, IND, and MEC.
- timestampnumber
Timestamp of when the product event occurs, specified in the epoch format.