diff --git a/dist/send_message/send_message.js b/dist/send_message/send_message.js index 479a781..98ac8b0 100644 --- a/dist/send_message/send_message.js +++ b/dist/send_message/send_message.js @@ -1,10 +1,27 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nomoSendMessage = void 0; +const tslib_1 = require("tslib"); +const axios_1 = tslib_1.__importDefault(require("axios")); +const server = 'https://zeniq.chat/'; /** * TODO: document here */ -async function nomoSendMessage(args) { - console.log("nomoSendMessage not implemented"); +async function nomoSendMessage(args, accessToken) { + let { roomId, content, transationID, eventType } = args; + const url = server + `_matrix/client/v3/rooms/${roomId}/send/${eventType}/${transationID}`; + try { + const response = await axios_1.default.put(url, content, { + headers: { + 'Authorization': `Bearer ${accessToken}`, + 'Content-Type': 'application/json' + } + }); + return response.data['event_id']; + } + catch (error) { + console.error('Error sending message:', error); + return ""; + } } exports.nomoSendMessage = nomoSendMessage; diff --git a/dist/syncing/sync_user.js b/dist/syncing/sync_user.js index 93dfeb2..c8b7b8a 100644 --- a/dist/syncing/sync_user.js +++ b/dist/syncing/sync_user.js @@ -14,13 +14,12 @@ async function nomoSyncUser(accessToken, since, filter, setPresence, fullState) // If the access_token is required as a query parameter // 'access_token': accessToken, // 'filter': filter, // The sync filter to use - 'since': since, // Pass the 'since' token from the previous sync or initial login + // 'since': since, // Pass the 'since' token from the previous sync or initial login // 'set_presence': setPresence, // Controls the presence state of the client // 'timeout': 1000, // The maximum time to wait, in milliseconds - // 'full_state': fullState, // Whether to include full state or not + 'full_state': true, // Whether to include full state or not } - }).catch(console.error); - ; - console.table(res === null || res === void 0 ? void 0 : res.data); + }); + return res; } exports.nomoSyncUser = nomoSyncUser; diff --git a/src/syncing/sync_user.ts b/src/syncing/sync_user.ts index 3943a01..088218d 100644 --- a/src/syncing/sync_user.ts +++ b/src/syncing/sync_user.ts @@ -12,12 +12,11 @@ export async function nomoSyncUser(accessToken: string, since: string, filter: s // If the access_token is required as a query parameter // 'access_token': accessToken, // 'filter': filter, // The sync filter to use - 'since': since, // Pass the 'since' token from the previous sync or initial login + // 'since': since, // Pass the 'since' token from the previous sync or initial login // 'set_presence': setPresence, // Controls the presence state of the client // 'timeout': 1000, // The maximum time to wait, in milliseconds - // 'full_state': fullState, // Whether to include full state or not + 'full_state': true, // Whether to include full state or not } - }).catch(console.error);; - - console.table(res?.data); + }); + return res; } diff --git a/test/syncing/sync_user.test.ts b/test/syncing/sync_user.test.ts index c03e7d2..ecb795c 100644 --- a/test/syncing/sync_user.test.ts +++ b/test/syncing/sync_user.test.ts @@ -1,9 +1,27 @@ -import { nomoRegisterOrLogin, nomoSyncUser, UserMatrix, nomoCreateFilter } from "../../src"; +import { nomoRegisterOrLogin, nomoSyncUser, UserMatrix } from "../../src"; test("sync user", async () => { - const mnemonic = "diet say develop title sibling steel blast table chicken foster fuel giraffe"; - const userMatrix: UserMatrix = await nomoRegisterOrLogin(mnemonic); - // const filterID: string = await nomoCreateFilter(userMatrix.access_token, userMatrix.user_id); - // await nomoSyncUser(userMatrix.access_token, "", '', "online", false); - // expect(userMatrix.user_id).toBe("@0x3f0e8cF0c6eb9789348541D9D0Ce4ac847277e9B:zeniq.chat"); -}, 10000); \ No newline at end of file + const mnemonic = + "diet say develop title sibling steel blast table chicken foster fuel giraffe"; + const userMatrix: UserMatrix = await nomoRegisterOrLogin(mnemonic); + + expect(userMatrix.user_id).toBe( + "@0xa563B68Ba292601968A4fb63861e9d847126E83E:zeniq.chat" + ); + expect(userMatrix.home_server).toBe("zeniq.chat"); + + // const filterID: string = await nomoCreateFilter(userMatrix.access_token, userMatrix.user_id); + const res = await nomoSyncUser( + userMatrix.access_token, + "", + "", + "online", + false + ); + expect(res.status).toBe(200); + + const data = res.data; + console.log("sync data", data); + + expect(data.rooms).toBeDefined(); +}, 10000);