Over a million developers have joined DZone.

Integrate a Chatbot With a Third-Party System (MovieDB)

DZone 's Guide to

Integrate a Chatbot With a Third-Party System (MovieDB)

See how to integrate a chatbot with a third-party system.

· AI Zone ·
Free Resource


After having several conversations with customers, colleagues, and partners about SAP Conversational AI, one feature always stands out: integration.

Chatbots offer a new user experience that, in many ways, are more efficient and effective than a human interaction, and there are many statistics to support that statement. However, very often, it’s hard for a chatbot to be helpful and valuable on its own. It needs to be able to retrieve information from other systems and present consolidated data to the user.

With many developers and customers not having the resources (skills or licenses) to build a middleware application from scratch for their integration purposes, I have decided to demonstrate an integration example using SAP Cloud Platform Integration (CPI).

The example in this blog is inspired by the movie bot tutorial originally developed by the SAP Conversational AI team.


This guide is intended for knowledge sharing purposes only. The steps presented here, including the accuracy and cleanliness of the code, security considerations, and overall steps are not to be considered best practices.


You must have:

  • An SAP Cloud Platform Integration-PI account
  • Basic knowledge of SAP Cloud Platform Integration
  • A free account with SAP Conversational AI (you can sign up here)
  • Read and understood Parts 1 & 2 of the movie bot tutorial

1. Forking and Configuring the Bot

1.1 Forking the Bot


1.2 Configuring the Bot

a) Once the forking process is complete, go to settings by clicking the cog icon.


b) Select the “Bot webhook base URL” box and type in your CPI runtime node.

Your runtime node should look something like this:

https://<Account Short Name>-iflmap.<SSL HOST>.<Landscape Host>/http.

For example: https://l0001-iflmap.hcisbp.eu1.hana.ondemand.com/http

Make sure to enter /http at the end of the URL because we will be using an http adapter later.


c) On the same screen click the Build tab at the top. Select the Discover skill and scroll down to the “_memory.yes” action.

d) Click the pencil icon to edit the action block.


e) Make sure “/discover-movies” is added to the URL and the POST method is selected.

f) Under Authentication: select basic authentication and enter your CPI tenant’s username and password.

g) Under Headers: add the field Content-Type application/json.

h) Under Body: use the default settings.




2. Getting Your MovieDB API URL and API Key

Go to link below and follow the steps:

  • 2.1 Create a MovieDB account
  • 2.2 Make sure you are logged in to your The Movie DB account
  • 2.3 Follow this link The Movie DB API and follow the steps to get your API key

It should look like this on MovieDB:


3. Building the Integration Flow

3.1 Getting Started

Go to your CPI tenant.

  • a) Create an integration package or use a pre-existing one of your liking.
  • b) Create a new integration flow of type Process Integration.

You are now ready to start building your integration flow.

3.2 Building the Integration Flow

  • a) Start by selecting an HTTPS adapter and dragging the line from Sender to Start.
  • b) Under the connection tab, make sure that you enter/do as shown in the screenshot.
  • c) Don’t change any other adapter settings.



4. Configuring Properties

Next, we want to extract the parameters from the incoming message from Conversational AI and save the parameters as properties for use in the MovieDB query.

  • a) Open the menu on the left and click the Transformation
  • b) Open the Script dropdown menu and select JavaScript.
  • c) Add the code below and save your data.



function processData(message) {
    var body = message.getBody(java.lang.String);
    var myObj = JSON.parse(body);
    var kind = myObj.conversation.memory.recording.type;
    var genreId = myObj.conversation.memory.genre.id;
    var language = myObj.conversation.language;
    var conversationId = myObj.conversation.id;

    message.setProperty("kind", kind);
    message.setProperty("genreId", genreId);
    message.setProperty("language", language);
    message.setProperty("conversationId", conversationId);


return message;

5. Querying the MovieDB

  • a) Add a request reply box, a receiver box outside the integration bus, and an http adapter connecting the two (as shown in the figure below).
  • b) Configure the http adapter as shown in the screenshot.
  • c) Replace the API_KEY field with your “api_key”.connection-api-db-movies

Now that we receive the response in the payload (body of the message), we can use the data and store it again in properties. We can use the stored data in our final response back to the bot.

  • d) Insert a script box of type JavaScript. See the figure below for how the integration flow looks so far.
  • e) Insert the following code in it



