Özel emoji oluşturma

Bu kılavuzda, Google Workspace kuruluşunda yeni bir özel emoji oluşturmak için Google Chat API'nin CustomEmoji kaynağında create yönteminin nasıl kullanılacağı açıklanmaktadır.

Özel emojiler yalnızca Google Workspace hesaplarında kullanılabilir ve yöneticinizin kuruluşunuz için özel emojileri etkinleştirmesi gerekir. Daha fazla bilgi için Google Chat'teki özel emojiler hakkında ve Özel emoji izinlerini yönetme başlıklı makaleleri inceleyin.

Ön koşullar

Node.js

Özel emoji oluşturma

Kullanıcı kimlik doğrulaması ile özel emoji oluşturmak için isteğinizde aşağıdakileri iletin:

  • chat.customemojis yetkilendirme kapsamını belirtin.
  • CreateCustomEmoji yöntemini çağırın.
  • İstek gövdesinde bir CustomEmoji kaynağı sağlayın, emojiName (emoji için seçtiğiniz benzersiz tanımlayıcı) ve payload (emoji için seçtiğiniz resim içeriği) değerlerini ayarlayın.

Aşağıdaki örnekte özel emoji oluşturulur:

Node.js

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

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 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: filename,
      }
    }
  };

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

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

main().catch(console.error);

Bu örneği çalıştırmak için aşağıdakileri değiştirin:

  • FILENAME: Resmin dosya adı.
  • EMOJI_NAME: Özel emojiniz için benzersiz bir ad (ör. :smiley-face:).

Chat API, oluşturulan özel emojiyi ayrıntılı olarak açıklayan bir CustomEmoji örneği döndürür.