Snap-in developmentReferences

Function invocation

A function can be invoked synchronously or asynchronously.

You need to implement the run method in your function. The run method is called when the function is invoked. The run method signature is defined below:

1type Context = {
2 // ID of the dev org for which the function is being invoked.
3 dev_oid: string;
4 // ID of the automation/command/snap-kit Action/Event Source for which the function is being invoked.
5 source_id: string;
6 // ID of the snap-in as part of which the function is being invoked.
7 snap_in_id: string;
8 // ID of the snap-in Version as part of which the function is being invoked.
9 snap_in_version_id: string;
10 // This secrets map would contain some secrets which platform would provide to the snap-in.
11 // `service_account_token`: This is the token of the service account which belongs to this snap-in. This can be used to make API calls to DevRev.
12 // `actor_session_token`: For commands, and snap-kits, where the user is performing some action, this is the token of the user who is performing the action.
13 secrets: Record<string, string>;
16type ExecutionMetadata = {
17 // A unique id for the function invocation. Can be used to filter logs for a particular invocation.
18 request_id: string;
19 // Function name as defined in the manifest being invoked.
20 function_name: string;
21 // Type of event that triggered the function invocation as defined in manifest.
22 event_type: string;
23 // DevRev endpoint to which the function can make API calls.
24 // Example : ""
25 devrev_endpoint: string;
28type InputData = {
29 // Map of organization inputs and their corresponding values stored in snap-in.
30 // The values are passed as string and typing need to be handled by the function
31 global_values: Record<string, string>;
32 // Map of event sources and their corresponding ids stored in snap-in.
33 // These could be used to schedule events on a schedule based event source.
34 event_sources: Record<string, string>;
35 // Map of secrets stored in the snap-ins including developer keyrings. The key is the secret name defined in manifest and value is the secret value.
36 keyrings: Record<string, string>;
39// Event sent to our app.
40type FunctionInput = {
41 // Actual payload of the event.
42 payload: Record<string, any>;
43 // Context of the function invocation.
44 context: Context;
45 // Metadata of the function invocation.
46 execution_metadata: ExecutionMetadata;
47 input_data: InputData;
50async function run(events: []FunctionInput): any;

As of now, it’s safe to assume that only one event is passed to the function at a time. The function can be invoked multiple times for multiple events.

The value returned from the run method is passed back in synchronous execution modes, such as commands, snap kit actions, and event source synchronous execution. In asynchronous execution modes, such as automation execution, the return value is ignored.