wuyi 4 недель назад
Родитель
Сommit
8fd6b6bba6

+ 9 - 1
src/controllers/tg-group.controller.ts

@@ -1,6 +1,6 @@
 import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'
 import { TgGroupService } from '../services/tg-group.service'
-import { CreateTgGroupBody } from '../dto/tg-group.dto'
+import { CreateTgGroupBody, InviteMembersBody } from '../dto/tg-group.dto'
 
 export class TgGroupController {
   private readonly tgGroupService: TgGroupService
@@ -49,4 +49,12 @@ export class TgGroupController {
       })
     }
   }
+
+  async inviteMembers(request: FastifyRequest<{ Body: InviteMembersBody }>, reply: FastifyReply) {
+    const { senderId, chatId, accessHash, members } = request.body
+
+    const result = await this.tgGroupService.inviteMembers(senderId, chatId, accessHash, members)
+
+    return reply.code(result.success ? 200 : 500).send(result)
+  }
 }

+ 7 - 0
src/dto/tg-group.dto.ts

@@ -5,3 +5,10 @@ export interface CreateTgGroupBody {
   initMsg?: string
   senderId?: string
 }
+
+export interface InviteMembersBody {
+  senderId?: string
+  chatId?: string
+  accessHash?: string
+  members?: string[]
+}

+ 2 - 0
src/services/tg-group.service.ts

@@ -131,4 +131,6 @@ export class TgGroupService {
       }
     }
   }
+
+  async inviteMembers(senderId?: string, chatId?: string, accessHash?: string, members?: string[]): Promise<any> {}
 }

+ 21 - 0
src/services/tgClient.service.ts

@@ -214,6 +214,27 @@ export class TgClientService {
     }
   }
 
+  async inviteMembersToChannelGroup(
+    client: TelegramClient,
+    inputChannel: Api.InputChannel,
+    inputUsers: Api.InputUser[]
+  ): Promise<void> {
+    this.app.log.info('正在邀请成员到群组...')
+
+    try {
+      await client.invoke(
+        new Api.channels.InviteToChannel({
+          channel: inputChannel,
+          users: inputUsers
+        })
+      )
+      this.app.log.info('已邀请成员到群组')
+    } catch (error) {
+      const errorMessage = this.extractErrorMessage(error)
+      throw new Error(`邀请成员到群组失败: ${errorMessage}`)
+    }
+  }
+
   async getInviteLink(client: TelegramClient, inputChannel: Api.InputChannel): Promise<string | null> {
     try {
       const inviteLink = await client.invoke(new Api.messages.ExportChatInvite({ peer: inputChannel }))