🪄 Using ChatGPT to generate JavaScript for advanced workflow automations

Tape’s built in automation actions provide lots of capabilities to users out of the box. Still, in various scenarios one may need at least a little bit of code to get to that “last mile”.

Not every advanced Tape user is also a JavaScript developer - to speed things up we recommend using ChatGPT to generate JavaScript that can be simply copied 1:1 into the “Execute Script” action in Tape and will simply work. We use ChatGPT for this example, a free account should be sufficient.

The more accurate our prompt, the better the result will become. This guide shows how to write a great prompt to get a working code snippet for a simple example case. It should also work for more complicated cases in the same way.

Example 1: Extract the first email address from a text :email:

We receive a user input inside a Tape record, e.g. via an external form or via email to App. We would then like to extract the first email address from that string to proceed with storing the raw email address, e.g. to a contact.

We write an accurate prompt to phrase what we expect as a result:

You are supposed to write JavaScript that executes in a Node.js environment, and which is designed to be used inside the script environment of a low-code platform called “Tape”. The environment runs Node.js in version 18.

Acceptance criteria:

  • Your code should take a string input and extracts the first valid email address from that string

Additional requirements:

  • Your code should always log the result for debugging
  • Your provided dummy input should yield at least one valid email
  • Your code should include a comment with a hint on where the input variable should be added, and that this can “include your custom tokens and field values”.
  • Declare a new variable with a meaningful name that will hold the result

The prompt provides as much context and restrictions as possible, to allow using the code afterwards with minium effort. Note that only the bold part is actually describing “what should happen”, while the rest is more or less context. You can adjust that bold section to your requirements - we will change it in the next example.

In order to use the code, just create a workflow automation in Tape with a trigger of your choice, and add an “Execute script” action. You then need to only paste the generated code from ChatCPT, and ensure these two things.

  • Assign your input properly using your variable, e.g. the field value variable from your record
  • Assign the result to your declared script action variable for later use

After running the prompt, copying the code and creating your automation (including the previous two steps) it may look similar to this screenshot:

Note that I renamed my variable to result by clicking on it in the action header “Execute a script and save output result in …”.

The automation is now in place, we can create a record:

And here we go, a comment is created and shows the result we expected:

Note: For simplicity (and accuracity) of this guide, we use the first email address. You could also prompt to receive “the first apparent business email address”, or the “receipient email address” which may be more magic but also seems more volatile from a technical perspective. Feel free to try out whatever you come up with!

Example 2: Coming from PHP: find an alternative :anchor:

We know that many Tape partners, users and developers have worked with PHP in the past or are still using it. As Tape has no PHP support (and will not), it is crucial to be able to determine a JS way of “doing things” efficiently when solving real world problems.

This prompt attempts to assist with finding a replacement for the PHP function ucwords, which uppercases each word in a string. We use a similar prompt and provide the same descriptive context:

You are supposed to write JavaScript that executes in a Node.js environment, and which is designed to be used inside the script environment of a low-code platform called “Tape”. The environment runs Node.js in version 18.

Acceptance criteria:

  • Your code should behave equally to the PHP function “ucwords”

Additional requirements:

  • Your code should always log the result for debugging
  • Your provided dummy input should yield at least one valid email
  • Your code should include a comment with a hint on where the input variable should be added, and that this can “include your custom tokens and field values”.
  • Declare a new variable with a meaningful name that will hold the result

ChatGPT provides us with a meaningful result and also helpful inline comments. You can now repeat the steps from example #1 to leverage the received code snippet in Tape. :tada:

Wrapup

ChatGPT can speed up things significantly and as Tape uses default JavaScript syntax almost any code should run out of the box. Be sure to assign your variables and also check that you copy the full code into Tape to avoid errors. :information_source:

Have fun! :rocket:

:bulb: We are excited to hear what you come up with, and how it works you. Feel free to share your experience and also additions to this guide in the comments. :point_down:

2 Likes