function processData(message) {
    var body = message.getBody(java.lang.String);
    var myObj = JSON.parse(body);

    var i, x = "";

    for (i in myObj.results) {
    x += myObj.results[i];

    var title = [myObj.results[0].title, myObj.results[1].title, myObj.results[2].title, myObj.results[3].title, myObj.results[4].title];
    var subtitle = [myObj.results[0].overview, myObj.results[1].overview, myObj.results[2].overview, myObj.results[3].overview, myObj.results[4].overview];
    var imageUrl = [myObj.results[0].poster_path, myObj.results[1].poster_path, myObj.results[2].poster_path, myObj.results[3].poster_path, myObj.results[4].poster_path];
    var buttonValue = [myObj.results[0].id, myObj.results[1].id, myObj.results[2].id, myObj.results[3].id, myObj.results[4].id];

    message.setProperty("title", title);
    message.setProperty("subtitle", subtitle);
    message.setProperty("imageUrl", imageUrl);
    message.setProperty("buttonValue", buttonValue);

return message;

5. Adding a Content Modifier That Contains the Final Payload That Goes Back to SAP Conversational AI

  • a) Add in a “Content Modifier”
  • b) In the message header, add in the authorization details from CAI, that would be your request token (find it in the settings of your bot’s page under token)

Note: If the number of characters in the content array exceeds 512, the bot shows No Reply.


  • c) Add in the code below under the Message Body tab


    "replies": [
            "type": "carousel",
              "title": "${property.title[0]}",
              "subtitle": "${property.subtitle[0]}",
              "imageUrl": "https://image.tmdb.org/t/p/w600_and_h900_bestv2${property.imageUrl[0]}",
              "buttons": [
                  "title": "View More",
                  "type": "web_url",
                  "value": "https://www.themoviedb.org/${property.kind}/${property.id[0]}"
              "title": "${property.title[1]}",
              "subtitle": "${property.subtitle[1]}",
              "imageUrl": "https://image.tmdb.org/t/p/w600_and_h900_bestv2${property.imageUrl[1]}",
              "buttons": [
                  "title": "View More",
                  "type": "web_url",
                  "value": "https://www.themoviedb.org/${property.kind}/${property.id[1]}"
              "title": "${property.title[2]}",
              "subtitle": "${property.subtitle[2]}",
              "imageUrl": "https://image.tmdb.org/t/p/w600_and_h900_bestv2${property.imageUrl[2]}",
              "buttons": [
                  "title": "View More",
                  "type": "web_url",
                  "value": "https://www.themoviedb.org/${property.kind}/${property.id[2]}"
              "title": "${property.title[3]}",
              "subtitle": "${property.subtitle[3]}",
              "imageUrl": "https://image.tmdb.org/t/p/w600_and_h900_bestv2${property.imageUrl[3]}",
              "buttons": [
                  "title": "View More",
                  "type": "web_url",
                  "value": "https://www.themoviedb.org/${property.kind}/${property.id[3]}"
              "title": "${property.title[4]}",
              "subtitle": "${property.subtitle[4]}",
              "imageUrl": "https://image.tmdb.org/t/p/w600_and_h900_bestv2${property.imageUrl[4]}",
              "buttons": [
                  "title": "View More",
                  "type": "web_url",
                  "value": "https://www.themoviedb.org/${property.kind}/${property.id[4]}"

(Optional) Add the following groovy script if you want to see how your payload looks like at the end of the integration flow.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import com.sap.it.api.mapping.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;

def Message processData(Message message) {

map = message.getProperties();
if (property_ENABLE_PAYLOAD_LOGGING.toUpperCase().equals("TRUE")) {
def header = message.getHeaders() as String;
def body = message.getBody(java.lang.String) as String;

String timeStamp = new SimpleDateFormat("HH:mm:ss.SSS").format(new Date());
String logTitle = timeStamp + " JSstep ";

def messageLog = messageLogFactory.getMessageLog(message);
if (messageLog != null) {
messageLog.addAttachmentAsString(logTitle, body, "text/xml");
return message;

6. Deploying and Testing Your Bot


You should be good to go now, but feel free to ask for support in the comments section below!

I’d love to hear from the community how this example can be enhanced through better code, instructions, or any other way.

Happy bot building everyone!

chatbots ,sap cloud platform integration ,cloud platform ,chatbot backend ,chatbot development ,chatbot platform ,api ,javascript ,ai chatbot ,ai

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}