Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Serverless

The SurveySparrow app development platform includes a serverless environment to enable you to create apps that run in response to events such as SurveySparrow 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.

Whenever an event happens in the server of the SurveySparrow then that event is captured and sent to the app. With this payload the app can do whatever it wants.

In order to capture and use this event the app has to register what are all events that it is using in the manifest.json file.

Under the product name:

"events": {
  "<eventName>": {
    "handler": "<eventCallbackMethod>"
  },
  "<eventName>": {
    "handler": "<eventCallbackMethod>"
  }
}

Sample:

  "events":{
    "onSubmissionComplete":{
      "handler":"submissionHandler"
    },
    "onContactCreate": {
          "handler": "onContactCreate"
    }
  }

server.js

exports = {
  onSubmissionComplete: function (args) {
    console.log('Hello, Survey Id is ' + args['data']['survey_id']);
  },
  onContactCreate: function (args) {
    console.log('Hello, Contact Id is ' + args['data']['id'])
  }
};

In this, whenever a submission has happened in SurveySparrow then that payload will be passed to the app. In the server.js the mentioned handler will get the payload of the submission.

For now, only onSubmissionComplete, onContactCreate, onContactUpdate, onContactDelete are the supported serverless events.

Each of the events can be simulated in the app which is running locally. In order to simulate the events it is important to add them in the manifest file. To simulate the events you can go here after running your app using ssdk run command.

How it looks when you simulate an event in your local app:

image-8

image-9

image-10

(The simulated event has come to handler in server.js)


Sample payloads of each of the events:

All these payloads can be found in server/test_data in your app directory and can be modified accordingly.

