GPT 操作库:Gmail

简介

本文档为开发者提供了构建特定应用程序的 GPT 操作的说明和指南。在继续之前,请确保您已熟悉以下信息:

此 GPT 操作提供了有关如何连接到 Google Gmail 的概述,Google 的私密安全电子邮件,适用于个人或企业。此操作连接到 Google Gmail API,可以读取、发送、列出和起草已授权帐户中的电子邮件。

价值 + 示例业务用例

价值:Gmail GPT 将作为强大的工具,简化沟通流程,改善客户参与度,并优化资源分配。

示例用例

  • 通过总结冗长的电子邮件和根据先前的电子邮件线索起草回复来管理内部沟通。
  • 支持代理可以根据公司的沟通指南、语气和风格,为客户提供即时回复。
  • 引用其他 GPT,例如数据分析 GPT,然后通过电子邮件沟通起草/发送合并的分析。

应用程序信息

应用程序关键链接

在开始之前,请查看应用程序中的这些链接:

  • 应用程序网站:https://mail.google.com/mail/u/0/#inbox
  • 应用程序 API 文档:https://developers.google.com/gmail/api/guides

应用程序先决条件

在开始之前,请确保您拥有一个 Google Cloud 帐户并启用了 Gmail API:

  • 设置 Google Cloud 项目
  • 从 Google API 库启用 Gmail API
  • 如果应用程序的“发布状态”为“测试”,请确保用户已添加到您的应用程序

ChatGPT 步骤

自定义 GPT 说明

创建自定义 GPT 后,将以下文本复制到“说明”面板中。有疑问吗?请查看入门示例,了解此步骤的详细信息。

**上下文**
充当电子邮件助手,旨在以各种方式增强用户与电子邮件的交互。此 GPT 可通过总结电子邮件/线索、识别后续步骤/跟进、起草或发送预先编写的回复以及以编程方式与第三方工具(例如 Notion 待办事项、Slack 频道摘要、用于响应的数据提取)进行交互来帮助提高生产力。此 GPT 拥有对 GMAIL OAuth 2.0 API 的完全范围访问权限,能够从 Gmail 读取、撰写、发送和永久删除电子邮件。

**说明**

- 除非另有说明,否则始终以登录用户的姓名结束电子邮件。
- 验证电子邮件数据是否以所需格式正确编码(例如,消息正文的 base64)。
- 电子邮件编码过程:1\ 以 RFC 2822 格式构建电子邮件消息。2\ 对电子邮件消息进行 Base64 编码。3\ 使用 API 发送编码后的消息。
- 如果未指定,请始终使用用户名签署所有电子邮件。
- API 使用:回答用户问题后,在收到另一个问题之前,请勿再次调用 Google API。
- 所有创建、草稿或发送的电子邮件都应为纯文本。
- 确保电子邮件格式干净,并且格式与某人从自己的收件箱发送电子邮件的方式相同。创建草稿或发送电子邮件后,向用户显示一条消息,确认草稿已准备好或电子邮件已发送。
- 检查“收件人”电子邮件地址是否有效且格式正确。它应为“recipient@example.com”格式。
- 仅提供现有电子邮件的摘要;请勿捏造电子邮件内容。
- 专业性:行为专业,提供清晰简洁的回复。
- 澄清:在需要时寻求澄清,以确保准确完整地满足用户请求。
- 隐私和安全:尊重用户隐私并安全地处理所有数据。

OpenAPI 架构

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

openapi: 3.1.0

info:
  title: Gmail Email API
  version: 1.0.0
  description: API to read, write, and send emails in a Gmail account.

servers:

  - url: https://gmail.googleapis.com

paths:
  /gmail/v1/users/{userId}/messages:
    get:
      summary: List All Emails
      description: Lists all the emails in the user's mailbox.
      operationId: listAllEmails
      parameters:

        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.

        - name: q
          in: query
          schema:
            type: string
          description: Query string to filter messages (optional).

        - name: pageToken
          in: query
          schema:
            type: string
          description: Token to retrieve a specific page of results in the list.

        - name: maxResults
          in: query
          schema:
            type: integer
            format: int32
          description: Maximum number of messages to return.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageList'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error

  /gmail/v1/users/{userId}/messages/send:
    post:
      summary: Send Email
      description: Sends a new email.
      operationId: sendEmail
      parameters:

        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Message'
      responses:
        '200':
          description: Email sent successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error

  /gmail/v1/users/{userId}/messages/{id}:
    get:
      summary: Read Email
      description: Gets the full email content including headers and body.
      operationId: readEmail
      parameters:

        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.

        - name: id
          in: path
          required: true
          schema:
            type: string
          description: The ID of the email to retrieve.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FullMessage'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error

  /gmail/v1/users/{userId}/messages/{id}/modify:
    post:
      summary: Modify Label
      description: Modify labels of an email.
      operationId: modifyLabels
      parameters:

        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.

        - name: id
          in: path
          required: true
          schema:
            type: string
          description: The ID of the email to change labels.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LabelModification'
      responses:
        '200':
          description: Labels modified successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error

  /gmail/v1/users/{userId}/drafts:
    post:
      summary: Create Draft
      description: Creates a new email draft.
      operationId: createDraft
      parameters:

        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Draft'
      responses:
        '200':
          description: Draft created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Draft'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error

  /gmail/v1/users/{userId}/drafts/send:
    post:
      summary: Send Draft
      description: Sends an existing email draft.
      operationId: sendDraft
      parameters:

        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SendDraftRequest'
      responses:
        '200':
          description: Draft sent successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error

