Scheduled Events

You can create one-time or recurring scheduled events to invoke serverless apps. At the specified time, the App Framework is notified which then invokes the relevant serverless method in the app.

Sample Use Cases

  • Reminders: You can be notified about a specific event scheduled at a particular time. For example, you can trigger an SMS five minutes before a meeting.
  • Data Sync: You can poll an external product every hour for updates and make the same changes in Freshdesk.
  • Recurring tasks: You can create daily/weekly reports or tickets to track recurring tasks.

Note:
1. You need to have CLI v4.0.0 or higher in order to use this feature. For more information on how to get the latest version, click here.
2. You can have a maximum of 1000 one-time schedules and 1 recurring schedule.
3. The timeout period for app execution is 20 seconds and the default time zone is UTC. The schedule_at time must be at least 5 minutes from the current time.

Take a look at the Scheduled events sample app for a demonstration of this feature.

Payload

At the specified time, the corresponding method in the server.js file is invoked and the following payload is passed to the app.

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
{ "account_id" : "value", "event" : "onScheduledEvent", "region" : "value", "timestamp" : "value", "domain" : "value", "data" : {}, "iparams" : { "Param1" : "value", "Param2" : "value" } }
EXPAND ↓

The following table lists the payload attributes.

Attribute Type Description
account_id number The Freshdesk account ID.
event string The name of the event (onScheduledEvent).
region string The region where the app is installed, either "US", "EU", "EUC", or "AUS".
timestamp number Represents the time (epoch format) when the event was received.
domain string The Freshdesk account domain.
data JSON The payload that was passed while creating the schedule. The payload should be of JSON type and the size should not exceed 4 KB.
iparams object Installation parameters.

Sample payload

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{ "account_id": 12345, "event": "onScheduledEvent", "timestamp" : 1496400354326, "region" : "US", "domain": "https://xyz.freshdesk.com", "data": { "account_name": "Jacob", "account_id": 3, "country": "France" }, "iparams": { } }
EXPAND ↓
Registration
To perform an action, you need to register the scheduled event with the corresponding callback. This is done in the following format.

server.js Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
exports = { events: [ { event: "onScheduledEvent", callback: "onScheduledEventHandler" } ], onScheduledEventHandler: function(payload) { console.log("Logging arguments from onScheduledEvent: " + JSON.stringify(payload)); if(payload.data.account_id = 3) { //your code to perform any actions } } };
EXPAND ↓

Note:
1. You should include the event and callback definition in the exports block.
2. You should include only one callback function for an event.

Schedules

You can use the following methods to create, update, and delete schedules.

To create a one-time schedule - server.js Copied Copy
1
2
3
4
5
6
7
8
9
10
$schedule.create({ name: "ticket_reminder", data: {ticket_id: 100001}, schedule_at: "2018-06-10T07:00:00.860Z", }) .then(function(data) { //"data" is a json with status and message. }, function(err) { //"err" is a json with status and message. });
EXPAND ↓

To create a recurring schedule - server.js Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$schedule.create({ name: "ticket_reminder", data: {ticket_id: 10001}, schedule_at: "2018-06-10T07:00:00.860Z", repeat: { time_unit: "minutes", frequency: 5 } }) .then(function(data) { //"data" is a json with status and message. }, function(err) { //"err" is a json with status and message. });
EXPAND ↓

To fetch a schedule - server.js Copied Copy
1
2
3
4
5
6
7
8
$schedule.fetch({ name: "ticket_reminder" }) .then(function(data) { //"data" is a json with name, data and schedule_at used to create the schedule }, function(err) { // “err” is a json with status and message. });
EXPAND ↓

To update a schedule - server.js Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$schedule.update({ name: "ticket_reminder", data: {ticket_id: 10001}, schedule_at: "2018-06-10T07:00:00.860Z", repeat: { time_unit: "hours", frequency: 1 } }) .then(function(data) { //"data" is a json with status and message. }, function(err) { //"err" is a json with status and message. });
EXPAND ↓

To delete a schedule - server.js Copied Copy
1
2
3
4
5
6
7
8
$schedule.delete({ name: "ticket_reminder" }) .then(function(data) { //"data" is a json with status and message. }, function(err) { //"err" is a json with status and message. });
EXPAND ↓

The parameters and their description are listed in the table.

PARAMETER TYPE DESCRIPTION
name string Unique string to identify the schedule.
data json Data that needs to be passed to the schedule event handler when the event is fired.
schedule_at time (ISO format) Time at which the schedule needs to be triggered.
Note:
For recurring schedules (with time_unit as days), the hour and minutes at which the scheduled event must be fired will be taken from the schedule_at value.
time_unit string Time unit (minutes, hours, or days) for which the recurring schedule is created.
frequency number Frequency of execution of an event with respect to the time unit.

Testing

To enable you to test this feature, all schedules will be automatically triggered 5 seconds after they are created or updated.

Log in with your Freshdesk account

Enter your helpdesk URL to proceed to login

Proceed

By clicking "Proceed", you agree to our Terms of Use.