OnSubmissionComplete(Event is triggered when a submission is completed in surveysparrow)
Click to expand
  For CX Surveys:
    
    {
  "eventType": "onSubmissionComplete",
  "ruleEvent": "SUBMISSION_COMPLETED",
  "objectType": "SUBMISSION",
  "data": {
    "id": 1000056325,
    "time_taken": "5.00",
    "state": "COMPLETED",
    "device_type": "COMPUTER",
    "feedback": null,
    "ip": null,
    "location": null,
    "language": "en",
    "geo_info": {},
    "created_at": "2024-02-23T07:20:22.474Z",
    "updated_at": "2024-02-23T07:20:22.497Z",
    "account_id": 1000056200,
    "survey_id": 1000035288,
    "contact": {
      "email": "naveen@gmail.com",
      "full_name": "naveen",
      "last_name": "",
      "first_name": "naveen",
      "createddate": "02-23-2024",
      "id": 1003695263
    },
    "score": 5,
    "meta_data": {
      "browser": "Chrome 118.0.0.0",
      "os": "macOS 10.15.7",
      "time_zone": "Asia/Calcutta",
      "browser_language": "en-GB"
    },
    "survey": {
      "id": 1000035288,
      "survey_type": "CSAT",
      "name": "Naveenrk CSAT"
    },
    "folder": {
      "id": 1000056356,
      "name": "General"
    },
    "answers": {
      "1000406992": {
        "answer": 5,
        "question": "How satisfied are you with our service?",
        "question_type": "CSATScore",
        "question_tags": [],
        "question_id": 1000406992,
        "skipped": false
      },
      "1000406993": {
        "answer": "I was focused.",
        "question": "What is the primary reason for your score?",
        "question_type": "CSATFeedback",
        "question_tags": [],
        "question_id": 1000406993,
        "skipped": false,
        "parent_question_id": 1000406992
      }
    },
    "variables": {},
    "expressions": {},
    "channel": {
      "id": 1000009054,
      "type": "LINK",
      "name": "Web Link Share",
      "status": "ACTIVE",
      "web_url": "https://naveenrk.surveysparrow.com/s/Naveenrk-CSAT/ntt-fCYi7nYTWtAZd2HfL3i4ng"
    }
  },
  "account_id": 1000056200
}
 
    
  For Other Surveys : 
  
  {
    "eventType": "onSubmissionComplete",
    "ruleEvent": "SUBMISSION_COMPLETED",
    "objectType": "SUBMISSION",
    "data": {
      "id": 1001001581,
      "time_taken": "6.00",
      "state": "COMPLETED",
      "start_time": "2023-12-01T11:16:23.007Z",
      "completed_time": "2023-12-01T11:16:29.007Z",
      "device_type": "COMPUTER",
      "feedback": null,
      "ip": null,
      "location": null,
      "language": "en",
      "geo_info": {},
      "created_at": "2023-12-01T11:16:28.935Z",
      "updated_at": "2023-12-01T11:16:29.007Z",
      "account_id": 12,
      "nomination_id": null,
      "survey_id": 1001000164,
      "survey": {
        "id": 1001000164,
        "survey_type": "ClassicForm",
        "name": "Employee Experience Survey"
      },
      "folder": {
        "id": 12,
        "name": "General"
      },
      "contact": {
        "email": "eldridge777l@surveysparrow.com",
        "mobile": "424-998-0848",
        "full_name": "Eldridge Rogahn",
        "last_name": "Rogahn",
        "first_name": "Eldridge",
        "createddate": "10-10-2023",
        "id": 1001000589
      },
      "meta_data": {
        "browser": "Chrome 119.0.0.0",
        "os": "macOS 10.15.7",
        "time_zone": "Asia/Calcutta",
        "browser_language": "en-US"
      },
      "answers": {
        "1001000645": {
          "answer": 9,
          "step": 10,
          "question": "op 1",
          "question_tags": [],
          "question_type": "",
          "question_id": 1001000645,
          "skipped": false
        },
        "1001000646": {
          "answer": "yui",
          "answer_sentiment": null,
          "question": "trext",
          "question_tags": [],
          "question_type": "",
          "question_id": 1001000646,
          "skipped": false
        }
      },
      "variables": {
        "variable_1": "56"
      },
      "expressions": {
        "1001000001": "9.000000000000000"
      },
      "channel": {
        "id": 1001000246,
        "type": "EMBED",
        "name": "Embed Share 1",
        "status": "ACTIVE",
        "subject": "Could you spare a quick moment to give some feedback?",
        "is_default": false,
        "limits": null,
        "token": "tt-wuMTgKw8kTZE2bhqAT1Brp",
        "web_url": "https://ayesha.surveysparrow.com/s/test/tt-853e56"
      }
    },
    "account_id": 100000001
  }
  
  
OnContactCreate(Event is triggered when a contact is created in surveysparrow)
Click to expand
    
{
  eventType: "onContactCreate",
  ruleEvent: "CONTACT_CREATED",
  objectType: "CONTACT",
  objectId: 100000321,
  data: {
    id: 100000321,
    contact_type_id: 3,
    attrs: {
      email: "srirdsdam.r@surveysparrow.com",
      phone: "6383683088",
      mobile: "9736277722",
      full_name: "new contact",
      job_title: "contact",
      language: "en",
      last_name: "contact",
      first_name: "new",
      createddate: "09-12-2023",
      extra_property: "abcd",
      new_employee_property: "abcd",
    },
    hidden: false,
    account_id: 100000001,
    created_at: "2023-09-12T02:49:27.804Z",
    manager_id: null,
    is_active: true,
    deactivated: false,
    unsubscribed: false,
    unsubscribed_at:null,
    bounced: false,
    full_name: "new contact",
    role: "default",
    updated_at: "2023-09-12T02:49:27.804Z",
    deleted_at: null,
    contact_lists: [
      {
        id: 100000005,
        name: "test",
        description: null,
        type: "STATIC",
        properties: {
        },
        contact_type_id: 3,
        created_at: "2023-08-21T10:43:49.684Z",
        updated_at: "2023-09-12T02:49:27.911Z",
        deleted_at: null,
        account_id: 100000001,
      },
      {
        id: 100000006,
        name: "sample-contacts (1)",
        description: "Auto created during the contact import (sample-contacts (1))",
        type: "STATIC",
        properties: {
        },
        contact_type_id: 3,
        created_at: "2023-08-21T10:57:29.170Z",
        updated_at: "2023-09-12T02:49:27.911Z",
        deleted_at: null,
        account_id: 100000001,
      },
    ],
    contact_property_value_mapping: [
    ],
    manager: null,
  },
  account_id: 100000001,
}
    
  
OnContactUpdate(Event is triggered when a contact is updated in surveysparrow)
Click to expand
    
