Prerequisites
- Ensure you have a Google Cloud Platform account with Dialogflow enabled.
- Create a Dialogflow agent and set up intents and entities according to your needs.
- Ensure you have an Intercom account and access to the Intercom developer hub.
Configuring Dialogflow
- Go to the Dialogflow console and navigate to the Integrations tab.
- Enable the Webhook integration within your Dialogflow agent settings. This allows Dialogflow to send information to external URLs.
- Create a custom Webhook URL using a cloud function or a server endpoint to handle Dialogflow’s requests.
Creating a Webhook
- Set up a server using Node.js, Python, or any preferred language to handle incoming Dialogflow webhook requests.
- Ensure your server can parse JSON requests and respond with JSON formatted responses.
- Example Node.js server setup:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.post('/webhook', (req, res) => {
const intent = req.body.queryResult.intent.displayName;
let response = { fulfillmentText: "Default response" };
if (intent === 'YourIntentName') {
response.fulfillmentText = "Custom response for intent";
}
res.json(response);
});
app.listen(process.env.PORT || 3000, () => {
console.log('Server is running');
});
Connect Webhook to Dialogflow
- In the Dialogflow console, navigate to Fulfillment, enable Webhook, and input your server’s webhook URL.
- Ensure that your server is publicly accessible and using HTTPS for secure communication.
Setting Up Intercom
- Log in to your Intercom account and navigate to the Developer Hub.
- Create a new app and note down the app ID and app secret, which will be used to authenticate your integration.
- Enable the "Incoming" and "Outgoing" Webhooks in Intercom if needed, for further customization and interaction.
Integrating with Intercom
- In your server handling the Dialogflow webhook, implement a function to send messages to Intercom using their API.
- Use the Intercom Node.js library or directly make HTTP requests to Intercom's API.
- Example Intercom API call:
const axios = require('axios');
function sendMessageToIntercom(userId, message) {
return axios.post(`https://api.intercom.io/messages`, {
message_type: "inapp",
body: message,
from: { type: "user", user_id: userId }
}, {
headers: {
'Authorization': `Bearer YOUR_ACCESS_TOKEN`,
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
}
Testing the Integration
- Interact with your Dialogflow agent through Intercom chat, ensuring intents trigger correctly and responses are sent back effectively.
- Monitor both systems for logs and errors to ensure the webhook is functioning correctly and sending necessary data between systems.
Finalizing and Deploying
- Confirm that your server is stable and can handle scaling based on expected traffic.
- Deploy your server solution to a robust cloud service to ensure maximum uptime for your Dialogflow-Intercom integration.