Create a custom emoji

This guide explains how to use the create method on the CustomEmoji resource of the Google Chat API to create a new custom emoji in a Google Workspace organization.

Custom emojis are only available for Google Workspace accounts, and your administrator must turn custom emoji on for your organization. For more information, see Learn about custom emoji in Google Chat and Manage custom emoji permissions.

Prerequisites

Node.js

Create a custom emoji

To create a custom emoji with user authentication, pass the following in your request:

  • Specify the chat.customemojis authorization scope.
  • Call the CreateCustomEmoji method.
  • In the request body, provide a CustomEmoji resource, setting the emojiName (a unique identifier you choose for the emoji) and payload (image content you choose for the emoji).

The following example creates a custom emoji:

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

To run this sample, replace the following:

  • FILENAME: A filename of the image.
  • EMOJI_NAME: A unique name for your custom emoji, like :smiley-face:.

The Chat API returns an instance of CustomEmoji that details the custom emoji that was created.