{
  eventType: "onContactUpdate",
  ruleEvent: "CONTACT_UPDATED",
  objectType: "CONTACT",
  objectId: 100000321,
  data: {
    id: 100000321,
    contact_type_id: 3,
    attrs: {
      email: "srirdsdam.r@surveysparrow.com",
      phone: "6383683088",
      mobile: "",
      full_name: "new contact",
      job_title: "contact",
      language: "en",
      last_name: "contact",
      first_name: "new",
      createddate: "09-12-2023",
      extra_property: "abcd",
      new_employee_property: "abcd",
    },
    hidden: false,
    account_id: 100000001,
    created_at: "2023-09-12T02:49:27.804Z",
    manager_id: null,
    is_active: true,
    deactivated: false,
    unsubscribed: false,
    unsubscribed_at:null,
    bounced: false,
    full_name: "new contact",
    role: "default",
    updated_at: "2023-09-12T02:50:56.795Z",
    deleted_at: null,
    contact_lists: [
      {
        id: 100000005,
        name: "test",
        description: null,
        type: "STATIC",
        properties: {
        },
        contact_type_id: 3,
        created_at: "2023-08-21T10:43:49.684Z",
        updated_at: "2023-09-12T02:49:27.911Z",
        deleted_at: null,
        account_id: 100000001,
      },
      {
        id: 100000006,
        name: "sample-contacts (1)",
        description: "Auto created during the contact import (sample-contacts (1))",
        type: "STATIC",
        properties: {
        },
        contact_type_id: 3,
        created_at: "2023-08-21T10:57:29.170Z",
        updated_at: "2023-09-12T02:49:27.911Z",
        deleted_at: null,
        account_id: 100000001,
      },
    ],
    contact_property_value_mapping: [
    ],
    manager: null,
  },
  account_id: 100000001,
}
    
  
OnContactDelete(Event is triggered when a contact is deleted in surveysparrow)
Click to expand
    
    {
      eventType: "onContactDelete",
      ruleEvent: "CONTACT_DELETED",
      objectType: "CONTACT",
      objectId: 100000321,
      data: {
        id: 100000321,
        first_name: "new",
        last_name: "contact",
        email: "srirdsdam.r@surveysparrow.com",
        phone: "6383683088",
        mobile: "",
        job_title: "contact",
        active: true,
        unsubscribed: false,
        bounced: false,
        spam_victim: false,
        disposable: false,
        attrs: {
          email: "srirdsdam.r@surveysparrow.com",
          phone: "6383683088",
          mobile: "",
          full_name: "new contact",
          job_title: "contact",
          language: "en",
          last_name: "contact",
          first_name: "new",
          createddate: "09-12-2023",
          extra_property: "abcd",
          new_employee_property: "abcd",
        },
        role: "default",
        hidden: false,
        language: "en",
        contact_type_id: 3,
        deactivated: false,
        portal_language: "ENGLISH",
        email_lowercase: null,
        created_at: "2023-09-12T02:49:27.804Z",
        updated_at: "2023-09-12T02:50:56.795Z",
        deleted_at: "2023-09-12T02:52:06.216Z",
        account_id: 100000001,
        manager_id: null,
      },
      account_id: 100000001,
    }
        
      
