맞춤 그림 이모티콘 만들기

이 가이드에서는 Google Chat API의 CustomEmoji 리소스에서 create 메서드를 사용하여 Google Workspace 조직에서 새 맞춤 이모티콘을 만드는 방법을 설명합니다.

맞춤 이모티콘은 Google Workspace 계정에서만 사용할 수 있으며 관리자가 조직의 맞춤 이모티콘을 사용 설정해야 합니다. 자세한 내용은 Google Chat의 맞춤 이모티콘 알아보기 및 맞춤 이모티콘 권한 관리를 참고하세요.

기본 요건

Node.js

맞춤 이모티콘 만들기

사용자 인증으로 맞춤 이모티콘을 만들려면 요청에 다음을 전달하세요.

  • chat.customemojis 승인 범위를 지정합니다.
  • CreateCustomEmoji 메서드를 호출합니다.
  • 요청 본문에서 CustomEmoji 리소스를 제공하고 emojiName (이모티콘에 선택한 고유 식별자) 및 payload (이모티콘에 선택한 이미지 콘텐츠)를 설정합니다.

다음 예시에서는 맞춤 이모티콘을 만듭니다.

Node.js

chat/client-libraries/cloud/create-custom-emoji-user-cred.js
import fs from 'node:fs';
import {createClientWithUserCredentials} from './authentication-utils.js';

const USER_AUTH_OAUTH_SCOPES = [
  'https://www.googleapis.com/auth/chat.customemojis',
];

// This sample shows how to create custom emoji with user credential
async function main() {
  // Create a client
  const chatClient = await createClientWithUserCredentials(
    USER_AUTH_OAUTH_SCOPES,
  );

  // TODO(developer) Replace FILENAME here.
  const filename = 'FILENAME';
  // Read custom emoji file content into a base64 encoded string.
  const fileContent = fs.readFileSync(filename, {encoding: 'base64'});

  // Initialize request argument(s)
  const request = {
    custom_emoji: {
      // TODO(developer): Replace EMOJI_NAME here.
      emoji_name: 'EMOJI_NAME',
      payload: {
        file_content: fileContent,
        filename,
      },
    },
  };

  // Make the request
  const response = await chatClient.createCustomEmoji(request);

  // Handle the response
  console.log(response);
}

await main();

이 샘플을 실행하려면 다음을 바꿉니다.

  • FILENAME: 이미지의 파일 이름입니다.
  • EMOJI_NAME: 맞춤 이모티콘의 고유한 이름입니다(예: :smiley-face:).

Chat API는 생성된 맞춤 이모티콘을 자세히 설명하는 CustomEmoji 인스턴스를 반환합니다.