Skip to main content

Dialogflow CX Integration

Integrate Sticky Calls API with Dialogflow CX for context-aware conversational AI.


Setup

Time: 10 minutes Difficulty: Easy


Step 1: Create Webhook

1.1 Deploy Webhook Function

Cloud Function (Node.js):

const axios = require('axios');

exports.stickyCallsWebhook = async (req, res) => {
const session = req.body.sessionInfo;
const parameters = session.parameters;

try {
// Call Sticky Calls API
const response = await axios.post(
'https://api.stickycalls.com/v1/calls/start',
{
call_id: session.name,
identity_hints: {
ani: parameters.caller_phone,
external_ids: {
dialogflow_session: session.name
}
}
},
{
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
}
);

// Set session parameters
const identity = response.data.identity;
const sessionParameters = {
customer_ref: response.data.customer_ref,
identity_confidence: identity.confidence,
identity_level: identity.level,
caller_context: JSON.stringify(response.data.variables || {}),
open_intents: response.data.open_intents || []
};

res.json({
sessionInfo: {
parameters: sessionParameters
}
});

} catch (error) {
console.error('Sticky Calls API error:', error);
res.json({
sessionInfo: {
parameters: {
customer_ref: null,
identity_confidence: 0,
identity_level: 'none',
caller_context: '{}'
}
}
});
}
};

1.2 Configure Webhook in Dialogflow CX

  1. Go to ManageWebhooks
  2. Click Create
  3. Name: sticky-calls-identify
  4. URL: Your Cloud Function URL
  5. Save

Step 2: Add Webhook to Start Page

  1. Go to Start page
  2. Add Entry Fulfillment
  3. Enable Webhook
  4. Select: sticky-calls-identify
  5. Tag: get-caller-context

Step 3: Route Based on Context

Create Route

Condition:

$session.params.identity_confidence >= 0.7

Fulfillment:

Agent says: "Welcome back! I can see your previous interaction history."

Transition: Route to relevant page based on context


Step 4: Save Context on End

End Flow Page

Entry Fulfillment:

exports.saveContext = async (req, res) => {
const session = req.body.sessionInfo;
const parameters = session.parameters;

await axios.post(
'https://api.stickycalls.com/v1/calls/end',
{
call_id: session.name,
customer_ref: parameters.customer_ref,
intent: parameters.detected_intent || 'general_inquiry',
intent_status: parameters.unresolved_issues?.length > 0 ? 'open' : 'closed',
variables: {
summary: parameters.conversation_summary || '',
detected_intent: parameters.detected_intent || ''
}
},
{
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
}
);

res.json({ fulfillmentResponse: { messages: [] } });
};

Flow Example

Start Page

Entry Fulfillment: Call webhook (identify caller)

Route 1: IF identity_confidence >= 0.7
→ "Welcome back! I can see your interaction history."
→ Route to relevant intent

Route 2: ELSE
→ "Welcome! How can I help?"
→ Standard flow

... conversation ...

End Page
→ Webhook: Save context
→ End session

Advanced: Intent Routing

Route based on open intents:

// In webhook response
const openIntents = response.data.open_intents || [];
const hasOpenBillingIntent = openIntents.some(i => i.intent === 'billing_issue' && i.status === 'open');
const hasOpenTechnicalIntent = openIntents.some(i => i.intent === 'technical' && i.status === 'open');

if (hasOpenBillingIntent) {
return {
targetPage: 'projects/.../pages/billing-support'
};
} else if (hasOpenTechnicalIntent) {
return {
targetPage: 'projects/.../pages/technical-support'
};
}

Testing

  1. Test in Dialogflow CX simulator
  2. Make first call (no match)
  3. Complete conversation
  4. Make second call (should match)
  5. Verify context displayed

Ready to add memory to Dialogflow CX? Sign up →