DocStarBuilt with DocStar

Dynamic Options Display Through API Call in MSG91 Bot

Introduction

Dynamic options in a chatbot allow you to fetch and display real-time data to users based on their selections, rather than relying on static options. This makes the bot more intelligent, interactive, and personalized, creating a smoother user experience. By dynamically fetching options via an API call, you can handle a wide range of use cases — from country → state selections to product catalogs — without manually updating the bot.

This approach is a game changer for chatbots:

  • Users see only relevant, up-to-date options.

  • It reduces manual maintenance and errors.

  • It enables more complex conversational flows with minimal effort.

In this guide, we’ll demonstrate how to implement dynamic option display in MSG91 by letting users select a country (India, USA, China) and fetching 5 corresponding states through an API call.


Step 1: Create a Dummy Bot

Screenshot 2025-10-23 2.00.40 PM.png
  1. Go to the MSG91 Bot panel.

  2. Create a new bot named “Country → State Selector”.

  3. Add the first message card:

    • Message: “Select a country:”

    • Options: India, USA, China

  4. Save the user response in a variable:

    country_selected
    

Step 2: Set Up API Call Using Plugin Node

Refer to the image attached

Screenshot 2025-10-23 2.05.06 PM.pngScreenshot 2025-10-23 2.04.37 PM.png
  1. Add a Plugin node from the Connections section to call a dummy API that fetches random states for the selected country.

    • Alternatively, you can use an API node for the same task.

  2. Once you click Get Response, you can view the API response

    Screenshot 2025-10-23 2.05.54 PM.png
  3. Save the entire response in a variable named:

    states
    
    • Variable type: Array

  4. Drag a Message Card and select List type for the body content.

  5. Configure Dynamic Option Buttons:

    • Select Variable: states (this stores the API response in array format)

    • JSON Path for Title: state (each object in the array has the key state storing the state name)

    • Description: Skip this since we don’t have any description field.


Step 3: Display Dynamic Options

  • When the user sees the message card, they will now see 5 dynamic options corresponding to the selected country.

  • Save the user selection in a variable:

    state_selected
    

Step 4: Iteration and Refresh

  • Every time a new country is selected, make a fresh API call.

  • Ensure states overwrites the previous response.

  • Always maintain the format as array of objects with key state.


Step 5: Using the Selected State

Screenshot 2025-10-23 2.08.19 PM.png
  • Use state_selected for further logic or API calls.
    Example:

    "You selected {{state_selected}} from {{country_selected}}."
    

5. Output

Everytime user selects a country the bot fetches API response and display it to the end user

Screenshot 2025-10-23 2.11.20 PM.png

Screenshot 2025-10-23 2.12.22 PM.png

For any further queries you can reach out to us at [email protected]