Skip to main content

Web Service Module

Introduction

The WebService process module enables connecting LoyJoy to external APIs. As soon as the chat flow arrives at a WebService process module, a synchronous HTTP POST request is sent to the configured URL.

Typical Use Cases

Send variables and parameters from LoyJoy to a REST API in your IT infrastructure, and return new variables back from your REST API to LoyJoy.

How to Use the Module

HTTP request that will be sent to your REST API

The request body is structured as follows:

{
"process_definition_id": ...,
"process_instance_id": ...,
"params": {
"referrer": "http://example.org/referring_page",
"user-agent": "Mozilla/1.0N (Windows)",
...
},
"variables": {
"email": "john.smith@example.org",
"firstname": "John",
"gender": "male",
"lastname": "Smith",
"nps_score": "10",
...
}
}

The params and variables are examples. The params primarily are generated by the webbrowser. The variables are primarily generated by the process modules you have put into your experience (process-independent variables, process-specific variables).

HTTP response that your REST API can return optionally

The WebService REST API endpoint has to respond after a few seconds, or a timeout will occur and the process flow will proceed. Optionally, the response can provide variables to be set in the process instance:

{
"data": {
"variables": {
"some_key": "some_value"
}
}
}

Integrate the WebService process module with a Serverless Function

A typical use case would be to call a serverless function such as a Google Cloud Function from the WebService process module. To achieve this, simply enter the URL of your serverless function in the WebService process module.

For the implementation of a serverless function you can use any modern programming language and cloud platform. For Node.js you can find examples here.

Timeouts

The process module waits for a response from the server for around 20 seconds. If the server does not respond within this time, the process module will classify this as a timeout. There are multiple solutions to this problem.