Setting Up Google Dialogflow
- Go to the [Dialogflow Console](https://dialogflow.cloud.google.com/) and sign in with your Google account.
- Create a new agent by clicking on "Create Agent". Provide a project name, language, and time zone.
- Navigate to the "Fulfillment" section on the left panel and enable the "Inline Editor" or use an external webhook for communication.
{
"webhook": {
"url": "https://your-webhook-url.com/webhook"
}
}
Configuring IBM Watson
- Access the [IBM Cloud Dashboard](https://cloud.ibm.com) and log in with your credentials.
- Find "Resource List" and then select "Create resource" to create your IBM Watson Assistant.
- Follow the prompts to set up a new assistant, specifying necessary details such as name and language.
Creating a Bridge Service
- Develop a server-side application in a language of your choice (Node.js, Python, etc.) that will act as a bridge between Google Dialogflow and IBM Watson.
- This application will receive requests from Dialogflow, forward them to Watson, and then return Watson's response back to Dialogflow.
const express = require('express');
const bodyParser = require('body-parser');
const AssistantV2 = require('ibm-watson/assistant/v2');
const { IamAuthenticator } = require('ibm-watson/auth');
const app = express();
app.use(bodyParser.json());
const assistant = new AssistantV2({
version: '2023-10-10',
authenticator: new IamAuthenticator({
apikey: 'YOUR_WATSON_API_KEY',
}),
serviceUrl: 'YOUR_SERVICE_URL',
});
// Route to handle Dialogflow fulfillment
app.post('/webhook', (req, res) => {
const query = req.body.queryResult.queryText;
assistant.message({
assistantId: 'YOUR_ASSISTANT_ID',
sessionId: 'YOUR_SESSION_ID',
input: {
'message_type': 'text',
'text': query
}
})
.then(response => {
const watsonReply = response.result.output.generic[0].text;
return res.json({ fulfillmentText: watsonReply });
})
.catch(err => {
console.log(err);
return res.json({ fulfillmentText: "I'm having trouble connecting to my assistant." });
});
});
app.listen(3000, () => console.log('Server is running on port 3000'));
Deploying the Bridge Service
- Ensure that your bridge service application is accessible via a public URL. You can use services like Heroku, AWS, or Google Cloud Platform for deployment.
- Update the webhook URL in your Dialogflow agent to point to your deployed application.
Testing Your Integration
- Go back to Dialogflow console and test communications through the "Try It Now" section on the right.
- Verify that queries are sent to Watson and the responses are correctly returned to Dialogflow.
Troubleshooting
- Use logs within your bridge service to track requests and responses between Dialogflow and Watson.
- Verify credentials and URLs at both ends to ensure they match the ones provided by Google and IBM.