Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
// Reactions on chat messages. A π on a bot's message is the person's reply to it. A π answers only an open card or a
// line in a person's inbox; elsewhere it, like the others, is quiet feedback the bot reads with its next turn.
/** Every reaction a client offers and the server accepts, in the order clients show them. */
export const REACTIONS = ["π", "π", "β€οΈ", "π", "π", "π"] as const;
export type Reaction = (typeof REACTIONS)[number];
/** What a reaction did, as POST /api/threads/:threadId/messages/:messageId/reactions reports it: a turn `started` with
* it as the person's reply to that message, or the reply waits `queued` behind the running turn; the open card on the
* message was `answered`; feedback the bot reads with its next turn (`noted`); or nothing reached a bot. */
export type ReactionDelivery = "started" | "queued" | "answered" | "noted" | "none";
/** π answers yes and π answers no (π only on a card or an inbox line); any other reaction answers nothing. */
export function reactionAnswer(emoji: string | null | undefined): "yes" | "no" | null {
return emoji === "π" ? "yes" : emoji === "π" ? "no" : null;
}
/** Slack sends a reaction's short name. Telegram, Discord and WhatsApp send the emoji itself. */
const SLACK_NAMES: Readonly<Record<string, Reaction>> = {
"+1": "π", thumbsup: "π", "-1": "π", thumbsdown: "π", heart: "β€οΈ", joy: "π", tada: "π", eyes: "π",
};
const SLACK_NAME = /^:?([a-z0-9_+-]+)(?:::skin-tone-[2-6])?:?$/;
/** Skin tones and the emoji presentation selector, which each platform adds or drops on its own. */
const VARIANTS = /[\u{1F3FB}-\u{1F3FF}]|\uFE0F/gu;
/** The reaction a person meant, from any client or chat channel: the emoji in any skin tone or presentation, or
* Slack's name for it. Null for anything outside REACTIONS. */
export function normalizeReaction(raw: unknown): Reaction | null {
if (typeof raw !== "string" || raw.length > 64) return null;
const value = raw.trim();
const name = SLACK_NAME.exec(value.toLowerCase())?.[1];
if (name) return Object.hasOwn(SLACK_NAMES, name) ? SLACK_NAMES[name]! : null;
const bare = value.replace(VARIANTS, "");
return REACTIONS.find((reaction) => reaction.replace(VARIANTS, "") === bare) ?? null;
}