Skip to content

Commit

Permalink
fixed js compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
dev2-nomo committed Dec 14, 2023
1 parent 98ac498 commit 347d767
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ The Nomo Assistant Listener is a AI model which answeres to your questions in a

```
npm install
node src/ai_chat/listen_on_messages.ts
node dist/ai_chat/listen_on_messages.js
```
67 changes: 67 additions & 0 deletions dist/ai_chat/listen_on_messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nomoAssistantListenOnMessages = void 0;
const sdk = require("matrix-js-sdk");
const index = require('../index');
const ai = require('../ai_chat/send_message_to_ai');
const nomoRegisterOrLogin = require('../register_login/register_login');
const mnemonic = 'used ensure guitar garlic wasp obscure general cute behind laundry remove jungle';
// @0xd5ed6fec4426378cfb17455b1b9c3f6db53f657a:zeniq.chat
async function nomoAssistantListenOnMessages() {
// const index = await import('../index');
// const ai = await import('../ai_chat/send_message_to_ai');
// const nomoRegisterOrLogin = await import('../register_login/register_login');
const userMatrix = await nomoRegisterOrLogin.nomoRegisterOrLogin(mnemonic);
const client = sdk.createClient({
baseUrl: index.server,
accessToken: userMatrix.access_token,
userId: userMatrix.user_id,
deviceId: userMatrix.device_id,
});
// await client.initCrypto();
await client.startClient({
initialSyncLimit: 10
});
client.on("Room.timeline", async function (event, room, toStartOfTimeline) {
if (toStartOfTimeline) {
return; // don't print paginated results
}
if (event.getType() === "m.room.encrypted") {
const clearEvent = await client.decryptEventIfNeeded(event);
if (clearEvent) {
console.log("(%s) %s :: %s", room.name, clearEvent.getSender(), clearEvent.getContent().body);
}
}
if (event.getType() === "m.room.message") {
const body = event.getContent().body;
console.log("%s: %s", event.getSender(), body);
const response = await ai.nomoSendMessageToAi(body);
if (response['choices'] && response['choices'].length > 0) {
const message = response['choices'][0].message;
if (message && message.content) {
const body = JSON.stringify(message.content);
const data = {
"msgtype": "m.text",
"body": body
};
client.sendMessage(room.roomId, data);
}
else {
console.log("No content in the message");
}
}
else {
console.log("No choices in the response");
}
}
});
client.on("RoomMember.membership", function (event, member) {
if (member.membership === "invite" && member.userId === userMatrix.user_id) {
client.joinRoom(member.roomId).then(function () {
console.log("Auto-joined %s", member.roomId);
});
}
});
}
exports.nomoAssistantListenOnMessages = nomoAssistantListenOnMessages;
nomoAssistantListenOnMessages().catch(console.error);
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nomoChatWithAi = exports.nomoCreateFilter = exports.nomoSyncUser = exports.nomoSendMessage = exports.nomoJoinRoom = exports.nomoListenRoom = exports.nomoRegister = exports.nomoLogin = exports.nomoRegisterOrLogin = exports.server = void 0;
exports.nomoAssistantListenOnMessages = exports.nomoChatWithAi = exports.nomoCreateFilter = exports.nomoSyncUser = exports.nomoSendMessage = exports.nomoJoinRoom = exports.nomoListenRoom = exports.nomoRegister = exports.nomoLogin = exports.nomoRegisterOrLogin = exports.server = void 0;
// here are the publicly exported functions
const server = 'https://zeniq.chat/';
exports.server = server;
Expand All @@ -20,3 +20,5 @@ var create_filter_1 = require("./syncing/create_filter");
Object.defineProperty(exports, "nomoCreateFilter", { enumerable: true, get: function () { return create_filter_1.nomoCreateFilter; } });
var ai_chat_1 = require("./ai_chat/ai_chat");
Object.defineProperty(exports, "nomoChatWithAi", { enumerable: true, get: function () { return ai_chat_1.nomoChatWithAi; } });
var listen_on_messages_1 = require("./ai_chat/listen_on_messages");
Object.defineProperty(exports, "nomoAssistantListenOnMessages", { enumerable: true, get: function () { return listen_on_messages_1.nomoAssistantListenOnMessages; } });
15 changes: 8 additions & 7 deletions src/ai_chat/listen_on_messages.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const sdk = require("matrix-js-sdk");
const index = require('../index');
const ai = require('../ai_chat/send_message_to_ai');
const nomoRegisterOrLogin = require('../register_login/register_login');


const mnemonic = 'used ensure guitar garlic wasp obscure general cute behind laundry remove jungle';
// @0xd5ed6fec4426378cfb17455b1b9c3f6db53f657a:zeniq.chat
async function main() {
const index = await import('../../dist/index.js');
const ai = await import('../../dist/ai_chat/send_message_to_ai.js');
const nomoRegisterOrLogin = await import('../../dist/register_login/register_login.js');
export async function nomoAssistantListenOnMessages() {
const userMatrix = await nomoRegisterOrLogin.nomoRegisterOrLogin(mnemonic);

const client = sdk.createClient({
Expand All @@ -21,7 +22,7 @@ async function main() {
initialSyncLimit: 10
});

client.on("Room.timeline", async function (event, room, toStartOfTimeline) {
client.on("Room.timeline", async function (event: any, room: any, toStartOfTimeline: any) {
if (toStartOfTimeline) {
return; // don't print paginated results
}
Expand Down Expand Up @@ -58,7 +59,7 @@ async function main() {
}
});

client.on("RoomMember.membership", function (event, member) {
client.on("RoomMember.membership", function (event: any, member: any) {
if (member.membership === "invite" && member.userId === userMatrix.user_id) {
client.joinRoom(member.roomId).then(function () {
console.log("Auto-joined %s", member.roomId);
Expand All @@ -67,4 +68,4 @@ async function main() {
});
}

main().catch(console.error);;
nomoAssistantListenOnMessages().catch(console.error);
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export { nomoJoinRoom } from "./join_room/join_room"
export { nomoSendMessage, SendMessageArgs } from "./send_message/send_message"
export { nomoSyncUser } from "./syncing/sync_user"
export { nomoCreateFilter } from "./syncing/create_filter"
export { nomoChatWithAi } from "./ai_chat/ai_chat"
export { nomoChatWithAi } from "./ai_chat/ai_chat"
export { nomoAssistantListenOnMessages } from "./ai_chat/listen_on_messages"

0 comments on commit 347d767

Please sign in to comment.