Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

For some files like GIF & video format (MP4),

when i use this code:

$url = 'https://api.telegram.org/bot'.token.'/sendVideo?chat_id='.uid."&video=".$file."&caption="
.urlencode($caption);

file_get_contents($url);

i get such this error :

{"ok":false,"error_code":400,"description":"Bad Request: wrong file identifier/HTTP URL specified"}

I really don't know why i get this, It's like this is random for errors, Because the code is depended to nothing i guess.

I use file_id that i've got from a channel's post.

What is the reason of that error? Bad Request: wrong file identifier/HTTP URL specified

  • I've searched all related topics, I've found NO good information .
like image 265
Farzad Avatar asked Mar 09 '17 14:03

Farzad


People also ask

Why is my bot on Telegram not working?

Suggestions: Ensure the Bot is in the group and as an admin. Try adding a new access token (revoke existing API key and create a new one then replace in plugin settings) If you edited the bot with @BotFather, make sure to restore it to the default settings.

What is the URL for Telegram API?

The first part of the URL indicates that you want to communicate with the Telegram API ( api.telegram.org ).


4 Answers

There are many possible reasons for this as mentioned in the documentation:

  • It is not possible to change the file type when resending by file_id. i.e. a video can't be sent as a photo, a photo can't be sent as a document, etc.
  • It is not possible to resend thumbnails.
  • Resending a photo by file_id will send all of its sizes.
  • file_id is unique for each individual bot and can't be transferred from one bot to another.
like image 117
ManzoorWani Avatar answered Oct 16 '22 16:10

ManzoorWani


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.

like image 24
Saeed Heidarizarei Avatar answered Oct 16 '22 14:10

Saeed Heidarizarei


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.

like image 9
xamgore Avatar answered Oct 16 '22 14:10

xamgore


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.

like image 3
Ali Rasouli Avatar answered Oct 16 '22 14:10

Ali Rasouli