Gato GraphQL + Yoast SEO + ChatGPT + MasterStudy LMS 데모

ChatGPT를 사용하여 MasterStudy LMS 강좌 및 레슨에 Yoast SEO 메타데이터 생성하기

ChatGPT를 사용하여 MasterStudy LMS 강좌 및 레슨의 SEO 메타데이터를 Yoast에서 자동으로 생성하고 업데이트합니다

Leonardo Losoviz
Leonardo Losoviz -
Logo
Image
Target Image
Target Image
Target Image

ChatGPT를 사용하여 MasterStudy LMS 강좌 및 레슨의 SEO 메타데이터를 자동으로 생성하고 업데이트한 후, 해당 메타데이터를 Yoast SEO에 저장할 수 있습니다. 이 모든 작업을 단일 Gato GraphQL 쿼리로 실행할 수 있습니다.

이 데모에서는 GraphQL을 사용하여 다음을 수행합니다:

  1. MasterStudy LMS에서 강좌 또는 레슨 데이터 가져오기
  2. ChatGPT를 호출하여 강좌 또는 레슨 데이터를 기반으로 SEO 메타데이터 생성하기
  3. 해당 강좌 또는 레슨의 Yoast SEO 메타데이터 업데이트하기

다음 변수를 제공해야 합니다:

  • courseOrLessonId: 업데이트할 MasterStudy LMS 강좌 또는 레슨의 ID
  • openAIAPIKey: OpenAI API의 API 키

필요한 커스텀 게시물 유형의 데이터에 대한 접근을 허용하도록 설정해야 합니다: stm-coursesstm-lessons.

GraphQL 쿼리는 다음과 같습니다:

query GetCourseOrLessonData($courseOrLessonId: ID!) {
  courseOrLesson: customPost(by: { id: $courseOrLessonId }, customPostTypes: ["stm-courses", "stm-lessons"]) {
    id
    ...on CustomPost {
      title
        @export(as: "title")
      content
        @export(as: "content")
    }
    ...WithMetaData
  }
}
 
query GenerateCourseSEOWithChatGPT(
  $openAIAPIKey: String!
  $systemMessage: String! = "You are an SEO specialist"
  $promptTemplate: String! = """
I'm working on creating the SEO metadata for courses and lessons in my Learning Management System.
 
Please evaluate the course or lesson data, and generate the following SEO metadata:
 
- Title
- Excerpt
- Focus Keyword
- Open Graph Title
- Open Graph Description
- Twitter Title
- Twitter Description
 
The data is:
 
- Title: {$title}
- Content: {$content}
"""
  $model: String! = "gpt-4o-mini"
)
  @depends(on: "GetCourseOrLessonData")
{
  prompt: _strReplaceMultiple(
    search: ["{$title}", "{$content}"],
    replaceWith: [$title, $content],
    in: $promptTemplate
  )
  openAIResponse: _sendJSONObjectItemHTTPRequest(input: {
    url: "https://api.openai.com/v1/chat/completions",
    method: POST,
    options: {
      auth: {
        password: $openAIAPIKey
      },
      json: {
        model: $model,
        messages: [
          {
            role: "system",
            content: $systemMessage
          },
          {
            role: "user",
            content: $__prompt
          },
        ],
        response_format: {
          type: "json_schema",
          json_schema: {
            name: "seo_metadata_response",
            strict: true,
            schema: {
              type: "object",
              properties: {
                seoMetadata: {
                  type: "object",
                  properties: {
                    title: {
                      type: "string"
                    },
                    excerpt: {
                      type: "string"
                    },
                    focusKeyword: {
                      type: "string"
                    },
                    openGraphTitle: {
                      type: "string"
                    },
                    openGraphDescription: {
                      type: "string"
                    },
                    twitterTitle: {
                      type: "string"
                    },
                    twitterDescription: {
                      type: "string"
                    }
                  },
                  required: ["title", "excerpt", "focusKeyword", "openGraphTitle", "openGraphDescription", "twitterTitle", "twitterDescription"],
                  additionalProperties: false
                }
              },
              required: ["seoMetadata"],
              additionalProperties: false
            }
          }
        }
      }
    }
  })
    @underJSONObjectProperty(by: { key: "choices" })
      @underArrayItem(index: 0)
        @underJSONObjectProperty(by: { path: "message.content" })
          @export(as: "jsonEncodedSeoMetadataResponse")
}
 
