Skip to main content

HTTP API Logic Hooks

These logic hooks are used for managing HTTP requests and handling their responses. They are used for interacting with APIs, injecting responses into systems, and controlling data flow based on API interactions.

Make HTTP GET Request

This logic hook can be used to call a custom HTTP API endpoint. It can be used only as a User Step. This guide explains how to set up a logic hook in Botium to make an HTTP GET request to a specified URL.

Steps:

  1. On the left navigation pane, head to Botium Tools & Settings > Test Sets > Your Test Set > Test Cases
  2. Click the + NEW button to add a new Convo, or select a previously created test case from the list.
  3. Add a new + USER STEP
  4. Click the Edit icon, or anywhere inside the step, and search the list for the 'Make HTTP GET Request' logic hook.

  5. Configure the Logic Hook:

    1. URL to Call: Specify the URL to call. The URL can contain scripting memory variables. For example: https://my-custom-api/get-response/$msg($.messageText)
    2. Optional Headers: You can add headers if you wish by clicking the ADD NEW HTTP HEADER button. These are entered as key/value pairs.

  6. Click the APPLY CHANGES button to complete the step entry.

Example Botium Script

In this example, the chatbot answers to “give me 2” with “2”. The Scripting Memory Function $msg is used to extract the chatbot text response from the message (JSON-Path expression $.messageText) and hand it over to an API call. So the URL will be https://jsonplaceholder.typicode.com/posts/2.
#me
give me 2

#bot
2
HTTPGET https://jsonplaceholder.typicode.com/posts/$msg($.messageText)
Add New Headers Using the Following Format
HTTPGET https://jsonplaceholder.typicode.com/posts/$msg($.messageText) | 
ARG-HEADERS-[{"name":"Someheaderkey","value":"someheadervalue"}]

Explanation:

  • HTTPGET
          https://jsonplaceholder.typicode.com/posts/$msg($.messageText)
    makes an HTTP GET request to the URL https://jsonplaceholder.typicode.com/posts/2, where 2 is extracted from the chatbot's response using the $msg($.messageText) function.
  • Headers can be added using the ARG-HEADERS parameter to include additional key/value pairs in the request.

Make HTTP POST Request

This logic hook can be used only as a User Step. This guide explains how to set up a logic hook in Botium to make an HTTP POST request to a specified URL.

Steps:

  1. On the left navigation pane, head to Botium Tools & Settings > Test Sets > Your Test Set > Test Cases
  2. Click the + NEW button to add a new Convo, or select a previously created test case from the list.
  3. Add a new + USER STEP
  4. Click the Edit icon, or anywhere inside the step, and search the list for the 'Make HTTP POST Request' logic hook.

  5. Configure the Logic Hook:

    1. URL to Call: Specify the URL to call. Both the URL and the Request Body can contain scripting memory variables.
    2. Request Body: Specify the request body. You can leave this parameter empty to send an empty POST body.
    3. Optional Headers: You can add headers if you wish by clicking the ADD NEW HTTP HEADER button. These are entered as key/value pairs.

  6. Click the APPLY CHANGES button to complete the step entry.

Example Botium Script

In this example, we demonstrate a HTTP POST with Body (in begin section)
#begin
HTTPPOST https://jsonplaceholder.typicode.com/posts | { "username": "Joe", "userId": 1 }

#me
Hello!
Add New Headers Using the Following Format
HTTPPOST https://jsonplaceholder.typicode.com/posts | 
{ 
  "username": "Joe", 
  "userId": 1 
} | 
ARG-HEADERS-[{"name":"Someheaderkey","value":"someheadervalue"}]

Explanation:

  • HTTPPOST https://jsonplaceholder.typicode.com/posts | { "username":
          "Joe", "userId": 1 }
    makes an HTTP POST request to the URL https://jsonplaceholder.typicode.com/posts with a body containing {"username": "Joe", "userId": 1}.
  • Headers can be added using the ARG-HEADERS parameter to include additional key/value pairs in the request.

Inject HTTP GET Response

This logic hook can be used to call a custom HTTP API and inject the response content into a User or Bot Message. It can be used as either a Bot or User Step.

Overview:This guide explains how to set up a logic hook in Botium to extract a chatbot's text response, send it to an API, and use the API response as the chatbot's reply.

In this example, the Scripting Memory Function $msg extracts the chatbot's text response from the message using the JSON-Path expression $.messageText. This extracted response is sent to an API call. The API response's body field is then injected back into the messageText field, which will be used in the Botium pipeline as the text response for assertions.

