UNPKG

sendingnetwork-bot-sdk

Version:
76 lines 4.03 kB
"use strict"; 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.UnstableAppserviceApis = void 0; /** * Unstable APIs that shouldn't be used in most circumstances for appservices. * @category Unstable APIs */ class UnstableAppserviceApis { constructor(client) { this.client = client; this.requestId = 0; } /** * Send several historical events into a room. * @param {string} roomId The roomID to send to. * @param {string} prevEventId The event ID where this batch will be inserted * @param {string} chunkId The chunk ID returned from a previous call. Set falsy to start at the beginning. * @param {any[]} events A set of event contents for events to be inserted into the room. * @param {any[]} stateEventsAtStart A set of state events to be inserted into the room. Defaults to empty. * @returns A set of eventIds and the next chunk ID */ sendHistoricalEventBatch(roomId, prevEventId, events, stateEventsAtStart = [], chunkId) { return __awaiter(this, void 0, void 0, function* () { return this.client.doRequest("POST", `/_api/client/unstable/org.sdn.msc2716/rooms/${encodeURIComponent(roomId)}/batch_send`, { prev_event: prevEventId, chunk_id: chunkId, }, { events, state_events_at_start: stateEventsAtStart, }); }); } /** * Sends an event to the given room with a given timestamp. * @param {string} roomId the room ID to send the event to * @param {string} eventType the type of event to send * @param {string} content the event body to send * @param {number} ts The origin_server_ts of the new event * @returns {Promise<string>} resolves to the event ID that represents the event */ sendEventWithTimestamp(roomId, eventType, content, ts) { return __awaiter(this, void 0, void 0, function* () { const txnId = `${(new Date().getTime())}__inc_appts${++this.requestId}`; const path = `/_api/client/v3/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/${encodeURIComponent(txnId)}`; const response = yield this.client.doRequest("PUT", path, { ts }, content); return response.event_id; }); } /** * Sends a state event to the given room with a given timestamp. * @param {string} roomId the room ID to send the event to * @param {string} type the event type to send * @param {string} stateKey the state key to send, should not be null * @param {string} content the event body to send * @param {number} ts The origin_server_ts of the new event * @returns {Promise<string>} resolves to the event ID that represents the message */ sendStateEventWithTimestamp(roomId, type, stateKey, content, ts) { return __awaiter(this, void 0, void 0, function* () { const path = `/_api/client/v3/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(type)}/${encodeURIComponent(stateKey)}`; const response = yield this.client.doRequest("PUT", path, { ts }, content); return response.event_id; }); } } exports.UnstableAppserviceApis = UnstableAppserviceApis; //# sourceMappingURL=UnstableAppserviceApis.js.map