|
1 | | -A function can be invoked synchronously or asynchronously. |
| 1 | +The function is invoked by the runner.ts file. |
| 2 | + |
| 3 | +runner.ts processes events of type "any", which are basically events of type "AirdropEvent" with some additional fields, and passes the events to the function. You can ignore the additional fields. |
| 4 | + |
2 | 5 | 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: |
3 | 6 | ```typescript |
4 | | -type Context = { |
5 | | - // ID of the dev org for which the function is being invoked. |
6 | | - dev_oid: string; |
7 | | - // ID of the automation/command/snap-kit Action/Event Source for which the function is being invoked. |
8 | | - source_id: string; |
9 | | - // ID of the snap-in as part of which the function is being invoked. |
10 | | - snap_in_id: string; |
11 | | - // ID of the snap-in Version as part of which the function is being invoked. |
12 | | - snap_in_version_id: string; |
13 | | - // ID of the service account. |
14 | | - service_account_id: string; |
15 | | - // This secrets map would contain some secrets which platform would provide to the snap-in. |
16 | | - // `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. |
17 | | - // `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. |
18 | | - secrets: Record<string, string>; |
19 | | -}; |
20 | | -type ExecutionMetadata = { |
21 | | - // A unique id for the function invocation. Can be used to filter logs for a particular invocation. |
22 | | - request_id: string; |
23 | | - // Function name as defined in the manifest being invoked. |
24 | | - function_name: string; |
25 | | - // Type of event that triggered the function invocation as defined in manifest. |
26 | | - event_type: string; |
27 | | - // DevRev endpoint to which the function can make API calls. |
28 | | - // Example : "https://api.devrev.ai/" |
29 | | - devrev_endpoint: string; |
30 | | -}; |
31 | | -type InputData = { |
32 | | - // Map of organization inputs and their corresponding values stored in snap-in. |
33 | | - // The values are passed as string and typing needs to be handled by the function |
34 | | - global_values: Record<string, string>; |
35 | | - // Map of event sources and their corresponding ids stored in snap-in. |
36 | | - // These could be used to schedule events on a schedule based event source. |
37 | | - event_sources: Record<string, string>; |
38 | | -}; |
39 | | -// Event sent to our app. |
40 | | -type 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; |
48 | | -}; |
49 | | -async function run(events: []FunctionInput): any; |
| 7 | +async function run(events: []AirdropEvent): void; |
50 | 8 | ``` |
51 | | -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. |
52 | | -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. |
| 9 | +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. |
0 commit comments