Final Salesforce Cookbook (#1293)

Co-authored-by: Aaron Wilkowitz <157151487+aaronwilkowitz-openai@users.noreply.github.com>
Co-authored-by: Aaron Wilkowitz <aaronwilkowitz@openai.com>
This commit is contained in:
aa-openai 2024-07-21 10:59:23 -07:00 committed by GitHub
parent 8bf12f2f5e
commit c9dc5942f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 498 additions and 1 deletions

View File

@ -112,4 +112,8 @@ rupert-openai:
name: "Rupert Truman"
website: "https://www.linkedin.com/in/rupert-truman/"
avatar: "https://avatars.githubusercontent.com/u/171234447"
aa-openai:
name: "Allison August"
website: "https://www.linkedin.com/in/allisonaugust/"
avatar: "https://avatars.githubusercontent.com/u/172655668?v=4"

View File

@ -0,0 +1,484 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This page provides an instruction & guide for developers building a GPT Action for a specific application. Before you proceed, make sure to first familiarize yourself with the following information: \n",
"- [Introduction to GPT Actions](https://platform.openai.com/docs/actions/introduction)\n",
"- [Introduction to GPT Actions Library](https://platform.openai.com/docs/actions/actions-library)\n",
"- [Example of Buliding a GPT Action from Scratch](https://platform.openai.com/docs/actions/getting-started)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This particular GPT Action provides an overview of how to connect to Salesforce, specifically, Salesforce Service Cloud. This schema detailed in this Action allows the user to pull case data and update cases directly from ChatGPT. The setup process to create Actions for other Salesforce Cloud solutions uses the same Connected App and authentication setup, but will require a different API schema."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Value + Example Business Use Cases"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Value**: Users can now leverage ChatGPT's natural language capability to connect directly to Salesforce\n",
"\n",
"**Example Use Cases**: \n",
"- Reduce average response time to customers\n",
"- Reduce time to troubleshoot cases or issues\n",
"- Ensure more consistent brand voice in reponse to customers when combined with knowledge and instructions in the GPT"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Application Information"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Application Key Links"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check out these links from the application before you get started:\n",
"- [Create Lightning Apps in Salesforce](https://help.salesforce.com/s/articleView?id=sf.apps_lightning_create.htm&type=5)\n",
"- [OAuth Tokens and Scopes](https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_tokens_scopes.htm&type=5)\n",
"- [Salesforce API Docs](https://developer.salesforce.com/docs/apis)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Application Prerequisites"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before you get started, make sure you go through the following steps in your application environment:\n",
"- Ensure you have permissions to create an App in Salesforce"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## ChatGPT Steps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Custom GPT Instructions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once you've created a Custom GPT, copy the text below in the Instructions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail."
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"**Context**: Your purpose is to pull information from Service Cloud, and push updates to cases. A user is going to ask you a question and ask you to make updates.\n",
"\n",
"**Instructions**:\n",
"1. When a user asks you to help them solve a case in Service Cloud, ask for the case number and pull the details for the case into the conversation using the getCaseDetailsFromNumber action.\n",
"2. If the user asks you to update the case details, use the action updateCaseStatus.\n",
"\n",
"**Example**: \n",
"User: Help me solve case 00001104 in Service Cloud."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### OpenAPI Schema "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once you've created a Custom GPT, copy the text below in the Actions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "yaml"
}
},
"outputs": [],
"source": [
"openapi: 3.1.0\n",
"info:\n",
" title: Salesforce Service Cloud Case Update API\n",
" description: API for updating the status of Service Cloud tickets (cases) in Salesforce.\n",
" version: 1.0.3\n",
"servers:\n",
" - url: https://your_instance.my.salesforce.com\n",
" description: Base URL for your Salesforce instance (replace 'your_instance' with your actual Salesforce domain)\n",
"paths:\n",
" /services/data/v60.0/sobjects/Case/{CaseId}:\n",
" patch:\n",
" operationId: updateCaseStatus\n",
" summary: Updates the status of a Service Cloud case\n",
" description: Updates the status of a Service Cloud ticket based on the case ID number.\n",
" parameters:\n",
" - name: CaseId\n",
" in: path\n",
" required: true\n",
" description: The ID of the case to update.\n",
" schema:\n",
" type: string\n",
" requestBody:\n",
" required: true\n",
" content:\n",
" application/json:\n",
" schema:\n",
" type: object\n",
" properties:\n",
" Status:\n",
" type: string\n",
" description: The new status of the case.\n",
" responses:\n",
" '204':\n",
" description: Successfully updated the case status\n",
" '400':\n",
" description: Bad request - invalid input or case ID not found\n",
" '401':\n",
" description: Unauthorized - authentication required\n",
" '404':\n",
" description: Not Found - case ID does not exist\n",
" delete:\n",
" operationId: deleteCase\n",
" summary: Deletes a Service Cloud case\n",
" description: Deletes a Service Cloud ticket based on the case ID number.\n",
" parameters:\n",
" - name: CaseId\n",
" in: path\n",
" required: true\n",
" description: The ID of the case to delete.\n",
" schema:\n",
" type: string\n",
" responses:\n",
" '204':\n",
" description: Successfully deleted the case\n",
" '400':\n",
" description: Bad request - invalid case ID\n",
" '401':\n",
" description: Unauthorized - authentication required\n",
" '404':\n",
" description: Not Found - case ID does not exist\n",
" /services/data/v60.0/query:\n",
" get:\n",
" operationId: getCaseDetailsFromNumber\n",
" summary: Retrieves case details using a case number\n",
" description: Retrieves the details of a Service Cloud case associated with a given case number.\n",
" parameters:\n",
" - name: q\n",
" in: query\n",
" required: true\n",
" description: SOQL query string to find the Case details based on Case Number.\n",
" schema:\n",
" type: string\n",
" example: \"SELECT Id, CaseNumber, Status, Subject, Description FROM Case WHERE CaseNumber = '123456'\"\n",
" responses:\n",
" '200':\n",
" description: Successfully retrieved the case details\n",
" content:\n",
" application/json:\n",
" schema:\n",
" type: object\n",
" properties:\n",
" totalSize:\n",
" type: integer\n",
" done:\n",
" type: boolean\n",
" records:\n",
" type: array\n",
" items:\n",
" type: object\n",
" properties:\n",
" Id:\n",
" type: string\n",
" CaseNumber:\n",
" type: string\n",
" Status:\n",
" type: string\n",
" Subject:\n",
" type: string\n",
" Description:\n",
" type: string\n",
" '400':\n",
" description: Bad request - invalid query\n",
" '401':\n",
" description: Unauthorized - authentication required\n",
" '404':\n",
" description: Not Found - case number does not exist\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Authentication Instructions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Pre-Action Steps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before you set up authentication in ChatGPT, please take the following steps in the application."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before you set up authentication in ChatGPT, please take the following steps in the application.\n",
"1. Navigate to Salesforce Setup"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![gptactions_salesforce.png](../../../images/gpt_actions_salesforce_setup.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. Search for “App Manager”\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![gptactions_salesforce.png](../../../images//gpt_actions_salesforce_manager.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3. Click “New Connected App”\n",
"4. Enter a Connected App Name\n",
"5. Enter contact email (your email)\n",
"6. Check the box to enable OAuth settings\n",
"7. Insert a callback URL (use a placeholder like https://chat.openai.com/aip//oauth/callback for now, youll update this later when you create the Action in ChatGPT) \n"
]
},
{
"cell_type": "markdown",
"metadata": {
"vscode": {
"languageId": "yaml"
}
},
"source": [
"![gptactions_salesforce.png](../../../images//gpt_actions_salesforce_oauth2.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"8. Select “Selected OAuth Scopes” and grant the appropriate permissions. Scope these based on your internal security policies. \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![gptactions_salesforce.png](../../../images//gpt_actions_salesforce_scope.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"9. Ensure the following boxes are checked:\n",
"- Enable Client Credentials Flow\n",
"- Enable Authorization Code and Credentials FLow\n",
"- Enable Token Exchange Flow\n",
"10. Ensure the following box is unchecked: \n",
"- Require Proof Key for Code Exchange (PKCE) Extension for Supported Authorization Flows\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![gptactions_salesforce.png](../../../images/gpt_actions_salesforce_settings_condensed.png) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"11. Save your New Connected App\n",
"12. Under “Consumer Key and Secret” click “Manage Consumer Details”. Verify your access using the code emailed to your account, and then copy the key and secret. \n",
"- Salesforce Consumer Key = ChatGPT Client ID\n",
"- Salesforce Consumer Secret = ChatGPT Client Secret\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![gptactions_salesforce.png](../../../images//gpt_actions_salesforce_credentials.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"13. Return to App page\n",
"14. Click “Manage” \n",
"15. Click “Edit Policies”\n",
"16. Under OAuth Policies, check the “Enable Token Exchange Flow” box\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![gptactions_salesforce.png](../../../images//gpt_actions_salesforce_token.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"17. Click save!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### In ChatGPT"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In ChatGPT, click on \"Authentication\" and choose **\"OAuth\"**. Enter in the information below. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- **Client ID**: use Client ID from steps above \n",
"- **Client Secret**: use Client Secret from steps above\n",
"- **Authorization URL**: https://[inserturlhere].my.salesforce.com/services/oauth2/authorize\n",
"- **Token URL**: https://[inserturlhere].my.salesforce.com/services/oauth2/token \n",
"- **Scope**: full\n",
"- **Token**: Default (POST)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Post-Action Steps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Once you've set up authentication in ChatGPT, follow the steps below in the application to finalize the Action. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Copy the callback URL from the GPT Action\n",
"- Navigate back to your Connected App in Salesforce, and add your callback URL.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### FAQ & Troubleshooting"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- *Callback URL Error:* If you get a callback URL error in ChatGPT, pay close attention to the screenshot above. You need to add the callback URL directly into Salesforce for the action to authenticate correctly\n",
"- *Internal Server Error:* Ensure all the correct boxes are checked and/or unchecked in the OAuth settings for your connected app. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Are there integrations that youd like us to prioritize? Are there errors in our integrations? File a PR or issue in our github, and well take a look.*\n"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1358,6 +1358,15 @@
date: 2024-07-15
authors:
- rupert-openai
tags:
- gpt-actions-library
- chatgpt
- title: GPT Actions library - Salesforce
path: examples/chatgpt/gpt_actions_library/gpt_action_salesforce.ipynb
date: 2024-07-18
authors:
- aa-openai
tags:
- gpt-actions-library
- chatgpt