Functions and Apps

CSML provides a way to execute external code in any language of your choice via a Foreign Function Interface, represented by the Fn() keyword.

Here are some ideas for CSML integrations:

There are 2 ways you can augment your CSML chatbot by connecting it to other services: importing custom code, or installing CSML Apps.

Using CSML Apps

​CSML Apps are a great way to extend the capabilities of your CSML chatbot by integrating other products with your bot without writing any additional code. CSML Studio provides a number of available apps (more than 50 and growing!), that make it possible to integrate your chatbot with the most popular services and applications on the market.

Example: Giphy app

For instance, if you are looking to add some fun Gifs to your bot, you can try our Giphy integration. To get started, go to Functions > Apps directory > Giphy.

Simply click on Install, and you are done! Some apps require credentials or API keys, but this one does not. If that's the case you are prompted to add environment variables upon installation.

Then, to use the app in your code, you can use it like this:

do gifs = Fn("giphy", action="gif", query="hello")
say Image(gifs[0])
goto end
The above code will generate a nice gif automatically!

Using Custom Code

If you already have custom code that you would like to use in your chatbot, you can import it directly as a custom function in CSML Studio and use it without any change.

In CSML Studio, functions are run by default on AWS Lambda, which ensures maximum availability, scalability and security by isolating your code in separate containers. The supported runtimes are currently:

  • Nodejs v10.x and 12.x

  • Java 8 and 11

  • Python 2.7, 3.6, 3.7 and 3.8

  • Dotnetcore 2.1 and 3.1

  • Go 1.x

  • Ruby 2.5 and 2.7

To get started with AWS Lambda compatible deployment package in any language, you can refer to this documentation.

As an example, let's create a simple nodejs 12.x function that will return a random user from This code performs a simple GET request to and returns the first user in the returned array. The code is available here on github: download it or clone it to get started.

Creating the function

To test this program, simply run node test.js at the root of the project. You should see something like the following:

Creating a deployment package

At the root of the project, run the command zip -r9 ../ .. This will create a deployment package for your function, that you will be able to import in CSML Studio.

Uploading to CSML Studio

In the sidebar, click on Functions > Add a new function. In the function creation page, upload your deployment package, give your function a distinctive and unique name such as getRandomUser, leave index.handler as your function's main handler and select nodejs12.x as the runtime.

You can leave the sections below as is for now; if your function took any argument or required any environment variable, this is where you would configure it.

Once you are done, simply save. You can now use your function in your CSML Chatbot, like this:

do user = Fn("getRandomUser")
say "The random user's name is: {{}} {{}}"
goto end