query ExtractSeoMetadata
  @depends(on: "GenerateCourseSEOWithChatGPT")
{
  decodedSeoMetadataResponse: _strDecodeJSONObject(string: $jsonEncodedSeoMetadataResponse)
    @underJSONObjectProperty(by: { path: "seoMetadata" })
      @export(as: "seoMetadata")
}
 
mutation GenerateSeoMetadataAndUpdateYoast(
  $courseOrLessonId: ID!
)
  @depends(on: "ExtractSeoMetadata")
{
  seoMetadataTitle: _objectProperty(
    object: $seoMetadata,
    by: { key: "title" }
  )
  seoMetadataExcerpt: _objectProperty(
    object: $seoMetadata,
    by: { key: "excerpt" }
  )
  seoMetadataFocusKeyword: _objectProperty(
    object: $seoMetadata,
    by: { key: "focusKeyword" }
  )
  seoMetadataOpenGraphTitle: _objectProperty(
    object: $seoMetadata,
    by: { key: "openGraphTitle" }
  )
  seoMetadataOpenGraphDescription: _objectProperty(
    object: $seoMetadata,
    by: { key: "openGraphDescription" }
  )
  seoMetadataTwitterTitle: _objectProperty(
    object: $seoMetadata,
    by: { key: "twitterTitle" }
  )
  seoMetadataTwitterDescription: _objectProperty(
    object: $seoMetadata,
    by: { key: "twitterDescription" }
  )
 
  updateCustomPostMetas(inputs: [
    { id: $courseOrLessonId, key: "_yoast_wpseo_title", value: $__seoMetadataTitle },
    { id: $courseOrLessonId, key: "_yoast_wpseo_metadesc", value: $__seoMetadataExcerpt },
    { id: $courseOrLessonId, key: "_yoast_wpseo_focuskw", value: $__seoMetadataFocusKeyword },
    { id: $courseOrLessonId, key: "_yoast_wpseo_opengraph-title", value: $__seoMetadataOpenGraphTitle },
    { id: $courseOrLessonId, key: "_yoast_wpseo_opengraph-description", value: $__seoMetadataOpenGraphDescription },
    { id: $courseOrLessonId, key: "_yoast_wpseo_twitter-title", value: $__seoMetadataTwitterTitle },
    { id: $courseOrLessonId, key: "_yoast_wpseo_twitter-description", value: $__seoMetadataTwitterDescription }
  ]) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
  }
}
 
query GenerateAndUpdateCourseOrLessonSeoMetadataAndCheckResults($courseOrLessonId: ID!)
  @depends(on: "GenerateSeoMetadataAndUpdateYoast")
{
  courseOrLessonResults: customPost(by: { id: $courseOrLessonId }, customPostTypes: ["stm-courses", "stm-lessons"]) {
    id
    ...WithMetaData
  }
}
 
fragment WithMetaData on WithMeta {
  metaTitle: metaValue(key: "_yoast_wpseo_title")
  metaDesc: metaValue(key: "_yoast_wpseo_metadesc")
  focusKeyword: metaValue(key: "_yoast_wpseo_focuskw")
  socialFBTitle: metaValue(key: "_yoast_wpseo_opengraph-title")
  socialFBDesc: metaValue(key: "_yoast_wpseo_opengraph-description")
  socialTwitterTitle: metaValue(key: "_yoast_wpseo_twitter-title")
  socialTwitterDesc: metaValue(key: "_yoast_wpseo_twitter-description")
}

변수는 다음과 같습니다:

{
  "courseOrLessonId": "123",
  "openAIAPIKey": "sk-..."
}

뉴스레터 구독하기

Gato GraphQL의 모든 업데이트를 놓치지 마세요.