|
|
@@ -412,12 +412,18 @@ export class TaskExecutor {
|
|
|
}
|
|
|
const chatId = groupEntity.chatId ?? groupEntity.id
|
|
|
const accessHash = groupEntity.accessHash
|
|
|
- if (chatId === undefined || chatId === null || accessHash === undefined || accessHash === null) {
|
|
|
- throw new Error('群拉人任务:群组实体缺少 id/chatId/accessHash(请检查 resolveGroupEntityByInviteLink 返回值)')
|
|
|
+ if (chatId === undefined || chatId === null) {
|
|
|
+ throw new Error('群拉人任务:群组实体缺少 id/chatId(请检查 resolveGroupEntityByInviteLink 返回值)')
|
|
|
}
|
|
|
|
|
|
- const inputChannel = await workerTgClient.getInputChannel(chatId, accessHash)
|
|
|
- await workerTgClient.inviteMembersToChannelGroup(inputChannel, [targetUser])
|
|
|
+ // 超级群/频道:有 accessHash,走 channels.InviteToChannel
|
|
|
+ if (accessHash !== undefined && accessHash !== null) {
|
|
|
+ const inputChannel = await workerTgClient.getInputChannel(chatId, accessHash)
|
|
|
+ await workerTgClient.inviteMembersToChannelGroup(inputChannel, [targetUser])
|
|
|
+ } else {
|
|
|
+ // 普通群(Chat):没有 accessHash,走 messages.AddChatUser
|
|
|
+ await workerTgClient.inviteUserToBasicChat(chatId, targetUser)
|
|
|
+ }
|
|
|
|
|
|
await this.taskItemRepo.update(item.id, {
|
|
|
status: TaskItemStatus.SUCCESS,
|
|
|
@@ -474,10 +480,14 @@ export class TaskExecutor {
|
|
|
if (!inviteGroupEntity) return
|
|
|
const chatId = inviteGroupEntity.chatId ?? inviteGroupEntity.id
|
|
|
const accessHash = inviteGroupEntity.accessHash
|
|
|
- if (chatId === undefined || chatId === null || accessHash === undefined || accessHash === null) return
|
|
|
try {
|
|
|
- const inputChannel = await workerTgClient.getInputChannel(chatId, accessHash)
|
|
|
- await workerTgClient.leaveGroup(inputChannel)
|
|
|
+ if (chatId === undefined || chatId === null) return
|
|
|
+ if (accessHash !== undefined && accessHash !== null) {
|
|
|
+ const inputChannel = await workerTgClient.getInputChannel(chatId, accessHash)
|
|
|
+ await workerTgClient.leaveGroup(inputChannel)
|
|
|
+ } else {
|
|
|
+ await workerTgClient.leaveBasicChat(chatId)
|
|
|
+ }
|
|
|
} catch {
|
|
|
// 忽略退群异常(可能已不在群、权限问题等)
|
|
|
}
|