ChatGPT Integration Example: NPS Survey Response with Moderation
Tags: chatgpt, webmethods, integration, api
Published: 2023-03-22 15:28:16

---
title: ChatGPT Integration Example: NPS Survey Response with Moderation
published: true
date: 2023-03-17 09:56:02 UTC
tags: chatgpt, webmethods, integration, api
canonical_url: https://tech.forums.softwareag.com/t/chatgpt-integration-example-nps-survey-response-with-moderation/276069
---

 

### Overview

This [webMethods.io Integration](https://www.softwareag.cloud/site/product/webmethods-io-integration.html#/) workflow example sends automated NPS survey responses generated by the [webMethods.io ChatGPT API Connector](https://tech.forums.softwareag.com/t/webmethods-io-chatgpt-api-connector-available-now/268371).

### Steps

1. As this will be an API, create a webhook trigger. ![image](https://global.discourse-cdn.com/techcommunity/original/3X/8/7/87ccca963f769044a871145ec878ff8de81145cd.png)

The body of the post will contain the NPS data as follows:

```
{
 "email": "example@softwareag.com",
  "score": "10",
  "comments": "very good software. I like it a lot”
}

```

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/3/6/36c42610c2e811e3d1e45e086febff8a690a761e_2_417x375.png)](https://global.discourse-cdn.com/techcommunity/original/3X/3/6/36c42610c2e811e3d1e45e086febff8a690a761e.png "image")

2.Just to help with debugging I insert a logger after the webhook and log the payload to help during testing.

![image](https://global.discourse-cdn.com/techcommunity/original/3X/d/4/d4b3cbfa42469b414225c03b7f8d6c98ad19a7a6.png)

3.Next to moderate the input add the ChatGPT connector and provide the API Key:

![image](https://global.discourse-cdn.com/techcommunity/original/3X/7/9/79e7f9abfb236be046fd02fc7653e3e22a75cb13.png)

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/1/3/13bb2ace96c0db4d58d31d5cb3a6c080ea3d2339_2_409x374.png)](https://global.discourse-cdn.com/techcommunity/original/3X/1/3/13bb2ace96c0db4d58d31d5cb3a6c080ea3d2339.png "image")

Then select the Create Moderation action:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/a/4/a417fadd550618158f719d9e144aedb3b77634b5_2_411x375.png)](https://global.discourse-cdn.com/techcommunity/original/3X/a/4/a417fadd550618158f719d9e144aedb3b77634b5.png "image")

4.Map the provided comments to the input of the create moderation action:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/5/f/5f1fb9752c349c054d60dabf8f2479619cc09dfc_2_517x343.png)](https://global.discourse-cdn.com/techcommunity/original/3X/5/f/5f1fb9752c349c054d60dabf8f2479619cc09dfc.png "image")

Press Next, and then test the action.

You see the results/scores returned from the moderation:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/0/7/07e299a9e983ed3551580be8ff93f260eb13540b_2_517x344.png)](https://global.discourse-cdn.com/techcommunity/original/3X/0/7/07e299a9e983ed3551580be8ff93f260eb13540b.png "image")

5.If all the moderation categories are false, then we’ll generate the AI completion, otherwise we’ll return a standard response. For this, I use the switch control, which I drop into the canvas

![image](https://global.discourse-cdn.com/techcommunity/original/3X/8/2/82b83542bb3b7c4d1a11c839dd6d1ba74f231fa1.png)

6.The default condition takes this to a return data on sync webhook action which just returns a pre-created thank you response, which then links to the end action:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/c/6/c6163cbac6b962fcd58601d6a606b63f13bd5fc5_2_517x61.png)](https://global.discourse-cdn.com/techcommunity/original/3X/c/6/c6163cbac6b962fcd58601d6a606b63f13bd5fc5.png "image")

> **Note:** the Access-Control-Allow-Origin with a null value was added so I could test this from an HTML page or a local application.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/a/2/a2c8e9dd5941afc38a4ce94309acd1a38b2776d3_2_517x345.png)](https://global.discourse-cdn.com/techcommunity/original/3X/a/2/a2c8e9dd5941afc38a4ce94309acd1a38b2776d3.png "image")

7.For the other action of the switch, add a ChatGPT connector and link this to the switch action.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/3/5/356e7c340690f4f3bb996c9049f3834202b278de_2_466x375.png)](https://global.discourse-cdn.com/techcommunity/original/3X/3/5/356e7c340690f4f3bb996c9049f3834202b278de.png "image")

8.Position your mouse over the arrow between the 2 nodes and select the settings icon:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/d/7/d798798cb871acaca642fbb2209c1d4d704cc96c_2_453x375.jpeg)](https://global.discourse-cdn.com/techcommunity/original/3X/d/7/d798798cb871acaca642fbb2209c1d4d704cc96c.jpeg "image")

9.Now configure the conditions for this transition by adding filters for all of the categories and match for false

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/4/5/45fe38cd929ac261cd82e7a2623a87af96ba3087_2_517x344.png)](https://global.discourse-cdn.com/techcommunity/original/3X/4/5/45fe38cd929ac261cd82e7a2623a87af96ba3087.png "image")

10.Ensure the other switch condition is set to the default case by clicking on the settings icon on that arrow and selecting ‘default’

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/b/5/b5a0bd26c28b968b51e9858109530350ab8dedb4_2_517x344.png)](https://global.discourse-cdn.com/techcommunity/original/3X/b/5/b5a0bd26c28b968b51e9858109530350ab8dedb4.png "image")

11.Your workflow should now look something like this:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/d/1/d1aea28dd8bf1417576dcdcac09fbf811ba01106_2_517x177.png)](https://global.discourse-cdn.com/techcommunity/original/3X/d/1/d1aea28dd8bf1417576dcdcac09fbf811ba01106.png "image")

12.Now we need to configure the Completion to generate the AI survey response.
13.Select the Create Completions action and configure it as follows:

a. Set Model to `text-davinci-003`  
b. Set Prompt to: `“Create me a response for an NPS survey with a score of “` leaving the cursor in the prompt box and clicking on the score data item from the webhook action.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/c/9/c98f5c2e3526cbf67b361f3b0b7edb515b3112fe_2_690x462.png)](https://global.discourse-cdn.com/techcommunity/original/3X/c/9/c98f5c2e3526cbf67b361f3b0b7edb515b3112fe.png "image")

c. Complete the rest of the prompt as follows: `, and where the following comments were provided:`  
d. Then add the comments to the prompt, so the prompt in total should look something like the following:  
`Create me a response for an NPS survey with a score of {{$request.body.score}}, and where the following comments were provided: {{$request.body.comments}}`  
e. Set the temperature to `0.7` (or higher for a more random answer, or lower for a more consistent and deterministic answer).  
f. Set max\_tokens to `4000`  
g. Your mapping should then look like this:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/e/b/ebd2d18e1632531c8d8b052b6e2fd93ca8d0d653_2_517x344.png)](https://global.discourse-cdn.com/techcommunity/original/3X/e/b/ebd2d18e1632531c8d8b052b6e2fd93ca8d0d653.png "image")

14.Press next, then “Test” the action with the test button and you should see a response from the ChatGPT davinci engine:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/3/9/39080c44f56b7688b34bb7b8e3bdad3828efafcb_2_517x345.png)](https://global.discourse-cdn.com/techcommunity/original/3X/3/9/39080c44f56b7688b34bb7b8e3bdad3828efafcb.png "image")

15.Press Done.

16.Now we’ll moderate the response from ChatGPT for safety by adding another moderation action from ChatGPT and passing the text response from ChatGPT to the moderation API.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/7/a/7aef9a3f3cfe48d12412a555f9e79cc2243252b8_2_517x186.png)](https://global.discourse-cdn.com/techcommunity/original/3X/7/a/7aef9a3f3cfe48d12412a555f9e79cc2243252b8.png "image")

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/d/5/d5f51bcf97cff59e6c2f77e27de4f2bc32d3514a_2_517x343.png)](https://global.discourse-cdn.com/techcommunity/original/3X/d/5/d5f51bcf97cff59e6c2f77e27de4f2bc32d3514a.png "image")

17.Press Next and Test this response.

18.Lastly, like the previous moderation, we’ll add a switch with the same checks. If all are false we link to a new return data on sync, otherwise we link to the pre-created response.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/c/8/c8cc9a55bc73c881a321288e6d5e3cc24653b1ba_2_517x188.png)](https://global.discourse-cdn.com/techcommunity/original/3X/c/8/c8cc9a55bc73c881a321288e6d5e3cc24653b1ba.png "image")

19.Lastly, we just need to configure the API response on the return data sync on webhook mapping in the response from ChatGPT:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/7/2/722888b5d559bb118c49d5d1bca1b08c28d638e6_2_517x344.png)](https://global.discourse-cdn.com/techcommunity/original/3X/7/2/722888b5d559bb118c49d5d1bca1b08c28d638e6.png "image")

You can then test the whole integration:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/c/b/cb7fd35fbe4dabf82dcc7807e324145147ae387d_2_517x304.jpeg)](https://global.discourse-cdn.com/techcommunity/original/3X/c/b/cb7fd35fbe4dabf82dcc7807e324145147ae387d.jpeg "image")

You can also download the workflow archive below and simply import it under your [webMethods.io](http://webMethods.io) Integration project:

[NPS Survey Response (with moderation).zip](https://tech.forums.softwareag.com/uploads/short-url/xdvmipUBKWxIVHrcLEoARrSoRez.zip) (91.0 KB)

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/c/1/c18138b32dc386ab1a958af72e85e053d1fb4e08_2_517x105.png)](https://global.discourse-cdn.com/techcommunity/original/3X/c/1/c18138b32dc386ab1a958af72e85e053d1fb4e08.png "image")

Note that you will be asked to connect to your OpenAI account and to provide an API key:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/6/6/662ea49c02f6dec1351da348370615cf29306a87_2_511x375.png)](https://global.discourse-cdn.com/techcommunity/original/3X/6/6/662ea49c02f6dec1351da348370615cf29306a87.png "image")

You can register for an OpenAI account from here: [OpenAI API](https://platform.openai.com/overview). After you login, you will need to upgrade your account and create an API key from your account menu.

To learn more about how you can integrate the [webMethods.io ChatGPT API Connector](https://tech.forums.softwareag.com/t/webmethods-io-chatgpt-api-connector-available-now/268371) with any application, you can watch our demos (we show the steps on how to register for an OpenAI account and create several workflows from scratch):

- [Demo: Generative AI (ChatGPT API connector for webMethods.io Integration) Augmenting Human Capabilities](https://tech.forums.softwareag.com/t/demo-generative-ai-chatgpt-api-connector-for-webmethods-io-integration-augmenting-human-capabilities/275028)
- [Demo: Automate and embed ChatGPT in any app with webMethods.io](https://tech.forums.softwareag.com/t/demo-automate-and-embed-chatgpt-in-any-app-with-webmethods-io/276066)

All connectors available in [webMethods.io](http://webMethods.io) Integration are listed here [Categories - webMethods.io Integration](https://docs.webmethods.io/integration/connectors/connector).

> If you are new to [webMethods.io](http://webMethods.io) Integration and want to try it, please refer to this [Getting Started with webMethods.io beginner’s guide](https://tech.forums.softwareag.com/t/getting-started-with-webmethods-io-a-beginners-guide/276051) and sign up here [Sign up - Software AG Cloud](https://signup.softwareag.cloud/#/basic?product=webmethodsioint) for a free forever account.

[Read full topic](https://tech.forums.softwareag.com/t/chatgpt-integration-example-nps-survey-response-with-moderation/276069)