Compare commits

..

5 Commits

Author SHA1 Message Date
dac037809c loggign 2025-07-02 06:42:22 -04:00
6088a2cbd3 add keepalive ping, onclose event reason 2025-07-02 06:41:43 -04:00
ed8d148d0a update README 2025-07-01 17:18:53 -04:00
379099dc7a remove unused code, add try/catch block 2025-07-01 15:30:33 -04:00
c0ed38ac1a update README 2025-07-01 15:26:38 -04:00
2 changed files with 31 additions and 49 deletions

View File

@ -1,15 +1,15 @@
## Pleroma -> Ollama Bot Setup
1. Clone project
2. Install npm 22.11.0 if you don't have it already
2. Install Node `v22.11.0` if you don't have it already
* If using `nvm`, just `nvm install 22.11.0` and then `nvm use 22.11.0` if necessary
3. `cd` into the project directory
4. Run `npm install`
6. Run `npx prisma migrate dev --name init`
7. To run the software on a cronjob, use `npm run once`
8. To run continuously, use `npm run ws`
7. To start, run `npm run start`
I recommend using `screen` to run this in the background until a `systemd` service can be created. I just haven't bothered to do it yet.
### Database Migrations
If you add stuff to the schema, follow the [Prisma development workflow](https://www.prisma.io/docs/orm/prisma-migrate/workflows/development-and-production). This will apply the new schema to the database and generate a new Prisma client with type safety.
Setting as a system service will come at some point, or someone could contribute if they wanted.

View File

@ -11,28 +11,6 @@ import { createWebsocket } from "./websocket.js";
const prisma = new PrismaClient();
// const getNotifications = async () => {
// try {
// const request = await fetch(
// `${process.env.PLEROMA_INSTANCE_URL}/api/v1/notifications?types[]=mention`,
// {
// method: "GET",
// headers: {
// Authorization: `Bearer ${process.env.INSTANCE_BEARER_TOKEN}`,
// },
// }
// );
// const notifications: Notification[] = await request.json();
// return notifications;
// } catch (error: any) {
// throw new Error(error.message);
// }
// };
// const notifications = await getNotifications();
const storeUserData = async (notification: Notification): Promise<void> => {
try {
await prisma.user.upsert({
@ -181,27 +159,31 @@ ws.on("upgrade", () => {
);
});
ws.on("message", async (data) => {
const message: WSEvent = JSON.parse(data.toString("utf-8"));
if (message.event !== "notification") {
// only watch for notification events
return;
}
console.log("Websocket message received.");
const payload = JSON.parse(message.payload) as Notification;
const ollamaResponse = await generateOllamaRequest(payload);
if (ollamaResponse) {
await postReplyToStatus(payload, ollamaResponse);
}
ws.on("close", (event: CloseEvent) => {
console.log(`Connection closed: ${event.reason}`);
});
// if (notifications) {
// await Promise.all(
// notifications.map(async (notification) => {
// const ollamaResponse = await generateOllamaRequest(notification);
// if (ollamaResponse) {
// postReplyToStatus(notification, ollamaResponse);
// }
// })
// );
// }
ws.on("open", () => {
setInterval(() => {
ws.send(JSON.stringify({ type: "ping" }));
console.log("Sending ping to keep session alive...");
}, 20000);
});
ws.on("message", async (data) => {
try {
const message: WSEvent = JSON.parse(data.toString("utf-8"));
if (message.event !== "notification") {
// only watch for notification events
return;
}
console.log("Websocket message received.");
const payload = JSON.parse(message.payload) as Notification;
const ollamaResponse = await generateOllamaRequest(payload);
if (ollamaResponse) {
await postReplyToStatus(payload, ollamaResponse);
}
} catch (error: any) {
console.error(error.message);
}
});