Skip to content

Commit 0c78ee3

Browse files
feat: bump backend package, handle websocket events correctly
1 parent 1758b50 commit 0c78ee3

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@grammyjs/menu": "^1.3.1",
3838
"@grammyjs/parse-mode": "^1.11.1",
3939
"@grammyjs/runner": "^2.0.3",
40-
"@polinetwork/backend": "^0.13.1",
40+
"@polinetwork/backend": "^0.15.2",
4141
"@t3-oss/env-core": "^0.13.4",
4242
"@trpc/client": "^11.5.1",
4343
"@types/ssdeep.js": "^0.0.2",

pnpm-lock.yaml

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/websocket.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ export class WebSocketClient extends Module<ModuleShared> {
3737

3838
constructor() {
3939
super()
40-
this.io = io(`http://${env.BACKEND_URL}`, { path: WS_PATH, query: { type: "telegram" } })
41-
}
42-
override async start() {
40+
this.io = io(`http://${env.BACKEND_URL}`, { path: WS_PATH, query: { type: "telegram" }, autoConnect: false })
4341
this.io.on("connect", () => {
4442
logger.info("[WS] connected")
4543
this.lastErrorCode = null
@@ -60,6 +58,10 @@ export class WebSocketClient extends Module<ModuleShared> {
6058
logger.error({ error }, "[WS] UNKNOWN error while connecting")
6159
})
6260

61+
this.io.on("disconnect", (reason, details) => {
62+
logger.info({ reason, details }, "[WS] disconnected")
63+
})
64+
6365
this.io.on("ban", async ({ chatId, userId, durationInSeconds }, cb) => {
6466
const error = await this.shared.api
6567
.banChatMember(chatId, userId, {
@@ -78,9 +80,12 @@ export class WebSocketClient extends Module<ModuleShared> {
7880
})
7981
}
8082

83+
override async start() {
84+
this.io.connect()
85+
}
86+
8187
override async stop() {
82-
this.io.close()
83-
logger.info("[WS] disconnected")
88+
this.io.disconnect()
8489
}
8590

8691
static isSocketError(e: Error): e is SocketError {

0 commit comments

Comments
 (0)