Telegram bot weird error : Bad Request: wrong file identifier/HTTP URL specified

后端 未结 6 1573
刺人心
刺人心 2021-01-07 22:25

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.

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-07 23:16

    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):

    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 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.

提交回复
热议问题