Prerequisites
- Ensure you have an IBM Cloud account. You can sign up for free if you don’t have one.
- Create a new GitHub account or use an existing one.
- Make sure Node.js and npm are installed on your local development environment, as they will be needed for setting up the integration.
- Install Git if it is not already installed on your computer.
Create an IBM Watson Service
- Log in to your IBM Cloud account and navigate to the dashboard.
- Click on **"Catalog"** and search for the Watson service you'd like to use (e.g., Watson Assistant).
- Select the Watson service and click **"Create"**. Follow the instructions to set up the service instance.
- After creating the service, navigate to the service dashboard and obtain your API Key and Service URL from the **"Manage"** section.
Create a New GitHub Repository
- Go to GitHub and click on the **"New"** button to create a new repository.
- Provide a repository name, description, and choose whether it should be public or private.
- Clone the newly created repository to your local machine using Git, by running:
git clone https://github.com/YOUR_USERNAME/YOUR_REPOSITORY.git
- Navigate into the cloned directory:
cd YOUR_REPOSITORY
Integrate IBM Watson in Your Application
- In your local repository, initialize a new Node.js project if not already done:
npm init -y
- Install the SDK for the IBM Watson service you intend to use. For example, if using Watson Assistant, run:
npm install ibm-watson
npm install dotenv
- Create a .env file to store your IBM Watson credentials securely:
touch .env
- Add your Watson API Key and URL to the .env file:
IBM_WATSON_API_KEY=your_api_key
IBM_WATSON_URL=your_service_url
- Create a new file named `app.js` and add the following code to integrate IBM Watson with your application:
require('dotenv').config();
const AssistantV2 = require('ibm-watson/assistant/v2');
const { IamAuthenticator } = require('ibm-watson/auth');
const assistant = new AssistantV2({
version: '2021-06-14',
authenticator: new IamAuthenticator({
apikey: process.env.IBM_WATSON_API_KEY,
}),
serviceUrl: process.env.IBM_WATSON_URL,
});
async function initAssistant() {
try {
const session = await assistant.createSession({ assistantId: 'your_assistant_id' });
console.log('Session ID:', session.result.session_id);
} catch (err) {
console.error(err);
}
}
initAssistant();
Commit and Push Changes to GitHub
- Stage all new files with:
git add .
- Commit the changes with a descriptive message:
git commit -m "Integrated IBM Watson with the application"
- Push the changes to the repository:
git push origin main
Review and Collaborate on GitHub
- Navigate to your GitHub repository to review the pushed code.
- For collaboration, invite collaborators to your repository or submit a Pull Request for teammates to review.
- Click on **"Pull requests"** for code reviews and discuss changes.