cancel
Showing results for 
Search instead for 
Did you mean: 

Webhook Call Response

Raiaan
Explorer
0 Kudos

How can I access the response from a webhook call within SAP CAI?

Accepted Solutions (1)

Accepted Solutions (1)

Dan_Wroblewski
Developer Advocate
Developer Advocate

I think there was a misunderstand of how the 2 capabilities work involving calling an API.

Inside an action, you can call an API in 2 ways:

  1. Use "Connect External Service → Consume API Service" Consume External Service" to call any API and get the response in the api_service_response object. Once you have the response, you can use it in a message or save some of the data to memory or use it any other way. This is described here: https://help.sap.com/docs/SAP_CONVERSATIONAL_AI/a4522a393d2b4643812b7caadfe90c18/6791b54dc72c4b64ad9...

So ... in your response above, the format of the response is designed to automatically display as a message whatever is in the content field. But `$(property.Response)` would have no meaning for the chatbot, except as text. Your webhook has to send whatever text you want to be displayed in the message, in the format as described in the link above.

Answers (1)

Answers (1)

dtephan
Participant
0 Kudos

The webhook response will directly be added to the bot response. The replies will be added to the messages and the conversation node will impact memory and language. More details can be found here.

If you want to use an API where the response needs to be transformed or only parts of the response should be used in further actions please refer to "consume API service" action.

Raiaan
Explorer
0 Kudos

Let's say I retrieve a count of items from a webhook call, say 5. If I now want to send a text message to the user that says "You have 5 items in your inventory" what is the syntax to access that webhook response value (5)?

dtephan
Participant
0 Kudos

Webhooks need to match the following response structure:

{
  "replies": [
    {
      "type": "text",
      "content": "Hello world!"
    }
  ],
  "conversation": {
    "language": "en",
    "memory": {
      "user": "Bob"
    }
  }
}

If the API called in your case does not match this structure "Consume API service" needs to be used instead of Webhook. The response of Consume API Service can be accessed with {{api_service_response}} afterwards.

Raiaan
Explorer
0 Kudos

I'm using a middleware so I need to use a webhook. My response looks like this

What's the syntax to access the "content" within CAI?