Skip to main content

1. Define the Vercel AI tool and backend API route

Create an AI tool that gets a list of opportunities from Salesforce and a backend route that uses Auth0 to get a Salesforce access token:
  • When the tool calls auth0.getAccessTokenForConnection(), pass sfdc as the connection name to get a Salesforce access token.
app/api/chat/route.js

2. Call from the frontend Chat UI

Use the @ai-sdk/react hook to wire up the chat component:
src/components/chat.tsx

3. Example UI

Navigate to https://localhost:3000 to see the chat UI:
Get Salesforce Opportunities Chat
UI
You can customize the chat UI to display structured results in tables, charts, or summaries. When the user sends a message like Get me 2 opportunities from Salesforce, GPT-4 interprets the request and invokes the listOpportunities tool, which securely calls the Salesforce API using access tokens obtained via Auth0 and returns the results.