OnTicketCreate(Event is triggered when a ticket is created in surveysparrow)
Click to expand
        
        {
    "eventType": "onTicketCreate",
    "ruleEvent": "TICKET_CREATED",
    "objectType": "TICKET",
    "objectId": 100000004,
    "data": {
        "id": 100000004,
        "subject": "Unable to restrict multiple submissions based on specific survey questions",
        "description": "Restriciting submissions based on contact is possible but doesn't work with specific questions in the survey",
        "created_at": "2023-12-20T10:53:18.507Z",
        "updated_at": "2023-12-21T07:00:49.754Z",
        "deleted_at": null,
        "submission_id": null,
        "nps_submission_id": null,
        "priority": {
            "id": 100000001,
            "value": "High"
        },
        "status": {
            "id": 100000004,
            "value": "Open"
        },
        "source": {
            "id": 100000006,
            "value": "Call"
        },
        "agent": {
            "id": 100000003,
            "name": "Gabriel",
            "email": "gabriel@surveysparrow.com"
        },
        "requester": {
            "id": 100000003,
            "name": "Gabriel",
            "email": "gabriel@surveysparrow.com",
            "phone": "9123456789",
            "mobile": "123456789"
        },
        "custom_fields": {
            "Text_field": "Random text"
        },
        "resolution_due": "2023-12-25T11:46:18.507Z",
        "first_response_due": "2023-12-18T11:46:18.507Z"
    },
    "account_id": 1000001115
}
        
  
OnTicketUpdate(Event is triggered when a ticket is updated in surveysparrow)
Click to expand
    
    {
    "eventType": "onTicketUpdate",
    "ruleEvent": "TICKET_UPDATED",
    "objectType": "TICKET",
    "objectId": 100000004,
    "data": {
        "id": 100000004,
        "subject": "Unable to restrict multiple submissions based on specific survey questions",
        "description": "Restriciting submissions based on contact is possible but doesn't work with specific questions in the survey",
        "created_at": "2023-12-20T10:53:18.507Z",
        "updated_at": "2023-12-21T07:00:49.754Z",
        "deleted_at": null,
        "submission_id": null,
        "nps_submission_id": null,
        "priority": {
            "id": 100000001,
            "value": "High"
        },
        "status": {
            "id": 100000004,
            "value": "Open"
        },
        "source": {
            "id": 100000006,
            "value": "Call"
        },
        "agent": {
            "id": 100000003,
            "name": "Gabriel",
            "email": "gabriel@surveysparrow.com"
        },
        "requester": {
            "id": 100000003,
            "name": "Gabriel",
            "email": "gabriel@surveysparrow.com",
            "phone": "9123456789",
            "mobile": "123456789"
        },
        "custom_fields": {
            "Text_field": "Random text"
        },
        "resolution_due": "2023-12-25T11:46:18.507Z",
        "first_response_due": "2023-12-18T11:46:18.507Z"
    },
    "account_id": 1000001115
}
    
  
OnTicketDelete(Event is triggered when a ticket is deleted in surveysparrow)
Click to expand
    
    {
    "eventType": "onTicketDelete",
    "ruleEvent": "TICKET_DELETED",
    "objectType": "TICKET",
    "objectId": 100000004,
    "data": {
        "id": 100000004,
        "subject": "Unable to restrict multiple submissions based on specific survey questions",
        "description": "Restriciting submissions based on contact is possible but doesn't work with specific questions in the surve",
        "created_at": "2023-12-20T10:53:18.507Z",
        "updated_at": "2023-12-21T07:00:49.754Z",
        "deleted_at": "2023-12-21T07:00:49.754Z",
        "submission_id": null,
        "nps_submission_id": null,
        "priority": {
            "id": 100000001,
            "value": "High"
        },
        "status": {
            "id": 100000004,
            "value": "Open"
        },
        "source": {
            "id": 100000006,
            "value": "Call"
        },
        "agent": {
            "id": 100000003,
            "name": "Gabriel",
            "email": "gabriel@surveysparrow.com"
        },
        "requester": {
            "id": 100000003,
            "name": "Gabriel",
            "email": "gabriel@surveysparrow.com",
            "phone": "9123456789",
            "mobile": "123456789"
        },
        "custom_fields": {
            "Text_field": "Random text"
        },
        "resolution_due": "2023-12-25T11:46:18.507Z",
        "first_response_due": "2023-12-18T11:46:18.507Z"
    },
    "account_id": 1000001115
}
    
  
OnTicketCommentCreate(Event is triggered when a comment is made on a ticket in surveysparrow)
Click to expand
    
    {
    "eventType": "onTicketCommentCreate",
    "ruleEvent": "TICKET_COMMENT_CREATED",
    "objectType": "TICKET_COMMENT",
    "objectId": 122,
    "data": {
        "body": "Will be resolved by a specific team of SurveySparrow",
        "id": 122,
        "ticket_id": 111,
        "type": "INTERNAL_NOTE/REPLY",
        "responder_type": "AGENT/REQUESTER",
        "agent": {
            "id": 333,
            "name": "Eldridge",
            "email": "eldridge777l@surveysparrow.com"
        },
        "created_at": "2023-12-20T10:53:18.507Z"
    },
    "account_id": 1000001115
}
    
  
OnWidgetCreate(Event is triggered when a new widget is created)
Click to expand
    
    {
    "eventType": "onWidgetCreate",
    "ruleEvent": "WIDGET_CREATE",
    "objectType": "DASHBOARD_WIDGET",
    "data": {
      "id": 1000001459,
      "name": "demo",
      "properties": {
        "date": {
          "date_range": {
            "end_date": null,
            "start_date": null,
            "display_string": "All Time"
          },
          "date_aggregation": "MONTHLY"
        },
        "meta": {},
        "filters": {
          "filter_groups": [],
          "global_connector": "AND"
        },
        "metrics": [
          {
            "aggregation": "COUNT",
            "resource_meta": {
              "metric_id": 1000001494,
              "metric_type": "OpinionScale",
              "metric_label": "some op qsttn",
              "metric_properties": {
                "data": {
                  "max": "builder.opinion_scale.max",
                  "mid": "builder.opinion_scale.mid",
                  "min": "builder.opinion_scale.min",
                  "step": 10,
                  "start": 0,
                  "reversed_order": false,
                  "not_applicable_tooltip_text": "Not Applicable"
                }
              }
            },
            "resource_type": "QUESTION",
            "data_source_id": 1000000375,
            "data_source_type": "survey",
            "data_survey_type": "ClassicForm"
          }
        ],
        "sources": [
          {
            "resource_id": 1000000375,
            "survey_type": "ClassicForm",
            "resource_type": "cognivue test 1"
          }
        ],
        "chart_type": {
          "type": "VERTICAL_BAR_CHART"
        },
        "color_theme": {
          "mono_color": null,
          "infographic_color": "#51D3D9"
        },
        "dimensions": [
          {
            "choices": {},
            "resource_meta": {
              "dimension_id": "submissionTime",
              "dimension_type": "SUBMISSION_TIME",
              "dimension_label": "Submission Time"
            },
            "resource_type": "CUSTOM",
            "data_source_id": 1000000375,
            "sub_dimensions": [],
            "data_source_type": "survey"
          }
        ]
      },
      "account_id": 1000000053,
      "dashboard_id": 1000000009
    },
    "account_id": 1000000053
  }
    
  
