/** * Twitch resolver adapter for channel/user name resolution. * * This module implements the ChannelResolverAdapter interface to resolve * Twitch usernames to user IDs via the Twitch Helix API.
*/
import { ApiClient } from "@twurple/api"; import { StaticAuthProvider } from "@twurple/auth"; import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime"; import type { ChannelResolveKind, ChannelResolveResult } from "./types.js"; import type { ChannelLogSink, TwitchAccountConfig } from "./types.js"; import { normalizeToken } from "./utils/twitch.js";
/** * Normalize a Twitch username - strip @ prefix and convert to lowercase
*/ function normalizeUsername(input: string): string { const trimmed = input.trim(); if (trimmed.startsWith("@")) { return normalizeLowercaseStringOrEmpty(trimmed.slice(1));
} return normalizeLowercaseStringOrEmpty(trimmed);
}
/** * Create a logger that includes the Twitch prefix
*/ function createLogger(logger?: ChannelLogSink): ChannelLogSink { return {
info: (msg: string) => logger?.info(msg),
warn: (msg: string) => logger?.warn(msg),
error: (msg: string) => logger?.error(msg),
debug: (msg: string) => logger?.debug?.(msg) ?? (() => {}),
};
}
/** * Resolve Twitch usernames to user IDs via the Helix API * * @param inputs - Array of usernames or user IDs to resolve * @param account - Twitch account configuration with auth credentials * @param kind - Type of target to resolve ("user" or "group") * @param logger - Optional logger * @returns Promise resolving to array of ChannelResolveResult
*/
export async function resolveTwitchTargets(
inputs: string[],
account: TwitchAccountConfig,
kind: ChannelResolveKind,
logger?: ChannelLogSink,
): Promise<ChannelResolveResult[]> { const log = createLogger(logger);
if (!account.clientId || !account.accessToken) {
log.error("Missing Twitch client ID or accessToken"); return inputs.map((input) => ({
input,
resolved: false,
note: "missing Twitch credentials",
}));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.