UNPKG

fnbr

Version:

A library to interact with Epic Games' Fortnite HTTP and XMPP services

74 lines 3.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const crypto_1 = require("crypto"); const Endpoints_1 = tslib_1.__importDefault(require("../../resources/Endpoints")); const enums_1 = require("../../resources/enums"); const Base_1 = tslib_1.__importDefault(require("../Base")); const UserNotFoundError_1 = tslib_1.__importDefault(require("../exceptions/UserNotFoundError")); // private scope const generateCustomCorrelationId = () => `EOS-${Date.now()}-${(0, crypto_1.randomUUID)()}`; /** * Represent's the client's chat manager (dm, party chat) via eos. */ class ChatManager extends Base_1.default { /** * Returns the chat namespace, this is the eos deployment id */ get namespace() { return this.client.config.eosDeploymentId; } /** * Sends a private message to the specified user * @param user the account id or displayname * @param message the message object * @returns the message id * @throws {UserNotFoundError} When the specified user was not found * @throws {EpicgamesAPIError} When the api request failed */ async whisperUser(user, message) { const accountId = await this.client.user.resolveId(user); if (!accountId) { throw new UserNotFoundError_1.default(user); } const correlationId = generateCustomCorrelationId(); await this.client.http.epicgamesRequest({ method: 'POST', url: `${Endpoints_1.default.EOS_CHAT}/v1/public/${this.namespace}/whisper/${this.client.user.self.id}/${accountId}`, headers: { 'Content-Type': 'application/json', 'X-Epic-Correlation-ID': correlationId, }, data: { message, }, }, enums_1.AuthSessionStoreKey.FortniteEOS); return correlationId; } /** * Sends a message in the specified conversation (party chat) * @param conversationId the conversation id, usually `p-[PARTYID]` * @param message the message object * @param allowedRecipients the account ids, that should receive the message * @returns the message id * @throws {EpicgamesAPIError} When the api request failed */ async sendMessageInConversation(conversationId, message, allowedRecipients) { const correlationId = generateCustomCorrelationId(); await this.client.http.epicgamesRequest({ method: 'POST', url: `${Endpoints_1.default.EOS_CHAT}/v1/public/${this.namespace}/conversations/${conversationId}/messages?fromAccountId=${this.client.user.self.id}`, headers: { 'Content-Type': 'application/json', 'X-Epic-Correlation-ID': correlationId, }, data: { allowedRecipients, message, }, }, enums_1.AuthSessionStoreKey.FortniteEOS); return correlationId; } } exports.default = ChatManager; //# sourceMappingURL=ChatManager.js.map