CRM Tools
Access customer data, order history, and send notifications.
Overview
CRM tools provide access to customer profiles, purchase history, and communication channels. They integrate with Salesforce, Firestore customer data, and notification services.
getCustomerProfile
Retrieve comprehensive customer profile:
import { getCustomerProfile } from '@hyperfold/actions-sdk';
// Get customer profile by ID
const customer = await getCustomerProfile('cust_xyz123');
// Returns:
{
customer_id: 'cust_xyz123',
email: 'john@example.com',
name: 'John Doe',
loyalty: {
tier: 'gold',
points: 2450,
tier_expires: '2026-12-31',
next_tier: 'platinum',
points_to_next: 550,
},
purchase_history: {
total_orders: 12,
total_spent: 2450.00,
avg_order_value: 204.17,
first_order: '2024-03-15',
last_order: '2025-12-10',
},
preferences: {
favorite_categories: ['footwear', 'sportswear'],
favorite_brands: ['AeroRun', 'Nike'],
size_preferences: { shoes: '10', shirts: 'L' },
communication: { email: true, sms: false },
},
segments: ['high_value', 'sports_enthusiast', 'discount_seeker'],
salesforce: {
account_id: '001xxx',
opportunity_count: 3,
last_interaction: '2025-12-18',
},
}
// Get with specific fields
const basic = await getCustomerProfile('cust_xyz123', {
fields: ['name', 'loyalty', 'purchase_history'],
});
// Get by email
const byEmail = await getCustomerProfile({ email: 'john@example.com' });
getOrderHistory
Access customer purchase history:
import { getOrderHistory } from '@hyperfold/actions-sdk';
// Get customer's order history
const orders = await getOrderHistory('cust_xyz123');
// Returns:
{
customer_id: 'cust_xyz123',
total_orders: 12,
orders: [
{
order_id: 'order_789',
date: '2025-12-10T14:30:00Z',
status: 'delivered',
total: 162.00,
items: [
{ product_id: 'prod_aero_x2', name: 'AeroRun X2', quantity: 1, price: 162.00 },
],
payment_method: 'card_visa_4242',
shipping_address: { city: 'San Francisco', state: 'CA' },
},
// ... more orders
],
stats: {
total_spent: 2450.00,
avg_order_value: 204.17,
orders_last_30_days: 2,
orders_last_90_days: 5,
},
frequent_products: [
{ product_id: 'prod_aero_x2', times_purchased: 3 },
{ product_id: 'prod_socks_wp', times_purchased: 5 },
],
}
// Get with filters
const recent = await getOrderHistory('cust_xyz123', {
limit: 5,
since: '2025-01-01',
status: 'delivered',
});
// Get orders for specific product
const productOrders = await getOrderHistory('cust_xyz123', {
product_id: 'prod_aero_x2',
});
Order history includes full details for personalization. Use the frequent_products field to suggest repurchases.
updateCustomer
Update customer profiles and sync with CRM:
import {
updateCustomerProfile,
updateLoyaltyTier,
addCustomerTag,
} from '@hyperfold/actions-sdk';
// Update customer profile
await updateCustomerProfile('cust_xyz123', {
preferences: {
size_preferences: { shoes: '10.5' },
},
});
// Update loyalty tier
await updateLoyaltyTier('cust_xyz123', {
new_tier: 'platinum',
reason: 'Reached 3000 points threshold',
notify_customer: true,
});
// Add customer tags/segments
await addCustomerTag('cust_xyz123', 'vip_2025');
await addCustomerTag('cust_xyz123', 'early_adopter');
// Record customer interaction
import { recordInteraction } from '@hyperfold/actions-sdk';
await recordInteraction('cust_xyz123', {
type: 'negotiation',
channel: 'agent',
outcome: 'purchase',
value: 162.00,
notes: 'Negotiated 10% Gold discount on AeroRun X2',
agent_id: 'sales-bot-01',
});
// Sync to Salesforce
import { syncToSalesforce } from '@hyperfold/actions-sdk';
await syncToSalesforce('cust_xyz123', {
update_account: true,
create_activity: true,
activity_type: 'Agent Purchase',
});
Notification Tools
Send emails, SMS, and internal notifications:
import {
sendEmail,
sendSMS,
postToSlack,
} from '@hyperfold/actions-sdk';
// Send transactional email
await sendEmail({
to: 'customer@example.com',
template: 'order_confirmation',
data: {
order_id: 'order_789',
items: [{ name: 'AeroRun X2', price: 162.00 }],
total: 162.00,
tracking_url: 'https://...',
},
});
// Send SMS notification
await sendSMS({
to: '+14155551234',
template: 'shipping_update',
data: {
order_id: 'order_789',
status: 'Out for delivery',
eta: '2:00 PM - 6:00 PM',
},
});
// Post to Slack (internal notifications)
await postToSlack({
channel: '#sales-wins',
message: '🎉 New conversion! $162 from Gold member',
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: '*New Sale*\\nCustomer: John Doe (Gold)\\nProduct: AeroRun X2\\nPrice: $162 (10% discount)',
},
},
],
});
// Send alert for high-value transactions
import { sendAlert } from '@hyperfold/actions-sdk';
await sendAlert({
severity: 'info',
title: 'High-value negotiation',
message: 'Customer negotiating $500+ purchase',
channels: ['slack', 'email'],
recipients: ['sales-manager@company.com'],
});
Usage in Agent
Complete example using CRM tools for personalization:
import {
HyperfoldAgent,
OnACPEvent,
getCustomerProfile,
getOrderHistory,
sendEmail,
recordInteraction,
} from '@hyperfold/actions-sdk';
@HyperfoldAgent({ name: 'crm-aware-agent', type: 'negotiator' })
export class CRMAwareAgent {
@OnACPEvent('quote')
async handleQuote(productId: string, offer: number, context: BuyerContext) {
const customer = await getCustomerProfile(context.customer_id);
const history = await getOrderHistory(context.customer_id, {
product_id: productId,
});
if (history.orders.length > 0) {
const lastPurchase = history.orders[0];
const daysSinceLastPurchase = this.daysBetween(lastPurchase.date, new Date());
if (daysSinceLastPurchase < 30) {
return {
status: 'info',
message: `I see you purchased this item ${daysSinceLastPurchase} days ago. Is there an issue with your order?`,
support_link: '/support',
};
}
}
const pricing = await this.calculatePrice(productId, {
tier: customer.loyalty.tier,
lifetime_value: customer.purchase_history.total_spent,
favorite_brand: customer.preferences.favorite_brands.includes('AeroRun'),
});
await recordInteraction(context.customer_id, {
type: 'quote_request',
product_id: productId,
offered_price: pricing.suggested,
buyer_offer: offer,
});
return {
status: 'quote',
price: pricing.suggested,
personalization: `As a ${customer.loyalty.tier} member with ${customer.purchase_history.total_orders} orders, you qualify for our best pricing.`,
};
}
}
Ready to build custom agents? See the Negotiator Agent reference.