Create a custom emoji
Stay organized with collections
Save and categorize content based on your preferences.
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
- A Business or Enterprise Google Workspace account with access to Google Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Install the Node.js Cloud Client Library.
-
Create OAuth client ID credentials for a desktop application. To run the sample in this
guide, save the credentials as a JSON file named
credentials.json
to your local directory.
- Choose an authorization scope that supports user authentication.
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 theemojiName
(a unique identifier you choose for the emoji) andpayload
(image content you choose for the emoji).
The following example creates a custom emoji:
Node.js
importfsfrom'node:fs'; import{createClientWithUserCredentials}from'./authentication-utils.js'; constUSER_AUTH_OAUTH_SCOPES=[ 'https://www.googleapis.com/auth/chat.customemojis', ]; // This sample shows how to create custom emoji with user credential asyncfunctionmain(){ // Create a client constchatClient=awaitcreateClientWithUserCredentials( USER_AUTH_OAUTH_SCOPES, ); // TODO(developer) Replace FILENAME here. constfilename='FILENAME'; // Read custom emoji file content into a base64 encoded string. constfileContent=fs.readFileSync(filename,{encoding:'base64'}); // Initialize request argument(s) constrequest={ custom_emoji:{ // TODO(developer): Replace EMOJI_NAME here. emoji_name:'EMOJI_NAME', payload:{ file_content:fileContent, filename, }, }, }; // Make the request constresponse=awaitchatClient.createCustomEmoji(request); // Handle the response console.log(response); } awaitmain();
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.