Steps:

  1. On the left navigation pane, head to Botium Tools & Settings > Test Sets > Your Test Set > Test Cases
  2. Click the + NEW button to add a new Convo, or select a previously created test case from the list.
  3. Add a new + USER STEP or + BOT STEP
  4. Click the Edit icon, or anywhere inside the step, and search the list for the 'Inject HTTP GET Response' logic hook.

  5. Configure the logic hook:

    1. URL to Call: Enter the URL for the HTTP GET request. For example: https://jsonplaceholder.typicode.com/posts/$msg($.messageText)
    2. JSON-Path Extractor: Specify the JSON-Path expression to extract the desired part of the response. For example:$.body
    3. Attribute to Set: Set the attribute in the message where the extracted response will be injected. For example:messageText

  6. Click the APPLY CHANGES button to complete the step entry.

Example Botium Script

#me
give me 2

#bot
SETFROMHTTPGET 
  https://jsonplaceholder.typicode.com/posts/$msg($.messageText) 
  | $.body 
  | messageText
Add New Headers Using the Following Format
SETFROMHTTPGET 
  https://jsonplaceholder.typicode.com/posts/$msg($.messageText) 
  | $.body 
  | messageText 
  | ARG-HEADERS-[{"name":"Someheaderkey","value":"someheadervalue"}]

Explanation:

  • SETFROMHTTPGET initiates the HTTP GET request.
  • The URL https://jsonplaceholder.typicode.com/posts/$msg($.messageText) uses the $msg($.messageText) function to insert the chatbot’s text response.
  • | $.body | messageText indicates that the API response's body will be injected back into the messageText field.
  • ARG-HEADERS is used to add custom headers to the API request.

Inject HTTP POST Response

This logic hook can be used to call a custom HTTP API and inject the response content into a User or Bot Message. It can be used as either a Bot or User Step.

This guide explains how to set up a logic hook in Botium to make an HTTP POST request, extract the response content, and use it as the chatbot's reply.

Steps:

  1. On the left navigation pane, head to Botium Tools & Settings > Test Sets > Your Test Set > Test Cases
  2. Click the + NEW button to add a new Convo, or select a previously created test case from the list.
  3. Add a new + USER STEP or + BOT STEP
  4. Click the Edit icon, or anywhere inside the step, and search the list for the 'Inject HTTP POST Response' logic hook.

  5. Configure the Logic Hook:

    1. URL to call: Specify the URL to call.
      Tip: Both the URL and the Request Body can contain scripting memory variables. For example;
      • URL: https://my-custom-api/post-response/$msg($.messageText)
      • Request Body: { "title": "$msg($.messageText)" }
    2. Request Body: Set the body of the request. You can leave this parameter empty to send an empty POST body.
    3. JSON-Path Extractor: Add your JSON extractor here to extract the data item from the HTTP POST JSON response.
    4. Attribute to Set: Specify the Botium Core field to set.
    5. Optional Headers: If you wish to add new headers, click the ADD NEW HTTP HEADER button. These are added as key/value pairs.

  6. Click the APPLY CHANGES button to complete the step entry.

Example Botium Script

In this example, the user's input "give me something" is sent in an API call to https://jsonplaceholder.typicode.com/posts. The API response's body field is then injected back into the messageText field, which will be used in the Botium pipeline as the text response for assertions.
#me
give me something

#bot
SETFROMHTTPPOST 
  https://jsonplaceholder.typicode.com/posts 
  | { "title": "$msg($.messageText)", "body": "$msg($.messageText)", "userId": 1 } 
  | $.body 
  | messageText
You said: give me something
Add New Headers Using the Following Format
SETFROMHTTPPOST 
  https://jsonplaceholder.typicode.com/posts 
  | { "title": "$msg($.messageText)", "body": "$msg($.messageText)", "userId": 1 } 
  | $.body 
  | messageText 
  | ARG-HEADERS-[{"name":"Someheaderkey","value":"someheadervalue"}]

Explanation:

  • SETFROMHTTPPOST initiates the HTTP POST request.
  • The URL https://jsonplaceholder.typicode.com/posts uses the $msg($.messageText) function to insert the chatbot’s text response into the request body.
  • | $.body | messageText indicates that the API response's body will be injected back into the messageText field.
  • ARG-HEADERS is used to add custom headers to the API request.

Inject HTTP GET Response into Parameter Store

This logic hook can be used to call a custom HTTP API and inject the response content into the parameter store. This allows you to create a new variable or overwrite an existing one. It can be used as either a Bot or User Step.

This guide explains how to set up a logic hook in Botium to call an HTTP GET API, extract the response content, and store it in the parameter store.

