Articles on: Custom Code & Design

🔧 Import JS code

Example link: https://creator.celestory.io/project/EXs9_365N

Importing your code allows you as developer to create your own Celestory block.

1.Create a ⬛ Run Javascript





This allows you to:

- create incoming trigger points

- create outgoing value points

2. Import your JS code



The editor of the block ⬛ Run Javascript contains a field to insert your JS code.



In this example of JS code using a ⛅ weather service:

const city = celestoryPoints.get('city', 'Paris');

const location = await fetch(https://cors-anywhere.herokuapp.com/https://www.metaweather.com/api/location/search?query=${city});const
if (locationData && locationData0] && locationData[0].woeid) { const woeid = locationData[0].woeid; const weather = await fetch([https://cors-anywhere.herokuapp.com/https://www.metaweather.com/api/location/${woeid}
if (weatherData && weatherData.consolidated_weather && weatherData.consolidated_weather.length > 0) { celestoryPoints.set('city', city); celestoryPoints.set('weather', weatherData.consolidated_weather0].weather_state_name); celestoryPoints.set('temperature', weatherData.consolidated_weather[0
return; }}
celestoryPoints.set('city', city);celestoryPoints.set('weather', 'NOT_FOUND');celestoryPoints.set('temperature', 'NOT_FOUND');

3. Connect your bloc



- the incoming trigger point "city" down at left can be linked to a text variable from a Text Input or a user choice. So if the value of this text variable corresponds to a city of the service, this one will be recognized and the corresponding values will be synchronized. This incoming point is not mandatory, and by default the city is assigned in the the code JS in Paris.

- the outgoing value points in the bottom right-hand corner "city", "weather", "temperature" allows you to go foreign service search targets information corresponding to the selected city to transform them into the value that it is then

possible to assign to a variable in the graph.

https://storage.crisp.chat/users/helpdesk/website/2ed10c2017948c00/c7fa362b-563f-4e06-bb25-1d20a0_1mwvj81.png)

To send your datas to other services, see: Connect your data with 🔌 Zapier" class="csh-markdown csh-markdown-image">](<a href=https://storage.crisp.chat/users/helpdesk/website/2ed10c2017948c00/c7fa362b-563f-4e06-bb25-1d20a0_1mwvj81.png)

To send your datas to other services, see: Connect your data with 🔌 Zapier" loading="lazy"/>
or [🔌 Integromat

Updated on: 29/03/2021

Was this article helpful?

Share your feedback

Cancel

Thank you!