Node-telegram-bot-api: Sending documents by HTTP URL returns 400 Bad Request (Part Two)

Created on 28 Apr 2017  路  9Comments  路  Source: yagop/node-telegram-bot-api

Expected Behavior

I'm trying to send GIFs by HTTP URL using the .sendDocument method.

Actual Behavior

Unhandled rejection Error: ETELEGRAM: 400 Bad Request: there is no document in the request
    at BaseError (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\node-telegram-bot-api\src\errors.js:10:5)
    at TelegramError (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\node-telegram-bot-api\src\errors.js:56:5)
    at request.then.err (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\node-telegram-bot-api\src\telegram.js:181:15)
    at tryCatcher (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromise0 (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\promise.js:693:18)
    at Async._drainQueue (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\async.js:133:16)
    at Async._drainQueues (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:666:20)
    at tryOnImmediate (timers.js:639:5)
    at processImmediate [as _immediateCallback] (timers.js:611:5)

Unhandled rejection Error: ETELEGRAM: 400 Bad Request: wrong file identifier/HTTP URL specified
    at BaseError (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\node-telegram-bot-api\src\errors.js:10:5)
    at TelegramError (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\node-telegram-bot-api\src\errors.js:56:5)
    at request.then.err (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\node-telegram-bot-api\src\telegram.js:181:15)
    at tryCatcher (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromise0 (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\promise.js:693:18)
    at Async._drainQueue (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\async.js:133:16)
    at Async._drainQueues (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues (C:\Users\Pichau\Documents\GitHub\thegifmachine\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:666:20)
    at tryOnImmediate (timers.js:639:5)
    at processImmediate [as _immediateCallback] (timers.js:611:5)

Steps to reproduce the Behavior

Add this code to your bot:

bot.onText(/\/link (.+)/, (msg, match) => {
  const chatId = msg.chat.id;
  const resp = match[1];
  bot.sendDocument(chatId, resp);
});

And then send these commands to it:

/link https://giant.gfycat.com/GoldenEquatorialAfricanjacana.gif
/link https://zippy.gfycat.com/GoldenEquatorialAfricanjacana.webm
/link http://i.imgur.com/OKRRfmN.mp4

Basically any .gif, .mp4 or .webm that I've tried didn't work.

investigate tg-side-issue

Most helpful comment

As documentation stands https://core.telegram.org/bots/api#sending-files

Sending by URL
In sendDocument, sending by URL will currently only work for gif, pdf and zip files.
Other configurations may work but we can't guarantee that they will.

All 9 comments

I am getting a different error:

ETELEGRAM: 400 Bad Request: failed to get HTTP URL content

PS: http://i.imgur.com/OKRRfmN.mp4 seems okay...

That's surely strange.

I too experience this... works perfoectly with getUpdates() on localhost, however throws on heroku

Mind sharing the URLs that are failing?

I will create a separate issue, I have a bit different problem

Created a separate issue describing my problem https://github.com/yagop/node-telegram-bot-api/issues/375

Unhandled rejection Error: 400 {"ok":false,"error_code":400,"description":"Bad Request: wrong file identifier/HTTP URL specified"}
// response ok
bot.onText(/\/food1/, function (msg) {
bot.sendPhoto(msg.chat.id, "https://lh3.googleusercontent.com/hjqm0yBkqDVEqNlGnTLr_ty3r50C7q6SqX3hVwuZsWS6yU-2AXEpq12ryXSvNvc07uaFgrjgKlRoWyvydvr0NDixXvy75P3-lWEIq4FRVCzd-jptak8Mwhkn6KCk6DrONQS__ardCrc7hSXJW9QOL8o-ImSjICvpSHTxqVJPj__R1xoOhSSSuJtHjrRNY404-eHrno2O5SdaNmiwwPwC8QidaNPRKnXInXDzGj540kt9xGxWqXdB_sBuQFDg9lYUt61n3S5OCe9GehRInwmXaPPQm9efVOb9UW72qLzpIUw-wWtF0ragjC6Y_TUKVU0g3zrQ4_fjqu9E8UxMQH38L1_Y3B6ZqdNFy4E_t19WVmRfP3cAlmbxtDDkIY2e3ydv5HpbMSAhilquaTD63pkd5BE5ZpKgm-QsEzUdWdKdoYLo1OB8arpTqJeh8UfmvZKMFUalkHVmYjiyeRI5ynWhdLh_k2dGXcoMXALuUFO0pJlPdz_7E-TCzFXZrL-u_1vKbZv-YXWfJZrHqn1p85A3MWocDvY8ZmTx8Dcy5HGCTa_Jid2Gj9dYKUr7opGq-Q=s1916-w1916-h1436-no",
{caption : "Beef"} );
});

// failed
bot.onText(/\/food2/, function (msg) {
bot.sendPhoto(msg.chat.id, "https://lh3.googleusercontent.com/hV30wubtbC07_JJpyWaVxSdFo59gWb6MZxcoWd-v2oM_XPubK5Xv9u0Zpt6fDj8RIUUGLMVSSKnIILBwusgHarhs7iTFglggogaS0e1PVrcapA_1jStVNZH8LgwtsA9shvJGdjPcj4pz4ODvpKlFwaEdz8u9sAuQyUEZmD96iTSnvyj0LDmsQMQy9kf2Y0pwu8ZHUTadJ8RigiTOYIGpwapu6qWoU5pBVgSxdqiuXUoo-vqP9YHFzPo4qAxB4GWbsrfDLxe-l1F4clCGhJeNp30S_SQStKkPR1efdgGRi92oNLwnR7dF8VUjwYmRbqro3szeY_zPhEu3dZjzTjyq9uf62T2W0PrIwSB8-RmLgdyYBf674gSIyCZd6eeE2-tHLKc20NXV-HMTy7kf6L_5dy9tunxCVZa0Z13a5MRyLfQEaFqDhjb8M7DGaEfe0PI1hhv3HNWDs1BlcvIgdBV-t5sLRXFH6sujRhAs7iC6R8cwW3STL-UIL-5WQZOvmttZaAKWMreFqAQ9Up2m-3TeK3EcgNrn1wg-FhyWfEOGa2REetJ5hZU776QO_TuxLd7vrcFZ1a_y5C5eYyUBi--184RmqdEeXx39qcfYMmuj3w=w1916-h1436-no",
{caption : "Porlk"} );
});

I had exactly same problem and couldn't upload an image (as sticker), http://.../blabla.webp. Not via telegram app, not via telegram bot API. To solve the issue I went to @webpagebot and sent him a link to my file. Seems that the telegram's cache was invalidated, and this worked.

As documentation stands https://core.telegram.org/bots/api#sending-files

Sending by URL
In sendDocument, sending by URL will currently only work for gif, pdf and zip files.
Other configurations may work but we can't guarantee that they will.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qunatumwhiskey picture qunatumwhiskey  路  4Comments

sidelux picture sidelux  路  3Comments

dimawebmaker picture dimawebmaker  路  3Comments

Kasra-S picture Kasra-S  路  3Comments

lenny76 picture lenny76  路  3Comments