OnWidgetUpdate(Event is triggered when a widget is updated)
Click to expand
    
   {
    "eventType": "onWidgetUpdate",
    "ruleEvent": "WIDGET_UPDATE",
    "objectType": "DASHBOARD_WIDGET",
    "data": {
      "current_data": {
        "id": 1000001458,
        "name": "bar charrt 2",
        "properties": {
          "date": {
            "date_range": {
              "end_date": null,
              "start_date": null,
              "display_string": "All Time"
            },
            "date_aggregation": "MONTHLY"
          },
          "meta": {},
          "filters": {
            "filter_groups": [],
            "global_connector": "AND"
          },
          "metrics": [
            {
              "aggregation": "COUNT",
              "resource_meta": {
                "metric_id": 1000001489,
                "metric_type": "NPSScore",
                "metric_label": "How likely are you to recommend caseactivitylogs2 to a friend or colleague?",
                "metric_properties": {
                  "data": {
                    "labels": {
                      "left": "builder.opinion_scale.min",
                      "right": "builder.opinion_scale.max"
                    },
                    "appearance": {
                      "filled": true,
                      "button_shape": "Square"
                    },
                    "start_with_one": false,
                    "segment_colors": {
                      "passives": "FFDB78",
                      "promoters": "8DCD71",
                      "detractors": "FC9B9C"
                    },
                    "tinted_options": false,
                    "include_feedback": true,
                    "segmented_options": false
                  }
                }
              },
              "resource_type": "QUESTION",
              "data_source_id": 1000000372,
              "data_source_type": "survey",
              "data_survey_type": "NPS"
            }
          ],
          "sources": [
            {
              "resource_id": 1000000372,
              "survey_type": "NPS",
              "resource_type": "Feedback NPS"
            }
          ],
          "chart_type": {
            "type": "VERTICAL_BAR_CHART"
          },
          "color_theme": {
            "mono_color": null,
            "infographic_color": "#51D3D9"
          },
          "dimensions": [
            {
              "choices": {},
              "resource_meta": {
                "dimension_id": "submissionTime",
                "dimension_type": "SUBMISSION_TIME",
                "dimension_label": "Submission Time"
              },
              "resource_type": "CUSTOM",
              "data_source_id": 1000000372,
              "sub_dimensions": [],
              "data_source_type": "survey"
            }
          ]
        },
        "account_id": 1000000053,
        "dashboard_id": 1000000009
      },
      "previous_data": {
        "id": 1000001458,
        "name": "bar charrt",
        "properties": {
          "date": {
            "date_range": {
              "end_date": null,
              "start_date": null,
              "display_string": "All Time"
            },
            "date_aggregation": "MONTHLY"
          },
          "meta": {},
          "filters": {
            "filter_groups": [],
            "global_connector": "AND"
          },
          "metrics": [
            {
              "aggregation": "COUNT",
              "resource_meta": {
                "metric_id": 1000001489,
                "metric_type": "NPSScore",
                "metric_label": "How likely are you to recommend caseactivitylogs2 to a friend or colleague?",
                "metric_properties": {
                  "data": {
                    "labels": {
                      "left": "builder.opinion_scale.min",
                      "right": "builder.opinion_scale.max"
                    },
                    "appearance": {
                      "filled": true,
                      "button_shape": "Square"
                    },
                    "start_with_one": false,
                    "segment_colors": {
                      "passives": "FFDB78",
                      "promoters": "8DCD71",
                      "detractors": "FC9B9C"
                    },
                    "tinted_options": false,
                    "include_feedback": true,
                    "segmented_options": false
                  }
                }
              },
              "resource_type": "QUESTION",
              "data_source_id": 1000000372,
              "data_source_type": "survey",
              "data_survey_type": "NPS"
            }
          ],
          "sources": [
            {
              "resource_id": 1000000372,
              "survey_type": "NPS",
              "resource_type": "Feedback NPS"
            }
          ],
          "chart_type": {
            "type": "VERTICAL_BAR_CHART"
          },
          "color_theme": {
            "mono_color": null,
            "infographic_color": "#51D3D9"
          },
          "dimensions": [
            {
              "choices": {},
              "resource_meta": {
                "dimension_id": "submissionTime",
                "dimension_type": "SUBMISSION_TIME",
                "dimension_label": "Submission Time"
              },
              "resource_type": "CUSTOM",
              "data_source_id": 1000000372,
              "sub_dimensions": [],
              "data_source_type": "survey"
            }
          ]
        },
        "account_id": 1000000053,
        "dashboard_id": 1000000009
      }
    },
    "account_id": 1000000053
  }
    
  
