สร้างอีโมจิที่กำหนดเอง

คู่มือนี้อธิบายวิธีใช้เมธอด create ในทรัพยากร CustomEmoji ของ Google Chat API เพื่อสร้างอีโมจิ ที่กำหนดเองใหม่ในองค์กร Google Workspace

อีโมจิที่กำหนดเองจะใช้ได้กับบัญชี Google Workspace เท่านั้น และผู้ดูแลระบบต้องเปิดอีโมจิที่กำหนดเองให้องค์กร ดูข้อมูลเพิ่มเติมได้ที่ดูข้อมูลเกี่ยวกับอีโมจิที่กำหนดเองใน Google Chat และจัดการสิทธิ์ของอีโมจิที่กำหนดเอง

ข้อกำหนดเบื้องต้น

Node.js

  • บัญชี Google Workspace สำหรับธุรกิจหรือองค์กร ที่มีสิทธิ์เข้าถึง Google Chat

สร้างอีโมจิที่กำหนดเอง

หากต้องการสร้างอีโมจิที่กำหนดเองด้วยการตรวจสอบสิทธิ์ผู้ใช้ ให้ส่งข้อมูลต่อไปนี้ในคำขอ

  • ระบุchat.customemojisขอบเขตการให้สิทธิ์
  • เรียกใช้เมธอด CreateCustomEmoji
  • ในเนื้อหาคำขอ ให้ระบุCustomEmojiรีซอร์ส โดยตั้งค่า emojiName (ตัวระบุที่ไม่ซ้ำกันที่คุณเลือกสำหรับอีโมจิ) และ payload (เนื้อหารูปภาพที่คุณเลือกสำหรับอีโมจิ)

ตัวอย่างต่อไปนี้สร้างอีโมจิที่กำหนดเอง

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

หากต้องการเรียกใช้ตัวอย่างนี้ ให้แทนที่ข้อมูลต่อไปนี้

  • FILENAME: ชื่อไฟล์ของรูปภาพ
  • EMOJI_NAME: ชื่อที่ไม่ซ้ำสำหรับอีโมจิที่กำหนดเอง เช่น :smiley-face:

Chat API จะแสดงอินสแตนซ์ของ CustomEmoji ซึ่งแสดงรายละเอียดของอีโมจิที่กำหนดเองที่สร้างขึ้น