GPT Actions library - Salesforce

2024 年 7 月 18 日
在 Github 中打开

这个特定的 GPT Action 概述了如何连接到 Salesforce,特别是 Salesforce Service Cloud。此 Action 中详细描述的架构允许用户直接从 ChatGPT 中提取案例数据和更新案例。为其他 Salesforce Cloud 解决方案创建 Actions 的设置过程使用相同的连接应用程序和身份验证设置,但需要不同的 API 架构。

价值:用户现在可以利用 ChatGPT 的自然语言功能直接连接到 Salesforce

示例用例:

  • 缩短客户平均响应时间
  • 减少案例或问题故障排除时间
  • 与 GPT 中的知识和说明相结合,确保在回复客户时品牌声音更加一致

在开始之前,请确保在您的应用程序环境中完成以下步骤

  • 确保您拥有在 Salesforce 中创建应用程序的权限

创建自定义 GPT 后,将以下文本复制到“Instructions”(指令)面板中。有疑问?查看入门示例,了解此步骤的详细工作原理。

**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.

**Instructions**:
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.
2. If the user asks you to update the case details, use the action updateCaseStatus.

**Example**: 
User: Help me solve case 00001104 in Service Cloud.

创建自定义 GPT 后,将以下文本复制到“Actions”(操作)面板中。有疑问?查看入门示例,了解此步骤的详细工作原理。

openapi: 3.1.0
info:
  title: Salesforce Service Cloud Case Update API
  description: API for updating the status of Service Cloud tickets (cases) in Salesforce.
  version: 1.0.3
servers:
  - url: https://your_instance.my.salesforce.com
    description: Base URL for your Salesforce instance (replace 'your_instance' with your actual Salesforce domain)
paths:
  /services/data/v60.0/sobjects/Case/{CaseId}:
    patch:
      operationId: updateCaseStatus
      summary: Updates the status of a Service Cloud case
      description: Updates the status of a Service Cloud ticket based on the case ID number.
      parameters:
        - name: CaseId
          in: path
          required: true
          description: The ID of the case to update.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                Status:
                  type: string
                  description: The new status of the case.
      responses:
        '204':
          description: Successfully updated the case status
        '400':
          description: Bad request - invalid input or case ID not found
        '401':
          description: Unauthorized - authentication required
        '404':
          description: Not Found - case ID does not exist
    delete:
      operationId: deleteCase
      summary: Deletes a Service Cloud case
      description: Deletes a Service Cloud ticket based on the case ID number.
      parameters:
        - name: CaseId
          in: path
          required: true
          description: The ID of the case to delete.
          schema:
            type: string
      responses:
        '204':
          description: Successfully deleted the case
        '400':
          description: Bad request - invalid case ID
        '401':
          description: Unauthorized - authentication required
        '404':
          description: Not Found - case ID does not exist
  /services/data/v60.0/query:
    get:
      operationId: getCaseDetailsFromNumber
      summary: Retrieves case details using a case number
      description: Retrieves the details of a Service Cloud case associated with a given case number.
      parameters:
        - name: q
          in: query
          required: true
          description: SOQL query string to find the Case details based on Case Number.
          schema:
            type: string
            example: "SELECT Id, CaseNumber, Status, Subject, Description FROM Case WHERE CaseNumber = '123456'"
      responses:
        '200':
          description: Successfully retrieved the case details
          content:
            application/json:
              schema:
                type: object
                properties:
                  totalSize:
                    type: integer
                  done:
                    type: boolean
                  records:
                    type: array
                    items:
                      type: object
                      properties:
                        Id:
                          type: string
                        CaseNumber:
                          type: string
                        Status:
                          type: string
                        Subject:
                          type: string
                        Description:
                          type: string
        '400':
          description: Bad request - invalid query
        '401':
          description: Unauthorized - authentication required
        '404':
          description: Not Found - case number does not exist

以下是关于使用此第三方应用程序设置身份验证的说明。有疑问?查看入门示例,了解此步骤的详细工作原理。

在 ChatGPT 中设置身份验证之前,请在应用程序中执行以下步骤。

在 ChatGPT 中设置身份验证之前,请在应用程序中执行以下步骤。

  1. 导航到 Salesforce 设置

gptactions_salesforce.png

  1. 搜索 “App Manager”(应用程序管理器)

gptactions_salesforce.png

  1. 点击 “New Connected App”(新建连接的应用程序)
  2. 输入连接的应用程序名称
  3. 输入联系人电子邮件(您的电子邮件)
  4. 选中复选框以启用 OAuth 设置
  5. 插入回调 URL(现在使用占位符,例如 https://chat.openai.com/aip//oauth/callback,稍后在 ChatGPT 中创建 Action 时再更新此 URL)

gptactions_salesforce.png

  1. 选择 “Selected OAuth Scopes”(选定的 OAuth 范围)并授予适当的权限。根据您的内部安全策略确定范围。

gptactions_salesforce.png

  1. 确保选中以下框
  • 启用客户端凭据流
  • 启用授权代码和凭据流
  • 启用令牌交换流
  1. 确保取消选中以下框
  • 要求支持的授权流使用代码交换的 Proof Key (PKCE) 扩展

gptactions_salesforce.png

  1. 保存您的新连接的应用程序
  2. 在 “Consumer Key and Secret”(消费者密钥和密钥)下,单击 “Manage Consumer Details”(管理消费者详细信息)。使用通过电子邮件发送到您帐户的代码验证您的访问权限,然后复制密钥和密钥。
  • Salesforce 消费者密钥 = ChatGPT 客户端 ID
  • Salesforce 消费者密钥 = ChatGPT 客户端密钥

gptactions_salesforce.png

  1. 返回应用程序页面
  2. 点击 “Manage”(管理)
  3. 点击 “Edit Policies”(编辑策略)
  4. 在 “OAuth Policies”(OAuth 策略)下,选中 “Enable Token Exchange Flow”(启用令牌交换流)框

gptactions_salesforce.png

  1. 点击保存!

在 ChatGPT 中,单击 “Authentication”(身份验证)并选择 “OAuth”。输入以下信息。

  • 客户端 ID:使用上述步骤中的客户端 ID
  • 客户端密钥:使用上述步骤中的客户端密钥
  • 授权 URL:https://[在此处插入 URL].my.salesforce.com/services/oauth2/authorize
  • 令牌 URL:https://[在此处插入 URL].my.salesforce.com/services/oauth2/token
  • 范围:full
  • 令牌:默认 (POST)

在 ChatGPT 中设置身份验证后,请按照应用程序中的以下步骤完成 Action。

  • 从 GPT Action 复制回调 URL
  • 导航回 Salesforce 中的连接的应用程序,并添加您的回调 URL。
  • 回调 URL 错误: 如果您在 ChatGPT 中收到回调 URL 错误,请密切注意上面的屏幕截图。您需要将回调 URL 直接添加到 Salesforce 中,以便 Action 正确进行身份验证
  • 内部服务器错误: 确保在连接的应用程序的 OAuth 设置中选中和/或取消选中所有正确的框。

您希望我们优先考虑哪些集成?我们的集成中是否存在错误?在我们的 github 中提交 PR 或 issue,我们会查看。