OnWidgetDelete(Event is triggered when a widget is deleted)
Click to expand
    
    {
    "eventType": "onWidgetDelete",
    "ruleEvent": "WIDGET_DELETE",
    "objectType": "DASHBOARD_WIDGET",
    "data": {
      "id": 1000001459,
      "account_id": 1000000053,
      "dashboard_id": 1000000009
    },
    "account_id": 1000000053
  }
    
  
OnDashboardCreate(Event is triggered when a new dashboard is created)
Click to expand
    
    {
  "eventType": "onDashboardCreate",
  "ruleEvent": "DASHBOARD_CREATE",
  "objectType": "DASHBOARD",
  "data": {
    "id": 1000000170,
    "name": "ddd445",
    "description": "",
    "account_id": 1000000053,
    "visibility": "MINE",
    "properties": { "base_color": "#CDFBF2", "dashboard_icon": 5 }
  },
  "account_id": 1000000053
}
    
  
OnDashboardUpdate(Event is triggered when a dashboard is updated)
Click to expand
    
    {
  "eventType": "onDashboardUpdate",
  "ruleEvent": "DASHBOARD_UPDATE",
  "objectType": "DASHBOARD",
  "data": {
    "current_data": {
      "id": 1000000170,
      "name": "ddd445567",
      "description": "",
      "account_id": 1000000053,
      "visibility": "SHARED",
      "properties": { "base_color": "#CDFBF2", "dashboard_icon": 5 }
    },
    "previous_data": {
      "id": 1000000170,
      "name": "ddd445",
      "description": "",
      "account_id": 1000000053,
      "visibility": "MINE",
      "properties": { "base_color": "#CDFBF2", "dashboard_icon": 5 }
    }
  },
  "account_id": 1000000053
}
    
  
OnDashboardDelete(Event is triggered when a dasboard is deleted)
Click to expand
    
    {
  "eventType": "onDashboardDelete",
  "ruleEvent": "DASHBOARD_DELETE",
  "objectType": "DASHBOARD",
  "data": { "id": 1000000170, "account_id": 1000000053 },
  "account_id": 1000000053
}
    
  
OnExternalEvent(Event is triggered when a third-party sends data to the incoming webhook)
Click to expand
    
    {
        "data": {
            "accountId": 2,
            "headers": {
                "x-forwarded-for": "107.23.202.147",
                "x-forwarded-proto": "https",
                "x-forwarded-port": "443",
                "host": "marketplace.servicesparrow.app",
                "x-amzn-trace-id": "Root=1-65cb0d1c-05618b34238835eb0a23294e",
                "content-length": "221",
                "accept": "application/json",
                "accept-charset": "utf-8",
                "accept-encoding": "gzip, deflate",
                "user-agent": "IFTTT-Protocol/v1",
                "authorization": "Bearer pudtlUifqXOD66NYm0VVAmTTL8csRJG--fCiMGZrCOia2lGpw0cr3JQL7C9ghtpoNjzkaAP30YTKLBsK76U9t7Mw",
                "x-ifttt-realtime": "0",
                "x-request-id": "a58bc84e04654229b248dd97829b0d02",
                "content-type": "application/json",
                "x-datadog-trace-id": "4433809555521032027",
                "x-datadog-parent-id": "1666971791582876090",
                "x-datadog-sampling-priority": "0",
                "x-datadog-tags": "_dd.p.tid=65cb0d1c00000000",
                "traceparent": "00-65cb0d1c000000003d880e4ca6904f5b-172246032fe4d1ba-00",
                "tracestate": "dd=s:0",
                "sentry-trace": "884c1a7bb28b46daa394facf0ee24dc7-2e9cc74b25614d24",
                "baggage": "sentry-trace_id=884c1a7bb28b46daa394facf0ee24dc7,sentry-environment=production,sentry-release=ifttt_front_end%40production-v6189,sentry-public_key=f2dd1d54d35a4355ac4becccc9033596"
            },
            "data": {
                "triggerFields": {
                    "chosenSurvey": "1000010864"
                },
                "trigger_identity": "7eb6977c519b2a40c0df2083c36c720c73dd2f0d",
                "ifttt_source": {
                    "id": "136127942",
                    "url": "https://ifttt.com/applets/ZwWuyMJE"
                },
                "user": {
                    "timezone": "Asia/Kolkata"
                }
            },
            "requestUrl": "/NjoyOjEmaGFzaD1ObzNCdzQ2UmZSVGVydWw/ifttt/v1/triggers/submission",
            "eventType": "onExternalEvent"
        },
        "iparams": null
    }
    
  

