Skip to content

nanocoai/nanoclaw / .claude/skills/add-mattermost

add-mattermost

Flagged

Add a self-hosted or cloud Mattermost bot channel through the Chat SDK bridge, reusing a healthy server when available and linking to official server setup guidance when needed.

FileKindSize
REMOVE.mdmarkdown1.5 KB
SERVER_SETUP.mdmarkdown1.3 KB
SKILL.mdskill md16.8 KB
apply-fixtures.jsonconfig5.8 KB
scripts/configure.tsscript3.2 KB
scripts/discover-server.mjsscript3.8 KB
scripts/read-response.mjsscript1.0 KB
scripts/remove-base-url.mjsexecutablescript335 B
scripts/remove-config.mjsexecutablescript381 B
scripts/select-server.mjsscript1020 B
scripts/verify-runtime.tsscript9.8 KB

scripts/configure.ts

View on GitHub
import { randomBytes } from 'node:crypto';
import { pathToFileURL } from 'node:url';

import { envValue } from '../../../../src/env.js';
import { upsertEnvVars } from '../../../../setup/set-env.js';

const urlShape =
  /^https?:\/\/(?:[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?|\[[0-9A-Fa-f:.]+\])(?::[0-9]{1,5})?(?:\/[A-Za-z0-9._~%+-]+)*$/;

export async function configure(
  baseUrl: string,
  botToken: string,
  callbackUrl: string,
): Promise<{ id: string; username: string }> {
  // Validate before the first write, including direct helper invocations. The
  // helper also owns authentication, so a failed earlier skill step can never
  // cause an unverified replacement credential to be persisted.
  for (const [label, value] of [
    ['base URL', baseUrl],
    ['callback URL', callbackUrl],
  ]) {
    if (!urlShape.test(value)) throw new Error(`Invalid Mattermost ${label}`);
    new URL(value); // also rejects invalid ports / IPv6 literals
  }
  if (!/^[A-Za-z0-9_-]{20,}$/.test(botToken)) throw new Error('Invalid Mattermost bot token');

  // This gate also protects direct helper calls and a resumed skill whose
  // earlier configuration check failed. Never persist a different SiteURL.
  const configResponse = await fetch(`${baseUrl}/api/v4/config/client?format=old`, {
    redirect: 'error',
    signal: AbortSignal.timeout(15_000),
  });
  if (!configResponse.ok) throw new Error('Could not verify Mattermost server configuration');
  const config = (await configResponse.json()) as Record<string, unknown>;
  if (config.SiteURL !== baseUrl || (config.WebsocketURL ?? '') !== '') {
    throw new Error('Mattermost SiteURL must match the selected URL and WebsocketURL must be blank');
  }

  const response = await fetch(`${baseUrl}/api/v4/users/me`, {
    headers: { Authorization: `Bearer ${botToken}` },
    redirect: 'error',
    signal: AbortSignal.timeout(15_000),
  });
  if (!response.ok) throw new Error('Mattermost rejected the bot token');
  const user = (await response.json()) as { id?: unknown; username?: unknown; is_bot?: unknown };
  if (
    typeof user.id !== 'string' ||
    !/^[a-z0-9]{26}$/.test(user.id) ||
    typeof user.username !== 'string' ||
    !/^[a-z0-9][a-z0-9._-]{0,63}$/.test(user.username) ||
    user.is_bot !== true
  ) {
    throw new Error('Mattermost did not return a valid bot account');
  }

  // Existing cards carry this secret. Rerunning setup must not invalidate them.
  // Generate it here so it never becomes a public skill capture or result var.
  const secret = envValue('MATTERMOST_CALLBACK_SECRET') ?? randomBytes(32).toString('hex');
  upsertEnvVars({
    MATTERMOST_BASE_URL: baseUrl,
    MATTERMOST_BOT_TOKEN: botToken,
    MATTERMOST_CALLBACK_URL: callbackUrl,
    MATTERMOST_CALLBACK_SECRET: secret,
  });
  return { id: user.id, username: user.username };
}

if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
  try {
    const [baseUrl = '', botToken = '', callbackUrl = ''] = process.argv.slice(2);
    const identity = await configure(baseUrl, botToken, callbackUrl);
    console.log(JSON.stringify(identity));
  } catch {
    console.error(
      'Could not authenticate and save Mattermost settings. Check server reachability, URLs, and the bot token.',
    );
    process.exitCode = 1;
  }
}
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall