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 corresponding changes in Freshcaller.
  • Recurring tasks: You can create daily/weekly tasks.

Notes:
  • You can have a maximum of 1000 one-time schedules and 1 recurring schedule.
  • 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 string Identifier of the Freshcaller account, auto-generated when the account is configured for a business.
event string Identifier of the event - onScheduledEvent.
region string Region where the Freshcaller account is deployed.
Possible values: US, EU, EUC, AUS, and IND.
timestamp number Timestamp of when the scheduled event occurs, specified in the epoch format.
domain string Domain name for the Freshcaller account. For example, acn.freshcaller.com.
data object The payload that is passed when creating the schedule. The payload should be of JSON type and the size should not exceed 4 KB.
iparams object Installation parameters specified as a JSON object of <parameter name>: <parameter value> pairs.

Sample payload

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
{ "account_id": "12345", "domain": "sample.freshcaller.com", "event": "onScheduledEvent", "timestamp": 1583839686, "region": "US", "data": { "sample_data1": "sample value1", "sample_data2": "sample value2", "sample_data3": 3 } }
EXPAND ↓
Registration

To register a scheduled event and the corresponding callback:

  1. From your app’s root directory, navigate to the manifest.json file.
  2. Include the events attribute, specifying the scheduled event and the corresponding callback methods as follows:
    Copied Copy
    1
    2
    3
    4
    5
    "events": { "onScheduledEvent": { "handler": "onScheduledEventHandler" } }

    Note: Include only one callback method for an event. Multiple events can access the same callback method.

  3. Navigate to the server.js file.
  4. In the exports block, enter the callback function definition as follows:
    Copied Copy
    1
    2
    3
    4
    5
    6
    7
    8
    9
    exports = { onScheduledEventHandler: function(payload) { console.log("Logging arguments from onScheduledEvent: " + JSON.stringify(payload)); if(payload.data.account_id = "3") { //your code to perform any actions } } };

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
11
12
13
14
15
16
$schedule.create({ name: "status_modifier", data: { "email": "abc@example.com", "role": "Account Admin", "preference": 3, "mobile_app_preference": 1, "deleted": false }, 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: "generate_call_metrics", data: {"id": 17993533}, schedule_at: "2018-06-10T07:00:00.860Z", repeat: { time_unit: "minutes", frequency: 40 } }) .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: "generate_call_metrics" }) .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: "generate_call_metrics", data: {id: 17993533}, 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: "generate_call_metrics" }) .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

When a scheduled event is triggered, schedules are run at the specified time and frequency.

For information on how to test scheduled events, see Test the app.