Don’t know what to write to a customer or a major donor? Not sure how to be kind and encourage someone to try a little harder next time? ChatGPT can do that for you. And now you can use it right inside Salesforce to respond to your emails.
My colleague Brian Ricter wrote an apex class connecting Flow with ChatGPT. It takes a string, sends that as the prompt to ChatGPT and returns the response. You can use this apex action in a flow to do anything you want with ChatGPT!
I’ve utilized Brian’s apex action in a screen flow that helps you respond to a contact’s most recent email. And I’ve packaged it up for you to install easily.
The Good Stuff
Set up steps:
- Prerequisites
- Set up Gmail to Salesforce integration or another way to log incoming emails in Salesforce.
- Sign up for a pay-as-you-go Open AI API account. I switched to a paid account about half way through testing and my bill so far is 1 cent.
- Get your API Key.
- Install the package that includes a flow, a custom setting and some code.
- Create a new Custom Settings record.
- From Setup, search for Custom Settings.
- Click on ChatGPT Settings.
- Click Manage then Edit.
- Paste in your API Key.
- Paste this into Endpoint:
https://api.openai.com/v1/chat/completions
- Add the Flow to your page layout.
- Find a Contact. Click the Setup gear icon and select Edit Page.
- Select a Flow Standard component and drag that to your page layout.
- Select the ChatGPT Email Response Flow.
- Click Pass record ID into this variable below the box below “recordId”
- Save (and you may need to activate).
- Add a Remote Site Setting.
- From Setup, search for Remote Site Settings.
- Click New. Give it a name and paste in the Endpoint you copied earlier. Save.
- Optional: Edit the default signature of the email from the current user’s name.
- Open the Flow.
- Select the blue square labeled Modify Email if Necessary.
- Change the value in the Sign Email From‘s Default Value.
- Click Done, Save As, Save and Activate.
Examples, Tips and Tricks
Warning
You’re at your own risk exposing any data to ChatGPT or using the emails that it drafts. I take no responsibility for what ChatGPT does with your data or what happens if you send flirty emails from your company account! Have your legal advisor look into ChatGPT before use it with Salesforce. Always test in a sandbox.
Credits:
- Brian Ricter wrote the apex class connecting Flow with ChatGPT.
- Rakesh Gupta, aka Automation Champion, wrote the class and test to remove HTML markup from the text. ChatGPT with API will not accept any <p> or special characters.