/bolt.new-ai-integrations

Bolt.new AI and IBM Watson integration: Step-by-Step Guide 2025

Easily integrate Bolt.new AI with IBM Watson using our quick guide. Learn expert tips, proven steps, and best practices for seamless AI integration.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to integrate Bolt.new AI with IBM Watson?

 

Adding IBM Watson Dependency via package.json

 

Create or update your package.json file in your Bolt.new AI project to include the IBM Watson SDK dependency. Since Bolt.new AI does not offer a terminal, you add the dependency by editing your project file.


{
  "name": "my-bolt-ai-project",
  "version": "1.0.0",
  "dependencies": {
    "ibm-watson": "^7.4.0"
    // You can add other dependencies as needed
  }
}
  • Make sure this snippet is placed in your project's root package.json file.
  • This instructs the Bolt.new platform to include the IBM Watson SDK in your project.

 

Creating the IBM Watson Service File

 

Add a new TypeScript file to your project named ibmWatsonService.ts in the source folder. This file will handle the initialization of the IBM Watson Assistant API client.


import AssistantV2 from 'ibm-watson/assistant/v2';
import { IamAuthenticator } from 'ibm-watson/auth';

// Initialize the Watson Assistant client
const assistant = new AssistantV2({
  version: '2021-06-14', // You can adjust the version if necessary
  authenticator: new IamAuthenticator({
    apikey: process.env.IBMWATSONAPIKEY
  }),
  serviceUrl: process.env.IBMWATSONURL // e.g., 'https://api.us-south.assistant.watson.cloud.ibm.com'
});

export default assistant;
  • Place this file in your project's source or utilities folder.
  • Ensure you set the environment variables IBMWATSONAPIKEY and IBMWATSONURL via the Bolt.new secrets or configuration settings.

 

Creating a Watson Session Utility Function

 

In the same file or a new file (for example, watsonUtils.ts), create a function to establish a session with IBM Watson Assistant. This session is required to send messages.


import assistant from './ibmWatsonService';

export async function createWatsonSession(): Promise<string> {
  try {
    const session = await assistant.createSession({
      assistantId: process.env.IBMWATSONASSISTANT_ID // Your Watson Assistant ID
    });
    return session.result.session_id;
  } catch (error) {
    console.error('Error creating Watson session:', error);
    throw error;
  }
}
  • This function uses the Watson Assistant client from the previous file.
  • Be sure to also add the IBMWATSONASSISTANT_ID environment variable in your project settings.

 

Creating a Function to Send Messages to Watson Assistant

 

Create a new function in a separate file or append it to your watsonUtils.ts file. This function will send a user message to IBM Watson Assistant and receive a response.


import assistant from './ibmWatsonService';

export async function sendMessageToWatson(sessionId: string, message: string): Promise<any> {
  try {
    const response = await assistant.message({
      assistantId: process.env.IBMWATSONASSISTANT_ID,
      sessionId: sessionId,
      input: {
        message_type: 'text',
        text: message
      }
    });
    return response.result;
  } catch (error) {
    console.error('Error sending message to Watson Assistant:', error);
    throw error;
  }
}
  • This function can be invoked wherever you need to interact with Watson in your project.
  • Ensure error logging is reviewed in the console for debugging purposes.

 

Integrating Watson Communication into Your Application Logic

 

Locate the file where you need to integrate IBM Watson with your Bolt.new AI logic (for example, app.ts or another controller file). Import the utility functions, create a session, and then send messages as needed.


import { createWatsonSession, sendMessageToWatson } from './watsonUtils';

// Example function that handles user input and queries Watson Assistant
async function processUserInput(userMessage: string) {
  try {
    // Create a session with IBM Watson Assistant
    const sessionId = await createWatsonSession();
    
    // Send the user message to Watson and await response
    const watsonResponse = await sendMessageToWatson(sessionId, userMessage);
    
    console.log('Watson Reply:', watsonResponse);
    
    // Handle or forward the Watson response as needed in your application
  } catch (error) {
    console.error('Error during Watson message processing:', error);
  }
}

// Example usage
processUserInput('Hello, Watson!');
  • Place this snippet in the file that handles your main application logic.
  • The example function demonstrates creating a session and sending a message.

 

Setting Environment Variables in Bolt.new

 

Since Bolt.new AI does not offer a terminal, you need to add your IBM Watson credentials using the built-in secrets or environment variables feature. In your project settings, add:


// IBMWATSONAPIKEY: Your IBM Watson API key.
// IBMWATSONURL: The IBM Watson service URL.
// IBMWATSONASSISTANT_ID: Your Watson Assistant ID.
  • Enter these key-value pairs exactly as noted in your project's environment settings.
  • This configuration ensures that the process.env variables used in your code are correctly populated.

 

Summary

 
  • Edit your package.json to add the IBM Watson SDK dependency.
  • Create ibmWatsonService.ts that initializes the Watson client.
  • Create utility functions in watsonUtils.ts to create sessions and send messages.
  • Integrate these functions in your main application file where interaction with Watson is required.
  • Set all necessary environment variables in your project's configuration.

 

By following these steps, you can successfully integrate IBM Watson services into your Bolt.new AI project using TypeScript.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022