UNPKG

chat

Version:

Unified chat abstraction for Slack, Teams, Google Chat, and Discord

78 lines (60 loc) 2.45 kB
--- title: Emoji description: Type-safe, cross-platform emoji that automatically convert to each platform's format. type: reference --- The `emoji` helper provides cross-platform emoji that automatically convert to the correct format for each platform. On Slack, emoji render as `:shortcode:` format. On other platforms, they render as Unicode characters. ## Usage ```typescript title="lib/bot.ts" lineNumbers import { emoji } from "chat"; await thread.post(`${emoji.thumbs_up} Great job!`); // Slack: ":+1: Great job!" // Teams/GChat/Discord: "👍 Great job!" ``` Emoji also work in reactions: ```typescript title="lib/bot.ts" lineNumbers await sent.addReaction(emoji.check); bot.onReaction(["thumbs_up", "heart", "fire"], async (event) => { if (!event.added) return; await event.adapter.addReaction(event.threadId, event.messageId, emoji.raised_hands); }); ``` ## Available emoji | Name | Emoji | Name | Emoji | |------|-------|------|-------| | `emoji.thumbs_up` | 👍 | `emoji.thumbs_down` | 👎 | | `emoji.heart` | ❤️ | `emoji.smile` | 😊 | | `emoji.laugh` | 😂 | `emoji.thinking` | 🤔 | | `emoji.eyes` | 👀 | `emoji.fire` | 🔥 | | `emoji.check` | ✅ | `emoji.x` | ❌ | | `emoji.question` | ❓ | `emoji.party` | 🎉 | | `emoji.rocket` | 🚀 | `emoji.star` | ⭐ | | `emoji.wave` | 👋 | `emoji.clap` | 👏 | | `emoji["100"]` | 💯 | `emoji.warning` | ⚠️ | | `emoji.raised_hands` | 🙌 | `emoji.muscle` | 💪 | | `emoji.ok_hand` | 👌 | `emoji.sad` | 😢 | | `emoji.memo` | 📝 | `emoji.gear` | ⚙️ | | `emoji.wrench` | 🔧 | `emoji.bug` | 🐛 | | `emoji.calendar` | 📅 | `emoji.clock` | 🕐 | | `emoji.sun` | ☀️ | `emoji.rainbow` | 🌈 | For a one-off custom emoji, use `emoji.custom("name")`. ## Custom emoji For workspace-specific emoji with full type safety, use `createEmoji()`: ```typescript title="lib/bot.ts" lineNumbers import { createEmoji } from "chat"; const myEmoji = createEmoji({ unicorn: { slack: "unicorn_face", gchat: "🦄" }, company_logo: { slack: "company", gchat: "🏢" }, }); await thread.post(`${myEmoji.unicorn} Magic! ${myEmoji.company_logo}`); // Slack: ":unicorn_face: Magic! :company:" // GChat: "🦄 Magic! 🏢" ``` You can also extend the built-in emoji map with TypeScript module augmentation: ```typescript title="lib/emoji.d.ts" lineNumbers declare module "chat" { interface CustomEmojiMap { my_custom: EmojiFormats; } } ```