create channel, adding bot to channel, get invite link and leave owner tg channel success
This commit is contained in:
parent
2d1456d40b
commit
f3414541c6
@ -172,6 +172,13 @@ func (tg *TelegramClient) CreateChannel(channelName string, botID int64) (string
|
|||||||
return "", errors.New("no active Telegram clients")
|
return "", errors.New("no active Telegram clients")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err := activeClient.GetUser(&client.GetUserRequest{
|
||||||
|
UserId: botID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.New("not found this bot, make privacy off")
|
||||||
|
}
|
||||||
|
|
||||||
channel, err := activeClient.CreateNewSupergroupChat(&client.CreateNewSupergroupChatRequest{
|
channel, err := activeClient.CreateNewSupergroupChat(&client.CreateNewSupergroupChatRequest{
|
||||||
Title: channelName,
|
Title: channelName,
|
||||||
IsChannel: true,
|
IsChannel: true,
|
||||||
@ -181,21 +188,11 @@ func (tg *TelegramClient) CreateChannel(channelName string, botID int64) (string
|
|||||||
return "", fmt.Errorf("failed to create channel: %s", err.Error())
|
return "", fmt.Errorf("failed to create channel: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
//resp, err := activeClient.AddChatMember(&client.AddChatMemberRequest{
|
|
||||||
// ChatId: channel.Id,
|
|
||||||
// UserId: botID,
|
|
||||||
//})
|
|
||||||
//if err != nil {
|
|
||||||
// return "", fmt.Errorf("failed to add bot to channel: %s", err.Error())
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//fmt.Println("resp", resp)
|
|
||||||
|
|
||||||
_, err = activeClient.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
|
_, err = activeClient.SetChatMemberStatus(&client.SetChatMemberStatusRequest{
|
||||||
ChatId: channel.Id,
|
ChatId: channel.Id,
|
||||||
MemberId: &client.MessageSenderUser{UserId: botID},
|
MemberId: &client.MessageSenderUser{UserId: botID},
|
||||||
Status: &client.ChatMemberStatusAdministrator{
|
Status: &client.ChatMemberStatusAdministrator{
|
||||||
CanBeEdited: true,
|
CustomTitle: "bot",
|
||||||
Rights: &client.ChatAdministratorRights{
|
Rights: &client.ChatAdministratorRights{
|
||||||
CanManageChat: true,
|
CanManageChat: true,
|
||||||
CanChangeInfo: true,
|
CanChangeInfo: true,
|
||||||
@ -210,15 +207,6 @@ func (tg *TelegramClient) CreateChannel(channelName string, botID int64) (string
|
|||||||
return "", fmt.Errorf("failed to make bot admin: %s", err.Error())
|
return "", fmt.Errorf("failed to make bot admin: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
//_, err = activeClient.LeaveChat(&client.LeaveChatRequest{
|
|
||||||
// ChatId: channel.Id,
|
|
||||||
//})
|
|
||||||
//if err != nil {
|
|
||||||
// return "", fmt.Errorf("failed to leave the channel: %s", err.Error())
|
|
||||||
//}
|
|
||||||
|
|
||||||
fmt.Println("channel.Id", channel.Id)
|
|
||||||
|
|
||||||
inviteLink, err := activeClient.CreateChatInviteLink(&client.CreateChatInviteLinkRequest{
|
inviteLink, err := activeClient.CreateChatInviteLink(&client.CreateChatInviteLinkRequest{
|
||||||
ChatId: channel.Id,
|
ChatId: channel.Id,
|
||||||
Name: channelName,
|
Name: channelName,
|
||||||
@ -230,5 +218,12 @@ func (tg *TelegramClient) CreateChannel(channelName string, botID int64) (string
|
|||||||
return "", fmt.Errorf("failed to get invite link: %s", err.Error())
|
return "", fmt.Errorf("failed to get invite link: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = activeClient.LeaveChat(&client.LeaveChatRequest{
|
||||||
|
ChatId: channel.Id,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to leave the channel: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
return inviteLink.InviteLink, nil
|
return inviteLink.InviteLink, nil
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ func (s *Service) DeleteTgAccountByID(ctx *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//func (s *Service) TEST(ctx *fiber.Ctx) error {
|
//func (s *Service) TEST(ctx *fiber.Ctx) error {
|
||||||
// botID := 542073142
|
// botID := 6712573453
|
||||||
// chanalName := "testAAAAAA"
|
// chanalName := "testAAAAAA"
|
||||||
// link, err := s.telegramClient.CreateChannel(chanalName, int64(botID))
|
// link, err := s.telegramClient.CreateChannel(chanalName, int64(botID))
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user