I want to create a robot in Telegram. After searching, I found telegram.bot in the Nuget package.
But I have problems sending photos. Function definition is similar to
Bot.SendPhoto(int channelId, string photo, string caption)
But I do not know what is expected in the parameter string photo. Should I convert my image to base64 string or pass image path or ...?
Currently my code is as follows
var Bot = new Telegram.Bot.Api("API KEY");
var b = new System.Net.WebClient().DownloadData(a.DefaultImage());
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(new System.IO.MemoryStream(b));
var z = bmp.GetThumbnailImage(200, (200 * bmp.Height) / bmp.Width,
new System.Drawing.Image.GetThumbnailImageAbort(
delegate { return true; }), IntPtr.Zero);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
z.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
var x = new Telegram.Bot.Types.FileToSend()
{
Filename = a.DefaultImage().Split('/').LastOrDefault(), Content = ms
};
var t = Bot.SendPhoto("@Chanel", x, a.Title);
But this throws an exception
Telegram.Bot.Types.ApiRequestException: [Error]: Invalid request: send file must be non-empty
source
share