question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when sending document (sendDocument)

See original GitHub issue

Hello, I’m currently facing an issue when I want to send a document. I tried 3 technics sending a local file, and a hosted file, neither document is sent.

Link to the Telegraf documentation

Sending local file (relativePath - asbolutePath)

bot.on('text', (ctx) => {
  const localFile = '../../public/assets/test.txt'
  return bot.telegram.sendDocument(process.env.CHAT_ID, request(localFile), [{disable_notification: true}]);
})

Sending hosted local file

With a simple server made by expressjs.

bot.on('text', (ctx) => {
  const localFile = 'http://localhost:3000/assets/test.txt'
  return bot.telegram.sendDocument(process.env.CHAT_ID, request(localFile), [{disable_notification: true}]);
})

Sending random remote file

bot.on('text', (ctx) => {
  const remoteFile = 'http://www.lehtml.com/download/js_doc.pdf'
  return bot.telegram.sendDocument(process.env.CHAT_ID, request(remoteFile), [{disable_notification: true}]);
})

I’m still getting this error

[nodemon] starting `node server.js`
App running on port 3000!

  Error: 400: Bad Request: wrong URL host
      at buildConfig.then.then.then.then (/path/to/project/node_modules/telegraf/core/network/client.js:232:17)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

Failed to process updates. { Error: 400: Bad Request: wrong URL host
    at buildConfig.then.then.then.then (/path/to/project/node_modules/telegraf/core/network/client.js:232:17)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
  code: 400,
  response:
   { ok: false,
     error_code: 400,
     description: 'Bad Request: wrong URL host' },
  description: 'Bad Request: wrong URL host',
  parameters: {},
  on:
   { method: 'sendDocument',
     payload: { '0': [Object], chat_id: '-112511335', document: [Object] } } }

Does anyone has an idea of what I’m doing wrong ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Ugarzcommented, Feb 4, 2018

Okay I finally managed to use it 😃 In fact I did not needed to use request at all. You were right ! So the final code is :

bot.on('text', (ctx) => {
  if(ctx.message && ctx.message.text === 'doc'){
    const remoteFile = 'http://www.lehtml.com/download/js_doc.pdf'
    return bot.telegram.sendDocument(process.env.CHAT_ID, remoteFile, [{disable_notification: true}]);
  }
  return;
})

If the text sent is doc, then send the document. Thank you @sergeysova for your help !

0reactions
sergeysovacommented, Feb 4, 2018

Please, show terminal output of

bot.on('text', (ctx) => {
  const remoteFile = 'http://www.lehtml.com/download/js_doc.pdf'

  return bot.telegram.sendDocument(process.env.CHAT_ID, remoteFile, [{ disable_notification: true }]);
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Common sending issues - DocuSign Support
Read this article if you are racing common sending issues like uploading/sending documents, errors like, "Page Cannot Be Displayed," email ...
Read more >
Error when using document data for IPP send Document ...
Hello @hungnq39 the print payload is binary data of the remaining HTTP payload that immediately follows the document attributes. Please see ...
Read more >
400 error when I send Document url toTelegram bot with api
my api code is: $url = 'https://api.telegram.org/bot'.$bot_id.'/sendDocument?chat_id='.$chat_id.' ...
Read more >
Error: "Failed to send document(s) for E-Signature." Is ...
Primavera Unifier Cloud Service - Version N/A to N/A [Release NA]: Error: "Failed to send document(s) for E-Signature.
Read more >
Unable to Send Document - Operation Failed!
Hi Mackie,. Thank you for reaching out and sorry about the trouble. As you receive error on the mobile application, did you check...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found