Key Considerations

  1. To integrate serverless functionalities on a react application created using SSDK CLI, just add a folder named server in the root directory and add the file server.js inside it. In the server.js file, add the necessary code as mentioned above such as the event configurations and the handlers.
  2. When importing local files or modules in any of the files within the server, the require() function returns a promise, so you need to await the require() call and then use the module. This is not a issue when importing NPM packages. Below is an example.

In the db_schema.js file present in the server folder,

  const db_schema = {
    id:{
        type: "string",
        required: true,
    },
    
    survey_id:{
        type: "string",
        required:true,
    }      
  }

  exports = {
    db_schema
  }

In the server.js file,

  const db_schema = require("./db_schema")

  async function handler(){
      const db_schema_obj = await db_schema;
  }


Note: When exporting data from a file within the server folder, ensure that you are using the exports keyword. Below is the syntax on exporting data inside the server folder.

  // an Object
  const sample_obj = {
    message: "sample text"
  }

  // a Function
  const sample_function = async ()=>{
    return {
      "data":"sample data"
    }
  }

  // exporting the sample object and the sample Function
  exports = {
    sample_obj,
    sample_function
  }
  1. When you want to import and use any NPM packages within the server folder

Server Method Invocation:

The Server Method Invocation (SMI) feature enables you to build an app with a front-end component that can invoke a serverless component. To do this:

  1. In the manifest.json > functions object, specify all the server methods that are called from the front-end component of the app, to allowlist the methods.

  2. In the front-end component (app.js), specify the method to invoke the serverless component and pass an appropriate payload to the serverless component. By default, the serverless environment adds the installation parameters set during app installation to the payload.

  3. In the serverless component (server.js), define the server method (SMI function) that is allow-listed in the app manifest and called from the front-end component. In this server method, include the app logic that runs based on the payload passed and the method will return success and failure responses to the front-end component.

The SMI functions should be mentioned under the productName in manifest.json like:

"functions": {
        "serverMethod1": {
          "timeout": 10
        },
        "serverMethod2": {
          "timeout": 15
        }
      }

Sample:

"functions":{
"surveyConverter":{       
    "timeout":10
   }
}

The server method can be invoked from the frontend using the client object like:

client.request.invoke(functionName, data);

Sample:

in app.js

const result = await window.client.request.invoke(“surveyConverter”, {data:”sample_data”});

server.js

exports = {
  surveyConverter: async function(options) {
    console.log(options);
    return {
      "data":"demo"
    }
}

The Server method will recieve the data along with the iparams of the app user like:

{
  "iparams":{
    api_Key: "dafsfdfaasdsd"
  },
  "data":{
    data:”sample_data”
  }
}

After the app logic in the server method runs, the server method sends an appropriate response to the front-end component. To enable this:

  • Navigate to the server.js file. In the exports code block, define the server method (SMI function) that is called from the front-end component. Place the app logic inside the server method.

The frontend component will get the value retired from this smi function and this value is stringified. The actual JSON can be taken from the retired value by JSON.parse(returned_value) in the frontend Component.