使用 Telegram - API 接收照片 [英] Receive photos with Telegram - API

查看:223
本文介绍了使用 Telegram - API 接收照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 C# 中使用 NuGet Telegram.Bot 接收和保存照片?

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)

但是没有用.

推荐答案

这只是对类型的检查.完成此检查后,您可以从照片对象中获得不同的照片尺寸.

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

这篇关于使用 Telegram - API 接收照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