Skip to content

Commit 01104cf

Browse files
committed
feat: add create channel function
1 parent 41be314 commit 01104cf

5 files changed

Lines changed: 571 additions & 2 deletions

File tree

TelegramDownloader/Data/ITelegramService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public interface ITelegramService
3838
Task<Message> uploadFile(string chatId, Stream file, string fileName, string mimeType = null, UploadModel um = null, string caption = null);
3939
Task<List<TelegramChatDocuments>> searchAllChannelFiles(long id, int lastId);
4040
bool isMyChat(long id);
41-
41+
Task<TL.Channel?> CreateChannel(string title, string about);
4242
}
4343
}

TelegramDownloader/Data/TelegramService.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,5 +1104,46 @@ public async Task<List<TelegramChatDocuments>> searchAllChannelFiles(long id, in
11041104

11051105
// return telegramChatDocuments;
11061106
//}
1107+
1108+
public async Task<TL.Channel?> CreateChannel(string title, string about)
1109+
{
1110+
try
1111+
{
1112+
_logger.LogInformation("Creating channel with title: {Title}", title);
1113+
1114+
// Create a new channel (broadcast = true for channel, false for megagroup/supergroup)
1115+
var updates = await client.Channels_CreateChannel(
1116+
title: title,
1117+
about: about,
1118+
broadcast: true, // true = channel, false = megagroup
1119+
megagroup: false,
1120+
for_import: false
1121+
);
1122+
1123+
// Extract the created channel from the updates
1124+
if (updates is Updates updatesObj)
1125+
{
1126+
var channel = updatesObj.chats.Values.OfType<TL.Channel>().FirstOrDefault();
1127+
if (channel != null)
1128+
{
1129+
_logger.LogInformation("Channel created successfully: {ChannelId} - {Title}", channel.ID, channel.Title);
1130+
1131+
// Refresh the chat list to include the new channel
1132+
chats = null;
1133+
await getAllChats();
1134+
1135+
return channel;
1136+
}
1137+
}
1138+
1139+
_logger.LogWarning("Channel creation returned unexpected result type");
1140+
return null;
1141+
}
1142+
catch (Exception ex)
1143+
{
1144+
_logger.LogError(ex, "Error creating channel: {Title}", title);
1145+
throw;
1146+
}
1147+
}
11071148
}
11081149
}

0 commit comments

Comments
 (0)