I am sending message to telegram channel using bot.
With using webhook method.
I\'m sending file_id via the link. I got the file_id from a channel post.
your mime type video is incorrect change it
There are many possible reasons for this as mentioned in the documentation:
If you forward a file (photo, audio, ...) to a bot, you will get a valid file_id
for this file (for your bot). It should be safe to use this id to send then file, but it seems it dosen't work for some files (audio, video, ...)!! (May be a Telegram API bug).
You can download and reupload the file to your bot, to get a new file_id
and this id will work.
if your url not seen from telegram server or your url is incorrect this error has been seen.
also you can send data to this url with multipart html post method(please fill {YourBotToken} and {your_channel_name_with_Atsign} value):
<form action="https://api.telegram.org/bot{YourBotToken}/sendVideo" method="POST" enctype="application/x-www-form-urlencoded">
<input type="file" name="video" />
<input type="hidden" name="chat_id" value="{your_channel_name_with_Atsign}" />
<button type="submit" >send</button>
</form>
in c# sample code is:
public bool sendVideo(string filename,string sendTo)
{
try
{
var botToken="{YourBotToken}";
var sendTo="{your_channel_name_with_Atsign}";
var filePath = "C:\\sample\\" + filename;
var sendTo, ="@YourChannelNameWithAtSign";
var bytesOfFile = System.IO.File.ReadAllBytes(filePath);
var url = $"https://api.telegram.org/bot{botToken}/sendVideo";
var res =Upload(url, sendTo, "video", bytesOfFile, filename).Result;
}
catch (Exception ex)
{
return false;
}
return true;
}
private static async Task<string> Upload(string actionUrl,string chat_id,string fileParamName, byte[] paramFileStream, string filename)
{
var formContent = new MultipartFormDataContent
{
{new StringContent(chat_id),"chat_id"},
{new StreamContent(new MemoryStream(paramFileStream)),fileParamName,filename}
};
var myHttpClient = new HttpClient();
var response = await myHttpClient.PostAsync(actionUrl.ToString(), formContent);
string stringContent = await response.Content.ReadAsStringAsync();
return stringContent;
}
this way does not need to have a website and you can use that from your stand alone system.
Your Awnser is here @farzad
Sending by file_id
file_id is unique for each individual bot and can't be transferred from one bot to another.
Go to @webpagebot and send him an URL to the file. The telegram's cache will be invalidated, and this should work. Seems that it is a bug on the server.
In my case I couldn't upload an image (as sticker), http://.../blabla.webp
not via telegram app, not via telegram bot API.