The POST /generate-next-message RPC endpoint provides AI-powered message generation for conversations. This intelligent system analyzes conversation context, persona characteristics, and business objectives to generate contextually appropriate responses that maintain conversation flow and drive desired outcomes.
POST https://your-api-name.mercury.ratiomachina.com/generate-next-message Content-Type: application/json Authorization: x-mercury-api-key: YOUR_API_KEY
Generate a contextually appropriate response based on conversation history and persona characteristics.
{
"conversation_id": "uuid-conv-123",
"generation_options": {
"response_length": "medium",
"tone_adjustment": "maintain_persona",
"include_questions": true,
"suggest_next_steps": true
},
"context": {
"customer_urgency": "medium",
"business_priority": "qualification",
"channel_preferences": {
"max_length": 160,
"emoji_allowed": false,
"links_allowed": true
}
}
}{
"generation_result": {
"status": "success",
"generation_time_ms": 1250,
"model_used": "gpt-4-turbo",
"confidence_score": 0.92
},
"generated_message": {
"content": "Thanks for your interest in our enterprise solutions! Based on your team size and technical requirements, I'd recommend scheduling a personalized demo. What time works best for you this week?",
"metadata": {
"tone": "professional_friendly",
"intent": "demo_scheduling",
"call_to_action": "schedule_demo",
"personalization_factors": ["company_size", "technical_role"],
"estimated_response_rate": 0.78
}
},
"context_analysis": {
"conversation_stage": "initial_qualification",
"customer_sentiment": 0.75,
"engagement_level": "high",
"key_interests": ["enterprise_features", "technical_integration"],
"objections_detected": [],
"next_logical_steps": ["demo_scheduling", "technical_discussion"]
},
"alternatives": [
{
"content": "I'd be happy to show you how our enterprise platform can address your specific needs. Would you prefer a technical deep-dive or a business-focused overview?",
"tone": "consultative",
"confidence": 0.87
},
{
"content": "Let me connect you with our technical team for a detailed discussion about integration requirements. When would be a good time for a 30-minute call?",
"tone": "direct",
"confidence": 0.83
}
]
}Generate messages that incorporate information from persona skills, such as knowledge base lookups or CRM data retrieval.
{
"conversation_id": "uuid-conv-456",
"generation_options": {
"use_skills": true,
"skill_execution_timeout": 10,
"fallback_on_skill_failure": true,
"response_length": "detailed"
},
"skill_preferences": {
"preferred_skills": [
"knowledge-base-lookup",
"product-catalog-search",
"pricing-calculator"
],
"skill_parameters": {
"knowledge-base-lookup": {
"category": "product_features",
"max_results": 3
},
"product-catalog-search": {
"product_type": "enterprise",
"include_pricing": true
}
}
},
"context": {
"customer_question": "What are the key differences between your Standard and Enterprise plans?",
"customer_profile": {
"company_size": "500_employees",
"industry": "fintech",
"current_tools": ["salesforce", "slack", "aws"]
}
}
}{
"generation_result": {
"status": "success",
"generation_time_ms": 2850,
"skills_executed": 2,
"confidence_score": 0.95
},
"generated_message": {
"content": "Great question! For a fintech company like yours with 500 employees, the Enterprise plan offers several key advantages over Standard:\n\n• **Advanced Security**: SOC 2 Type II compliance, GDPR ready, and custom SSO integration\n• **API Access**: Full REST API with 10,000 calls/month (vs 1,000 on Standard)\n• **Integrations**: Native Salesforce connector and AWS Lambda functions\n• **Support**: Dedicated CSM and 99.9% SLA\n\nBased on your current AWS infrastructure, you'd benefit from our enterprise-grade scalability. The ROI typically pays for itself within 6 months for companies your size. Would you like me to calculate a custom quote based on your specific needs?",
"metadata": {
"skills_used": [
{
"skill": "knowledge-base-lookup",
"results_found": 3,
"execution_time": "0.8s"
},
{
"skill": "product-catalog-search",
"products_matched": 2,
"execution_time": "1.2s"
}
],
"personalization_factors": [
"company_size",
"industry_fintech",
"current_aws_usage",
"salesforce_integration"
],
"call_to_action": "custom_quote_request"
}
},
"skill_results": {
"knowledge-base-lookup": {
"results": [
{
"title": "Enterprise Security Features",
"content": "SOC 2 Type II compliance, GDPR ready, custom SSO",
"relevance": 0.92
},
{
"title": "API Rate Limits by Plan",
"content": "Standard: 1,000 calls/month, Enterprise: 10,000 calls/month",
"relevance": 0.89
}
]
},
"product-catalog-search": {
"products": [
{
"name": "Standard Plan",
"features": ["basic_api", "email_support", "standard_integrations"]
},
{
"name": "Enterprise Plan",
"features": ["full_api", "dedicated_csm", "custom_integrations", "sla_guarantee"]
}
]
}
},
"context_analysis": {
"question_complexity": "high",
"information_density": "detailed",
"decision_stage": "evaluation",
"personalization_score": 0.91
}
}Generate a sequence of messages for complex workflows like follow-ups, nurture sequences, or multi-step processes.
{
"conversation_id": "uuid-conv-789",
"generation_type": "sequence",
"sequence_options": {
"message_count": 3,
"spacing_strategy": "immediate_to_gradual",
"escalation_pattern": "gentle_to_direct",
"sequence_goal": "demo_booking"
},
"context": {
"trigger_event": "no_response_to_demo_offer",
"days_since_last_message": 3,
"customer_engagement_level": "medium",
"business_priority": "high_value_lead"
},
"sequence_parameters": {
"message_1": {
"timing": "immediate",
"tone": "helpful_reminder",
"include_value_proposition": true
},
"message_2": {
"timing": "2_days_later",
"tone": "alternative_offer",
"include_social_proof": true
},
"message_3": {
"timing": "1_week_later",
"tone": "final_opportunity",
"include_urgency": true
}
}
}{
"generation_result": {
"status": "success",
"sequence_generated": true,
"total_generation_time_ms": 3200,
"sequence_confidence": 0.89
},
"message_sequence": [
{
"sequence_position": 1,
"timing": "immediate",
"content": "Hi John! I wanted to follow up on our conversation about your team's integration challenges. I noticed I haven't heard back about the demo - no worries, I know you're busy! The 30-minute session I mentioned would specifically address the API bottlenecks you mentioned. Would Thursday or Friday work better for you?",
"metadata": {
"tone": "helpful_reminder",
"approach": "understanding_reference_previous",
"estimated_response_rate": 0.65
}
},
{
"sequence_position": 2,
"timing": "2_days_later",
"content": "Quick alternative thought - instead of a full demo, would you prefer a 15-minute technical overview? I can show you exactly how we solved similar integration challenges for three other fintech companies like yours. Sometimes a shorter, focused session is easier to fit in. I have a few slots open next week if that's more manageable.",
"metadata": {
"tone": "alternative_offer",
"approach": "lower_commitment_social_proof",
"estimated_response_rate": 0.58
}
},
{
"sequence_position": 3,
"timing": "1_week_later",
"content": "John, I'll be honest - I think our platform could save your team significant time on the integration work you mentioned, but I don't want to keep pestering you if the timing isn't right. This is my last follow-up. If you'd still like to see how we can help streamline your processes, just reply 'YES' and I'll send you a calendar link. Otherwise, I'll move you to our quarterly newsletter and check back in a few months. Sound fair?",
"metadata": {
"tone": "final_opportunity",
"approach": "honest_urgency_easy_response",
"estimated_response_rate": 0.42
}
}
],
"sequence_strategy": {
"overall_approach": "value_focused_with_gradual_urgency",
"personalization_elements": [
"integration_challenges",
"team_size",
"fintech_industry",
"api_bottlenecks"
],
"psychological_techniques": [
"reciprocity",
"social_proof",
"commitment_consistency",
"scarcity"
],
"success_metrics": {
"expected_overall_response_rate": 0.55,
"conversion_probability": 0.23,
"sequence_completion_rate": 0.89
}
},
"fallback_options": [
{
"trigger": "no_response_after_sequence",
"action": "move_to_nurture_campaign",
"timing": "30_days_later"
},
{
"trigger": "negative_response",
"action": "apologetic_unsubscribe",
"timing": "immediate"
}
]
}Generate immediate responses for live chat scenarios with real-time context and rapid response requirements.
{
"conversation_id": "uuid-conv-chat-001",
"generation_mode": "real_time",
"real_time_options": {
"max_response_time_ms": 2000,
"typing_indicator": true,
"response_length": "concise",
"urgency_level": "immediate"
},
"live_context": {
"customer_typing": false,
"customer_online": true,
"last_message_timestamp": "2024-01-15T16:45:30Z",
"response_expected_by": "2024-01-15T16:46:00Z"
},
"channel_constraints": {
"platform": "website_chat",
"max_characters": 500,
"markdown_supported": true,
"emoji_appropriate": true,
"links_allowed": true
},
"immediate_context": {
"current_page": "/pricing",
"time_on_page": "3m 45s",
"previous_pages": ["/features", "/integrations"],
"cart_items": [],
"identified_intent": "pricing_inquiry"
}
}{
"generation_result": {
"status": "success",
"generation_time_ms": 1450,
"real_time_constraints_met": true,
"confidence_score": 0.88
},
"generated_message": {
"content": "I see you're checking out our pricing! 😊 Since you were looking at integrations, you might be interested in our Pro plan - it includes unlimited API calls and our Salesforce connector. What size team are you planning to support?",
"metadata": {
"response_type": "conversational",
"personalization_based_on": [
"current_page_pricing",
"previous_page_integrations",
"time_spent_researching"
],
"immediate_goal": "qualification_question",
"estimated_engagement": 0.82
},
"typing_simulation": {
"typing_duration_ms": 2500,
"typing_pattern": "natural_human",
"pause_points": [15, 38, 67]
}
},
"real_time_analysis": {
"customer_journey_stage": "consideration",
"urgency_indicators": [
"extended_time_on_pricing",
"multiple_feature_pages_viewed"
],
"behavioral_signals": {
"purchase_intent": 0.75,
"information_seeking": 0.90,
"comparison_shopping": 0.65
},
"recommended_next_actions": [
"ask_qualifying_questions",
"offer_personalized_demo",
"provide_social_proof"
]
},
"follow_up_suggestions": [
{
"trigger": "if_responds_with_team_size",
"suggested_response": "Perfect! For a team that size, the Pro plan would be ideal. Would you like me to show you a quick 2-minute demo of the features you'd use most?"
},
{
"trigger": "if_asks_about_pricing",
"suggested_response": "Great question! Our Pro plan is $49/month for up to 25 team members. That includes everything you were looking at plus priority support. Want to try it free for 14 days?"
}
]
}response_length - brief, medium, detailed, customtone_adjustment - maintain_persona, match_customer, escalate_urgencyformality_level - casual, professional, formalemotional_tone - empathetic, enthusiastic, neutral, reassuringurgency_level - low, medium, high, criticalinclude_questions - Generate engaging questionssuggest_next_steps - Propose clear action itemsinclude_social_proof - Add credibility elementspersonalization_level - low, medium, high, customcall_to_action_strength - subtle, moderate, strong{
"generation_result": {
"status": "failed",
"error_type": "context_insufficient",
"generation_time_ms": 450
},
"error": {
"code": "INSUFFICIENT_CONTEXT",
"message": "Not enough conversation history to generate contextual response",
"details": {
"minimum_messages_required": 2,
"current_message_count": 0,
"suggestion": "Use default_greeting or provide initial_context"
}
},
"fallback_options": {
"default_greeting": "Hi! I'm here to help with any questions about our products. What can I assist you with today?",
"persona_introduction": "Hello! I'm Alex, your sales assistant. I'd love to learn more about your needs and see how we can help your team succeed.",
"custom_fallback": "Use conversation.persona.default_greeting if available"
},
"retry_suggestions": [
"Provide initial_context in the request",
"Use conversation history from external system",
"Start with a template message and build context"
]
}