Steps:

  1. On the left navigation pane, head to Botium Tools & Settings > Test Sets > Your Test Set > Test Cases
  2. Click the + NEW button to add a new Convo, or select a previously created test case from the list.
  3. Add a new + USER STEP or + BOT STEP
  4. Click the Edit icon, or anywhere inside the step, and search the list for the 'Inject HTTP GET Response into Parameter Store' logic hook.

  5. Configure the Logic Hook:

    1. URL to Call: Specify the URL for the HTTP GET request. The URL can contain scripting memory variables. For example: https://jsonplaceholder.typicode.com/posts/$msg($.messageText)
    2. JSON-Path Extractor: Specify the JSON-Path expression to extract the desired part of the response. For example: $.title
    3. Parameter Store Variable: Set the parameter name in the parameter store where the extracted response will be injected. For example: apiResponse
    4. Optional Headers: You can add headers if you wish by clicking the ADD NEW HTTP HEADER button. These are entered as key/value pairs.

  6. Click the APPLY CHANGES button to complete the step entry.

Example Botium Script:

In this example, the user's input "give me 2" is sent in an API call to https://jsonplaceholder.typicode.com/posts/2. The API response's title field is then injected into the parameter store as the variable apiResponse.

#me
give me 2

#bot
2
SETPARAMETERSTOREFROMHTTPGET https://jsonplaceholder.typicode.com/posts/$msg($.messageText) | $.title | apiResponse

#me
$apiResponse

#bot
You said: qui est esse
Add New Headers Using the Following Format:
SETPARAMETERSTOREFROMHTTPGET
https://jsonplaceholder.typicode.com/posts/$msg($.messageText)
$.title
apiResponse
ARG-HEADERS-[{"name":"Someheaderkey","value":"someheadervalue"}]

Explanation:

  • SETPARAMETERSTOREFROMHTTPGET initiates the HTTP GET request.
  • The URL https://jsonplaceholder.typicode.com/posts/$msg($.messageText) uses the $msg($.messageText) function to insert the chatbot’s text response.
  • $.title | apiResponse indicates that the title field from the API response will be extracted and stored as the variable apiResponse in the parameter store.
  • ARG-HEADERS is used to add custom headers to the API request.

Inject HTTP POST Response into Parameter Store

This logic hook can be used to call a custom HTTP API and inject the response content into the parameter store. This allows you to create a new variable or overwrite an existing one. It can be used as either a Bot or User Step.

This guide explains how to set up a logic hook in Botium to call an HTTP POST API, extract the response content, and store it in the parameter store.

Steps:

  1. On the left navigation pane, head to Botium Tools & Settings > Test Sets > Your Test Set > Test Cases
  2. Click the + NEW button to add a new Convo, or select a previously created test case from the list.
  3. Add a new + USER STEP or + BOT STEP
  4. Click the Edit icon, or anywhere inside the step, and search the list for the 'Inject HTTP POST Response into Parameter Store' logic hook.

  5. Configure the Logic Hook:

    1. URL to call: Specify the URL to call.
      Tip: Both the URL and the Request Body can contain scripting memory variables. For example;
      • URL: https://my-custom-api/post-response/$msg($.messageText)
      • Request Body: { "title": "$msg($.messageText)" }
    2. Request Body: Set the body of the request. You can leave this parameter empty to send an empty POST body.
    3. JSON-Path Extractor: Add your JSON extractor here to extract the data item from the HTTP POST JSON response. For example: $.username
    4. Parameter Name: Set the parameter name in the parameter store where the extracted response will be injected. For example: name
    5. Optional Headers: You can add headers if you wish by clicking the ADD NEW HTTP HEADER button. These are entered as key/value pairs.

  6. Click the APPLY CHANGES button to complete the step entry.

Example Botium Script:

In this example, a POST request is made with a body containing user information. The username from the API response is stored as name in the parameter store.
#begin
SETPARAMETERSTOREFROMHTTPPOST
https://jsonplaceholder.typicode.com/posts
{ "username": "Joe", "userId": 1 }
$.username
name

#me
Hello $name!

#bot
You said: Hello Joe!
Add New Headers Using the Following Format:
SETPARAMETERSTOREFROMHTTPPOST
https://jsonplaceholder.typicode.com/posts
{ "username": "Joe", "userId": 1 }
$.username
name
ARG-HEADERS-[{"name":"Someheaderkey","value":"someheadervalue"}]

Explanation:

  • SETPARAMETERSTOREFROMHTTPPOST initiates the HTTP POST request.
  • The URL https://jsonplaceholder.typicode.com/posts uses the $msg($.messageText) function to insert the chatbot’s text response into the request body.
  • $.username | name indicates that the username field from the API response will be extracted and stored as the variable name in the parameter store.
  • ARG-HEADERS is used to add custom headers to the API request.

Was this article helpful?

0 out of 0 found this helpful