Using JavaScript with Integromat

Integromat is awesome, but sometimes it’s easier to write a few lines of JavaScript to put into your scenario.

It’s actually quite easy to do, using Google Cloud Functions.

Here’s a super simple way to re-implement the built in replace(string;old;new) function using JavaScript.

Built In Function

This is the sensible way to do this, using the built in Integromat function:

img

The built in functions are actually quite powerful, but they certainly have limits. There are some things that would be much easier to implement in JavaScript, especially if you are already fluent in it. Unfortunately I’m not particularly fluent, which is why I made the Python version of this article first.

JavaScript

1.. Create a new Google Cloud Function by clicking here. You might have to create a Google Cloud account if you don’t already have one. The usage in this example is within the free tier.

2.. Fill in the name, select 128 MB memory, and leave the runtime as Node.js 6:

3.. Next, add the code, which can be found at this gist, and set the function to match the function named within the code. Also, set the region to europe-west-1to be closer to the Integromat servers, resulting in a faster load time.

goofle-cloud-js-2

4.. Find the Trigger URL for this function by clicking on it and clicking “Trigger”. You’ll need to copy this for use later.

google-cloud-js-3

5.. Now go back to Integromat and create a new HTTP “Make a request” module. Set it up with the URL as the trigger from step 4, with the GET variables for “old_string”, “text_to_find”, and “text_to_replace”. The output should be the string, but with old replaced by new. This should work the same as the built in function.

img

You can now use the output of that anywhere else in the scenario!

Basic security can be added with an API Key type structure (with a hardcoded key in the function), otherwise anyone will be able to “call” the function if they know the URL. If I have time I will write more on that later.