@nekiro/kick-api
Version:
Efortlessly query kick.com api using easy to use interface with properly typed responses.
74 lines (73 loc) • 2.81 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatModule = void 0;
const errors_1 = require("../errors");
class ChatModule {
constructor(client) {
this.client = client;
this.baseRoute = "/public/v1/chat";
}
/**
* Send a chat message as either a bot or user
*
* @param params - Message parameters with conditional requirements:
* - For bot messages: only content and type are required
* - For user messages: broadcaster_user_id is also required
*
* @example Bot message
* ```typescript
* await client.chat.postMessage({
* type: "bot",
* content: "Hello from bot!"
* });
* ```
*
* @example User message
* ```typescript
* await client.chat.postMessage({
* type: "user",
* broadcaster_user_id: 12345,
* content: "Hello from user!"
* });
* ```
*
* @example Reply message
* ```typescript
* await client.chat.postMessage({
* type: "bot",
* content: "This is a reply!",
* reply_to_message_id: "original_message_id"
* });
* ```
*/
postMessage(params) {
return __awaiter(this, void 0, void 0, function* () {
if (!params || !params.content) {
throw new errors_1.KickBadRequestError("content is required");
}
if (!params.type || !["user", "bot"].includes(params.type)) {
throw new errors_1.KickBadRequestError("type must be 'user' or 'bot'");
}
if (params.content.length > 500) {
throw new errors_1.KickBadRequestError("content must be 500 characters or less");
}
if (params.type === "user" && !params.broadcaster_user_id) {
throw new errors_1.KickBadRequestError("broadcaster_user_id is required when type is 'user'");
}
return this.client.request(this.baseRoute, {
method: "POST",
body: JSON.stringify(params),
});
});
}
}
exports.ChatModule = ChatModule;