CSML Reference
  • Introduction
  • Installing CSML
  • Sending and Receiving Messages
    • Message Payloads
    • Custom Components
  • The Event
  • Memory
    • Using Variables in Messages
    • Temporary and Long-Term variables
    • Global variables
  • Navigating in a CSML Bot
  • Conditional Logic
  • External Code Execution
  • Native CSML Functions
  • Value Types
  • Automatic Type Inference
  • 📑CSML Studio Documentation
  • Standard Library
    • Keywords
    • Built-in Functions
    • HTTP Client
    • SMTP Client
    • Crypto Utilities
      • JWT
      • Hash, HMAC
      • Base64, Hex
    • String methods
    • Array methods
    • Object methods
    • Number methods
    • Generic methods
Powered by GitBook
On this page
  • Running App on CSML Studio
  • Executing App calls
  • Installing a custom nodejs App runtime

Was this helpful?

Edit on Git
Export as PDF

External Code Execution

PreviousConditional LogicNextNative CSML Functions

Last updated 4 years ago

Was this helpful?

The CSML engine is able to automatically handle the execution of any payload, any code, in any language, thanks to the built-in App() macro. With CSML Apps, you can integrate your own business logic, on your own servers, in your language of choice.

When used together with custom serverless function runtimes (cloud-based such as , , ), or on-premise with , or ), CSML Functions are a good way to execute custom business logic outside of the context of the conversation.

findweather:
  say "Let me query the weather in {{location}} for you..."
  do weather = Fn("weatherchannel", location = location)
  say "It will be {{weather.temperature}}°C tomorrow."

Deprecation notice: the original Fn() notation for calling Apps (formerly called Functions) in your CSML code has been replaced by the newer App() built-in as of CSML v1.5. Both notations will continue to work until CSML v2 is released, but this documentation will only reference the new App() usage from now on.

Running App on CSML Studio

When using the , the heavy setup of creating an App runtime is already done for you, which means that you can easily import functions in java, python, nodejs, go... without any additional setup, simply by uploading your code and calling the function in your CSML script.

CSML Studio also comes with that are installable in one-click.

Executing App calls

To execute external functions in any programming language when provided a fn_endpoint.

For example, when a App is called, a HTTP POST request will be performed to the provided fn_endpoint with the following payload:

{
    "client": {
        "bot_id": "unique-bot-id",
        "user_id": "unique-user-id",
        "channel_id": "unique-channel-id"
    },
    "function_id": "name_of_fn",
    "data": {
        "example": "somevalue",
        "someparam": 123,
        "obj_val": { "hi": "there" }
    }
}

The endpoint should return a JSON payload, formatted as follows:

{
    "data": data_to_return<JSON>
}

If the function fails, or returns an invalid payload, CSML will convert it as a Null value.

Installing a custom nodejs App runtime

Follow the instructions to install and add your own apps!

The following repository provides an easy way to run your own nodejs runtime:

AWS Lambda
Azure Functions
Google Cloud Functions
FnProject
OpenFaas
OpenWhisk
CSML Studio
many ready-to-use integrations
https://github.com/CSML-by-Clevy/csml-fn-endpoint-node