components:
  schemas:
    MessageList:
      type: object
      properties:
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
        nextPageToken:
          type: string

    Message:
      type: object
      properties:
        id:
          type: string
        threadId:
          type: string
        labelIds:
          type: array
          items:
            type: string
        addLabelIds:
          type: array
          items:
            type: string
        removeLabelIds:
          type: array
          items:
            type: string
        snippet:
          type: string
        raw:
          type: string
          format: byte
          description: The entire email message in an RFC 2822 formatted and base64url encoded string.

    FullMessage:
      type: object
      properties:
        id:
          type: string
        threadId:
          type: string
        labelIds:
          type: array
          items:
            type: string
        snippet:
          type: string
        payload:
          type: object
          properties:
            headers:
              type: array
              items:
                type: object
                properties:
                  name:
                    type: string
                  value:
                    type: string
            parts:
              type: array
              items:
                type: object
                properties:
                  mimeType:
                    type: string
                  body:
                    type: object
                    properties:
                      data:
                        type: string

    LabelModification:
      type: object
      properties:
        addLabelIds:
          type: array
          items:
            type: string
        removeLabelIds:
          type: array
          items:
            type: string

    Label:
      type: object
      properties:
        addLabelIds:
          type: array
          items:
            type: string
        removeLabelIds:
          type: array
          items:
            type: string

    EmailDraft:
      type: object
      properties:
        to:
          type: array
          items:
            type: string
        cc:
          type: array
          items:
            type: string
        bcc:
          type: array
          items:
            type: string
        subject:
          type: string
        body:
          type: object
          properties:
            mimeType:
              type: string
              enum: [text/plain, text/html]
            content:
              type: string

    Draft:
      type: object
      properties:
        id:
          type: string
        message:
          $ref: '#/components/schemas/Message'

    SendDraftRequest:
      type: object
      properties:
        draftId:
          type: string
          description: The ID of the draft to send.
        userId:
          type: string
          description: The user's email address. Use "me" to indicate the authenticated user.

Authentication Instructions

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

预操作步骤

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

  • 转到 Google Cloud 控制台
  • 导航到 API 和服务 > 凭据

gptactions_BigQuery_auth.png

gptactions_BigQuery_auth.png

  • 创建新的 OAuth 凭据(或使用现有的)

gptactions_BigQuery_auth.png

  • 找到您的 OAuth 客户端 ID 和客户端密钥,并将这两个值安全地存储起来(请参见下图)

gptactions_BigQuery_auth.png

在 ChatGPT 中

在 ChatGPT 中,点击“身份验证”并选择“OAuth”。在此处输入信息。

  • 客户端 ID:使用以上步骤中的客户端 ID
  • 客户端密钥:使用以上步骤中的客户端密钥
  • 授权 URL:https://accounts.google.com/o/oauth2/auth
  • 令牌 URL:https://oauth2.googleapis.com/token
  • 范围:https://mail.google.com/
  • 令牌:默认(POST)

后续操作步骤

在 ChatGPT 中设置身份验证后,请在应用程序中执行以下步骤以完成操作。

  • 复制 GPT 操作中的回调 URL
  • 在“授权的重定向 URI”(请参见上图)中,添加您的回调 URL

常见问题解答和故障排除

  • 回调 URL 错误:如果在 ChatGPT 中遇到回调 URL 错误,请仔细查看上面的屏幕截图。您需要将回调 URL 直接添加到 GCP 中,操作才能正确进行身份验证
  • 架构调用错误的项或数据集:如果 ChatGPT 调用错误的项或数据集,请考虑更新您的说明,使其更明确地(a)应调用哪个项/数据集或(b)要求用户在运行查询前提供这些确切的详细信息

您希望我们优先处理哪些集成?我们的集成中是否存在错误?在我们的 GitHub 中提交 PR 或 issue,我们将进行查看。