Membuat emoji kustom

Panduan ini menjelaskan cara menggunakan metode create pada resource CustomEmoji Google Chat API untuk membuat emoji kustom baru di organisasi Google Workspace.

Emoji kustom hanya tersedia untuk akun Google Workspace, dan administrator Anda harus mengaktifkan emoji kustom untuk organisasi Anda. Untuk informasi selengkapnya, lihat Mempelajari emoji kustom di Google Chat dan Mengelola izin emoji kustom.

Prasyarat

Node.js

Membuat emoji kustom

Untuk membuat emoji kustom dengan autentikasi pengguna, teruskan hal berikut dalam permintaan Anda:

  • Tentukan cakupan otorisasi chat.customemojis.
  • Panggil metode CreateCustomEmoji.
  • Dalam isi permintaan, berikan resource CustomEmoji, tetapkan emojiName (ID unik yang Anda pilih untuk emoji) dan payload (konten gambar yang Anda pilih untuk emoji).

Contoh berikut membuat emoji kustom:

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);

Untuk menjalankan contoh ini, ganti berikut ini:

  • FILENAME: Nama file gambar.
  • EMOJI_NAME: Nama unik untuk emoji kustom Anda, seperti :smiley-face:.

Chat API menampilkan instance CustomEmoji yang menjelaskan emoji kustom yang dibuat.