Sharing an action function (via the CLI)

The process of creating and sharing a new custom action step via the Block Store.

Sharing an action function (via the CLI)
The process of creating and sharing a new custom action step via the Block Store.

After reading this article you’ll know how to:

  • Create a function block
  • Publish the function block to the Block store
  • Release & install the block in your organization
  • Update the function block

Our platform expands its capabilities by presenting new features in the current-gen applications, one of which is the possibility of adding your own custom blocks to the application and sharing them via the block store. This article in particular explains how to create your own action function and then share it with other customers and organizations.

What is the Block Store?

The Block Store is where you can find blocks to build apps faster and easier. These blocks include actions, data sources, page components, and themes that you can add to your app with just a few clicks. For more information on the Block Store and its content please visit our article on it here.

Check if you have the Betty-Blocks CLI installed.

First, you will have to have the Betty Cli installed on your computer, to check if it is installed run the following command on your command line tool (Terminal or Command prompt):

$ bb –version

If it is installed, you will see the current version of the Cli you have installed. If you see an error message on your command-line tool, that means you do not have the Betty Cli installed. To do it properly, please visit our article on how to set up your low-code environment here.

See if your action step is ready.

You will need to have an action step that you want to share in the Block store. If you still haven’t written your action step, please visit our article on how to create your custom action step here.

Initialize a new block

To share your action step you will first need to put it inside of a block. To initialize a block you will need to run the following command:

$ bb blocks new <your-block-name>

This command will create a blocks folder in the root of your functions project and inside that folder, there will be a JSON file named by the given name. The JSON file will have the following structure:

 {

  "dependencies": [],

  "functions": [],

  "includes": []

 }

Dependencies

If a function in your block is importing external dependencies, you also need to include them in your block. For example, if you use lodash (Like the default hello world function) you do this as follows (there is no need to specify the version number because the CLI uses the version specified in the package.json file):

 {

  "dependencies": ["lodash"],

  "functions": ["sayHello 1.0"],

  "includes": []

 }

Functions

A function block can contain multiple functions. The functions key inside the JSON file will accept an array of string values that should trace back to the function names and versions in your project. If you have a folder structure like functions/say-hello/1.0 you can use it as follows in your block:

 {

  "dependencies": ["lodash"],

  "functions": ["sayHello 1.0", "deleteMany 1.4"],

  "includes": []

 }

This will create a function block that contains two functions Say Hello/1.0 and Delete Many/1.4.

Includes

It is also possible to include other files or folders outside your function directory. If you use a function that is declared in another file/folder you can use the includes to add them to your block. 

 {

  "dependencies": ["lodash"],

  "functions": ["sayHello 1.0", "deleteMany 1.4"],

  "includes": ["./utils", "./helpers/parse-name.js"]

 }

Publishing blocks

You can publish one or multiple blocks to the block store with the following command in your Command line:

$ bb blocks publish

With the result being:

? Which blocks do you want to publish? ›

◯   my-first-block

◯   my-second-block

Here you can navigate between blocks using the ↑  ↓ arrow keys and you can use either the spacebar or the ← and → arrow keys to select and deselect a block, you confirm your publication by pressing enter.

After a successful publication, you can view and manage your blocks in My Betty Blocks.

Dev blocks and Released blocks

Keep in mind that publishing a block with the CLI does not immediately make it available for other builders. To make it available you need to manually release (or update) your function block in your Block Store section

You can find your block by selecting ‘My Blocks’ and ‘Dev Blocks’ on the top left side under the ‘All’ tab.

 

Published block functions have the following states:

  • Dev - The block is in the Block Store but it cannot be shared with others yet.
  • Released - The block has been released and will be available for installation based on whoever you give permissions on the block to, they can install it like every other block in the block store.

After installing a function block the functions will be visible on the Action Steps page of the application you installed the block on.

Updating Block

To update your block you just have to run the publish command on your command line tool:

$ bb blocks publish

By following these steps, you’ll be able to create, update, and deploy custom action steps to the block store to help fellow users with their Betty Blocks application!

Do you want to discuss the creation of your action step with other developers? Check out our community!