user6190022
user6190022

Reputation:

Receive photos with Telegram - API

Is there a way to receive and save photos with the NuGet Telegram.Bot in C#?

Also, how can I get the message type, i tried

if (message.Type == MessageType.PhotoMessage)

but it didn't worked.

Upvotes: 2

Views: 3472

Answers (1)

Andréw
Andréw

Reputation: 106

This is just the check for the type. After this check you can get different photosizes from the Photo-Object.

_telegramClient = new TelegramBotClient(ConfigurationManager.AppSettings["TelegramApiKey"]);
_telegramClient.OnMessage += BotOnMessageReceived;
_telegramClient.StartReceiving();

var test = await _telegramClient.GetFileAsync(message.Photo[message.Photo.Count() - 1].FileId);

var image = Bitmap.FromStream(test.FileStream);

image.Save(@"C:\\Users\xxx\Desktop\test.png");

// message.Photo.Count()-1 => the biggest resolution

Upvotes: 2

Related Questions