How to create a plug-in


viaSocket provides a wonderful feature of creating your own plug-in. This gives you the flexibility to create any plugin you want. Let's dive deep into the process of creating your own plug-in and actions in your viaSocket account. 

1. Log into your viaSocket account. Choose the option plug-in builder 
       

In this example, we are going to build a MailChimp plug-in. 

2. Let’s break down this process step by step 

       

Things you add here will be visible in your plugin so add it carefully. 

Plugin is a viaocket service in which we integrate third party services with the help of their API. They are designed to be flexible and customizable, enabling users to create automation flows that suit their specific needs and workflows. Here is a guide to create a plugin.


Visibility Configuration

                                  




Authentication Configuration

Next step to set authentication for your plugin. In Authentication Configuration viaSocket provide two types of authentication methods for your application:

🛑 NOTE : If any service support base64 conversion then select Basic auth in that case.

                               

Authentication Configuration - Basic Auth

Typically, basic authentication requires the service's api-key. The processes to obtain an API key and the necessary fields are covered in detail in the service's documentation.

Configure additional Input Fields (if required) :

Click on Add Field and fill the field details

                      

🛑 NOTE: The fields you created for authentication are required to create actions and triggers. Use this value format: `${context.authData.fieldkey_name}`.

Test Me API

To complete the process of authentication the final step is to add the Test Me API. It is a simple GET API which is getting user details, profile information. This API is invoked during the authentication process of the plugin.

Sample Request with Response:

try{
let config = {
   method: 'get',
   maxBodyLength: Infinity,
url: 'https://api.airtable.com/v0/meta/whoami',
   headers: { 
     'Authorization': `Bearer ${context?.authData?.auth_key}`
   }
 };
 
 const response = await axios.request(config)
return response.data
}
catch(error){
    throw error
}

                 

Connection Label

It is a label provided to show authentication by the user when using the plugin in any of the flows. For security purposes, "Mask connection label value” is used to essentially conceal the actual value of the connection label. 

                              

Authentication Configuration - OAuth 2.0

Auth2.0 works by delegating user authentication to the service that hosts the user account and authorizing third-party applications to access the user account. To implement OAuth 2.0 in viaSocket for a particular service, you would typically need to register your application with the service to obtain a client ID and client secret, implement redirection endpoints for handling callbacks, and implement the logic to obtain and refresh access tokens using the client credentials.

                  

                   

Scopes: Scopes define and limit the access that a client application has to a user's resources on a resource server. They play a crucial role in determining the extent of the authorization granted during the OAuth flow. 

There are two types scopes:

  1. Space Separated: In some OAuth 2.0 implementations, scopes are represented as a space-separated list within the scope parameter. For example: scope=read write profile
  2. Comma Separated: In other OAuth 2.0 implementations, scopes are represented as a comma-separated list within the scope parameter. For example: scope=read, write, profile

🛑In the scope field when you write any scope you have to press ENTER KEY so that the scopes will get saved.

🛑Add fields process is same as Basic auth.

🛑Format to use response of authorization is `${context.authData.code}`. Replace code with key in the response you want to use.

Next step is to add required API’s and authenticate a user, the API’s you need to provide for your service is: 
                         

Access Token API:

Once the authorization code is generated, the next step is obtaining an access token. The primary purpose of an access token is to securely grant limited access to specific resources on behalf of a user or an application.

Example: 

                              

                          

🛑To use response of this block for is `${context.authData.accesstokencode.______ }`

Refresh Token API:

The refresh token serves to refresh the validity of the access token by generating a new token and extending the access token's duration.

Example: 

                       

                        

🛑To use response of this block for is `${context.authData.refreshtokencode.______ }`

Revoke Token API:

If you wish to disable an access or refresh token, simply send a request to the /revoke endpoint of the appropriate authorization server.

Example: 

                   

🛑To use response of this block for is `${context.authData.revoketokencode.______}`

Test Me API:

Same as basic auth

Example:

        

🛑Connection label is same as basic auth.

🛑Using try/catch in the code is a best practice for catching errors and debugging and in return always add response.data


How to create Actions 

We have successfully completed the authentication process now the next step is to create the desired action for the plugin. To create the action, click on create action->then provide all necessary information about the action

Add additionally required scopes

To perform the particular action if any other scopes is required enter it in the action scopes.

Now we have to write Action JSON:

The concept of "action JSON" in a viaSocket plugin refers to the structured JSON format used to define the fields of an action that are selected by the user when he/she uses that plugin. This JSON structure typically includes text fields, dropdowns, input groups etc.

Here is a simplified version of what an action JSON might look like: 

[
   {
     "key": "username",
     "label": "username",
     "type": "string",
     "required": true,
     "list": false,
     "altersDynamicFields": false
   },
   {
     "key": "email",
     "label": "email",
     "type": "string",
     "required": true,
     "list": false,
     "altersDynamicFields": false
   },
   {
     "key": "contact",
     "label": "contact",
     "type": "dropdown",
     "required": true,
     "list": false,
     "altersDynamicFields": false
   }
]

🛑To Get value of the field use `${context.inputData.field_key}`

🛑To know more about the JSON and its fields types refer the doc https://viasocket.com/faq/create-plugin

🛑For escape Json use https://www.freeformatter.com/json-escape.html#before-output

Final perform API:

The last step to complete the action is to add a final perform API. This API is responsible for performing the action.

Example: 


How to create Trigger

In viaSocket, a trigger is an event that starts your flow. It acts as the initial stimulus to commence an automated workflow whenever a particular event occurs. 

viaSocket provide two types of triggers you can choose according to your use case:

                                

These are designed to respond immediately to a specific event or condition. When the criteria for the trigger are met, the associated actions or processes are executed without delay. 

For instant triggers webhook are used. 

🛑Webhook Url is url you need to provide at the time of webhook creation. Pass its context `${context.inputData.hookurl} so when the trigger is included in the flow it automatically considers webhook of the flow to trigger.

🛑JSON part is same as action JSON. 

Next step is to add required API’s for create instant trigger, the API’s you need to provide for your service is: 

                 

Add PerformList API

🛑In this API you can add sample webhook payload or a GETapi which return response as webhook get when event performed.

Example: 

                

Add Perform Subscribe API:

Example: 

                       

ADD PerformUn-Subscribe API:

🛑Use above created webhook Id to delete that webhook. Format to use that webhook ID is `${context?.inputData?.performSubscribe.id} 

Example: 

                 

Unlike instant triggers, scheduled triggers are designed to activate at predetermined times or intervals. In viaSocket, scheduled triggers fetch data from the server every 15 minutes, and developers can use GET APIs to check and process data created or updated within the last 15 minutes, using JavaScript functions to filter and return the relevant data.

For create schedule trigger, the API’s you need to provide for your service is: 

                          

 

                          

Add PerformList API

🛑In this API you can add sample webhook payload or a GETapi which return response as webhook get when event performed.

Example: 

Add Perform API

🛑In this API you can add sample webhook payload or a GETapi which return response as webhook get when event performed.

Example: