|

|  How to Integrate IBM Watson with WhatsApp

How to Integrate IBM Watson with WhatsApp

January 24, 2025

Discover step-by-step instructions to seamlessly integrate IBM Watson with WhatsApp, enhancing communication through AI-driven customer interactions.

How to Connect IBM Watson to WhatsApp: a Simple Guide

 

Set Up IBM Watson

 

  • Create an IBM Cloud account if you don't have one. Follow this by logging in to the IBM Cloud dashboard.
  •  

  • Navigate to the Watson section and select the Watson Assistant service. Click to create a new instance of Watson Assistant.
  •  

  • Once the instance is created, access the service. Within the Watson Assistant GUI, create a new skill (or use an existing one) to define the conversational logic for your application.
  •  

  • Within the skill, configure intents, entities, and dialog flows that will govern the conversation patterns your Watson Assistant will handle.

 

Generate Watson Assistant API Credentials

 

  • After configuring the Watson Assistant skill, generate the API Key and Assistant ID from the service credentials section. These credentials will be used to authenticate requests to Watson Assistant.
  •  

  • Note these credentials securely as they are essential for integration with WhatsApp.

 

Set Up WhatsApp Business API

 

  • Sign up for the WhatsApp Business API via a business solution provider (BSP) or directly through the Meta for Developers platform.
  •  

  • Once registered, verify your business and phone number following WhatsApp’s guidelines.
  •  

  • Configure your WhatsApp Business API client and obtain an access token. This is important for authorizing API requests to WhatsApp.

 

Deploy a Webhook to Integrate Watson and WhatsApp

 

  • Develop a server-side application that serves as a webhook to receive events from WhatsApp and connect to Watson Assistant. This can be done using Express.js, Flask, or any web framework of your choice.
  •  

  • Set up a POST endpoint to handle incoming messages from WhatsApp. The endpoint should parse incoming JSON data for messages and sender information.
  •  

  • For example, using Express.js:
    const express = require('express');
    const app = express();
    app.use(express.json());
    
    app.post('/webhook', (req, res) => {
      const message = req.body.Body;
      const sender = req.body.From;
      
      // Call Watson Assistant service here
      
      res.sendStatus(200);
    });
    
    app.listen(3000, () => console.log('Webhook server is running'));
    
  •  

  • Within the webhook, implement logic to forward the message text to the Watson Assistant API using the credentials obtained earlier. Process the response generated by Watson and prepare it for delivery back through WhatsApp.

 

Configure Watson Assistant API Call

 

  • Integrate the Watson Assistant SDK or use direct HTTP requests to communicate with Watson’s API from your webhook. Example using the Watson SDK:
    const AssistantV2 = require('ibm-watson/assistant/v2');
    const { IamAuthenticator } = require('ibm-watson/auth');
    
    const assistant = new AssistantV2({
      version: '2023-10-15',
      authenticator: new IamAuthenticator({
        apikey: 'YOUR_API_KEY',
      }),
      serviceUrl: 'https://api.us-south.assistant.watson.cloud.ibm.com',
    });
    
    function sendToWatson(sessionId, message) {
      return assistant.message({
        assistantId: 'YOUR_ASSISTANT_ID',
        sessionId: sessionId,
        input: {
          'message_type': 'text',
          'text': message
        }
      });
    }
    
  •  

  • Remember to initialize a session with Watson in your webhook to keep track of conversation context between messages.

 

Return Response to WhatsApp

 

  • Upon receiving a response from Watson Assistant, format this message appropriately to comply with WhatsApp’s message structure.
  •  

  • Send the formatted response back to the user on WhatsApp using the WhatsApp Business API, leveraging the previously acquired access token for authentication.
  •  

  • Example using an HTTP POST method to WhatsApp API:
  •  

    const axios = require('axios');
    
    function sendToWhatsApp(responseMessage, recipient) {
      axios.post('https://graph.facebook.com/v13.0/me/messages', {
        messaging_product: 'whatsapp',
        to: recipient,
        text: { body: responseMessage }
      }, {
        headers: {
          'Authorization': `Bearer YOUR_ACCESS_TOKEN`,
          'Content-Type': 'application/json'
        }
      }).then(response => console.log('Message sent: ', response.data))
        .catch(error => console.error('Error sending message:', error));
    }
    

 

Test Your Integration

 

  • Ensure your webhook is accessible over the internet, possibly using tools like Ngrok during development.
  •  

  • Test the integration by sending a message to your WhatsApp Business account and verifying the response from Watson Assistant.
  •  

  • Iterate on conversation design and message formatting as necessary for optimal user experience.

 

Omi Necklace

The #1 Open Source AI necklace: Experiment with how you capture and manage conversations.

Build and test with your own Omi Dev Kit 2.

How to Use IBM Watson with WhatsApp: Usecases

 

Use Case: Customer Support Automation with IBM Watson and WhatsApp

 

  • Streamlined Communication
  •  

    • Integrating IBM Watson with WhatsApp allows businesses to provide instant customer support, leveraging Watson's AI to handle common queries and tasks.

     

  • 24/7 Availability
  •  

    • With automated WhatsApp responses powered by Watson, customers can access support around the clock without requiring human intervention.

     

  • Consistent User Experience
  •  

    • AI-driven responses ensure customers receive accurate and consistent information, enhancing trust and satisfaction.

     

  • Data-Driven Insights
  •  

    • Watson can analyze interaction data to identify frequent issues and provide insights into customer behavior and preferences.

     

  • Scalability
  •  

    • The integration can effectively handle a high volume of inquiries without additional staffing costs, making it scalable for growing businesses.

     

 

 

Use Case: Healthcare Consultation Bot with IBM Watson and WhatsApp

 

  • Instant Medical Assistance
  •  

    • By integrating IBM Watson with WhatsApp, healthcare providers can offer immediate medical consultation, using Watson’s AI capabilities to triage symptoms and suggest potential actions.

     

  • Personalized Health Information
  •  

    • Watson can personalize responses based on patient history and preferences, delivering tailored health advice to users through WhatsApp.

     

  • Secure Health Data Management
  •  

    • Ensure secure communication with encryption over WhatsApp, while IBM Watson handles data processing securely, maintaining patient confidentiality and compliance with regulations like HIPAA.

     

  • Improved Patient Engagement
  •  

    • Watson can proactively engage patients with scheduled check-ins and reminders via WhatsApp, promoting adherence to treatment plans and regular monitoring.

     

  • Cost Efficiency
  •  

    • The integration reduces the need for in-person consultations for minor issues, cutting costs while ensuring that healthcare resources are prioritized for urgent cases.

     

 

Omi App

Fully Open-Source AI wearable app: build and use reminders, meeting summaries, task suggestions and more. All in one simple app.

Github →

Order Friend Dev Kit

Open-source AI wearable
Build using the power of recall

Order Now

Troubleshooting IBM Watson and WhatsApp Integration

Why is my IBM Watson chatbot not responding on WhatsApp?

 

Check Configuration

 

  • Ensure that your IBM Watson Assistant and WhatsApp Business accounts are correctly linked. This integration usually involves a third-party service like Twilio.
  •  

  • Verify that your webhook URL is correctly set in Twilio's dashboard or your chosen provider's configuration page.

 

Inspect Logs

 

  • Check logs in IBM Cloud to verify the messages are received. Twilio’s message logs can also show if messages are being sent correctly.
  •  

  • Look for any errors or warning messages related to incoming WhatsApp messages.

 

Code Troubleshooting

 

const express = require('express');
const app = express();

app.post('/message', (req, res) => {
  const messageFromWhatsApp = req.body.Body;
  if (messageFromWhatsApp) {
    // Handle message and send to Watson Assistant
  } else {
    // Handle error
  }
  res.sendStatus(200);
});

 

  • Ensure your endpoint is correctly handling POST requests.
  •  

  • Check that the JSON body format matches what your logic expects.

How do I connect IBM Watson to WhatsApp API?

 

Connect IBM Watson to WhatsApp API

 

  • **Set Up IBM Watson:** Create an IBM Watson Assistant instance and define the intents, entities, and dialog in your assistant. Make sure you deploy the assistant and note down the assistant ID and credentials.
  •  

  • **Access WhatsApp API:** Sign up for the Meta for Developers (formerly Facebook) platform to access the WhatsApp Business API. Set up a new project and get the API credentials by following Meta's guidelines. Ensure you're approved and have the necessary permissions for API access.
  •  

  • **Integrate with Middleware:** Use a middleware platform like Twilio, Nexmo, or direct HTTP requests to bridge IBM Watson with WhatsApp API. The middleware will handle incoming WhatsApp messages, pass them to Watson, and return Watson’s responses to WhatsApp.

 


import requests

def send_to_watson(message):
    url = "https://<your-watson-endpoint>"
    response = requests.post(url, json={"text": message})
    return response.json()

def send_to_whatsapp(message):
    url = "https://graph.facebook.com/v11.0/sendMessageEndpoint"
    # Include credentials and payload formatting
    requests.post(url, json={"message": message})

incoming_message = "<input-message-from-whatsapp>"
watson_response = send_to_watson(incoming_message)
send_to_whatsapp(watson_response)

 

Can IBM Watson handle media messages on WhatsApp?

 

Can IBM Watson Handle Media Messages on WhatsApp?

 

  • IBM Watson itself does not natively integrate with WhatsApp, but you can use it with WhatsApp through a third-party service like Twilio.
  •  

  • To process media messages, you need to handle Twilio's incoming webhooks and parse media URLs before utilizing Watson's capabilities.

 

Example Implementation

 

  • Configure a Twilio account and get a WhatsApp sandbox number.
  •  

  • Set up a server to handle Twilio webhooks. Below is a Python example using Flask:

 

from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
import requests
import watson

app = Flask(__name__)

@app.route("/sms", methods=['POST'])
def sms_reply():
    msg = request.form.get('Body')
    media_url = request.form.get('MediaUrl0')
    
    if media_url:
        media = requests.get(media_url).content
        watson_response = watson.process(media)
    else:
        watson_response = watson.process_text(msg)

    resp = MessagingResponse()
    resp.message(watson_response)
    return str(resp)

if __name__ == "__main__":
    app.run(debug=True)

 

Remember to replace watson.process and watson.process_text with actual API calls to Watson services.

Don’t let questions slow you down—experience true productivity with the AI Necklace. With Omi, you can have the power of AI wherever you go—summarize ideas, get reminders, and prep for your next project effortlessly.

Order Now

Join the #1 open-source AI wearable community

Build faster and better with 3900+ community members on Omi Discord

Participate in hackathons to expand the Omi platform and win prizes

Participate in hackathons to expand the Omi platform and win prizes

Get cash bounties, free Omi devices and priority access by taking part in community activities

Join our Discord → 

OMI NECKLACE + OMI APP
First & only open-source AI wearable platform

a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded

OMI NECKLACE: DEV KIT
Order your Omi Dev Kit 2 now and create your use cases

Omi Dev Kit 2

Endless customization

OMI DEV KIT 2

$69.99

Make your life more fun with your AI wearable clone. It gives you thoughts, personalized feedback and becomes your second brain to discuss your thoughts and feelings. Available on iOS and Android.

Your Omi will seamlessly sync with your existing omi persona, giving you a full clone of yourself – with limitless potential for use cases:

  • Real-time conversation transcription and processing;
  • Develop your own use cases for fun and productivity;
  • Hundreds of community apps to make use of your Omi Persona and conversations.

Learn more

Omi Dev Kit 2: build at a new level

Key Specs

OMI DEV KIT

OMI DEV KIT 2

Microphone

Yes

Yes

Battery

4 days (250mAH)

2 days (250mAH)

On-board memory (works without phone)

No

Yes

Speaker

No

Yes

Programmable button

No

Yes

Estimated Delivery 

-

1 week

What people say

“Helping with MEMORY,

COMMUNICATION

with business/life partner,

capturing IDEAS, and solving for

a hearing CHALLENGE."

Nathan Sudds

“I wish I had this device

last summer

to RECORD

A CONVERSATION."

Chris Y.

“Fixed my ADHD and

helped me stay

organized."

David Nigh

OMI NECKLACE: DEV KIT
Take your brain to the next level

LATEST NEWS
Follow and be first in the know

Latest news
FOLLOW AND BE FIRST IN THE KNOW

thought to action

team@basedhardware.com

company

careers

events

invest

privacy

products

omi

omi dev kit

personas

resources

apps

bounties

affiliate

docs

github

help