Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendPhoto returns 400 #12

Closed
m90 opened this issue Jul 20, 2015 · 11 comments
Closed

sendPhoto returns 400 #12

m90 opened this issue Jul 20, 2015 · 11 comments

Comments

@m90
Copy link

m90 commented Jul 20, 2015

I'm having trouble sending any type of media (photos in my case).

I'm passing a request Object (that has a readable Stream interface) to sendPhoto

client.sendPhoto(config.group_chat_id, request(someUrl));

yet telegram returns

[Error: 400 {"ok":false,"error_code":400,"description":"Error: Bad Request: there is no photo in request"}]

I noticed the same thing happens when running the examples in the repository. Has there been an API change, am I doing something wrong or is this a bug?

@yagop
Copy link
Owner

yagop commented Jul 20, 2015

Hi, which URL are you sending?
There was a change on the Telegram API, maybe for a while wasn’t working.
Test are passing now, could you please check again? Thanks

@m90
Copy link
Author

m90 commented Jul 20, 2015

Hi & thanks for getting back to me so quick.

It's still failing, the URL that is used is:

https://api.telegram.org/<token>/sendPhoto

A little unrelated (but maybe related again), I was looking at your tests as well but I'm not too sure if they work at all (that's probably another issue):

When doing with a plain A+ promise:

it('does stuff', function(done){
  thingy().then(function(result){
   assert(false);
   done();
  });
});

the test will still pass as the promise will swallow the thrown exception. So I usually use it like this:

it('does stuff', function(){
  return thingy().then(function(result){
   assert(false);
  });
});

I never use Bluebird though, so I don't know if it handles this smarter (I'm asking in hope for a yes, so I can get rid of that.....).

@yagop
Copy link
Owner

yagop commented Jul 20, 2015

I mean the request URL (someUrl) on client.sendPhoto(config.group_chat_id, request(someUrl));

You can run the test with:

DEBUG='node-telegram-bot-api' \
TEST_TELEGRAM_TOKEN=<YOUR_TOKEN> \
TEST_USER_ID=<YOUR_USER> ./node_modules/.bin/mocha test/index.js

If promise fails, it will throw an Unhandled rejection Error: 400 {"ok":false,"error_code":400,"description":"Error: AUDIO_EXT_INVALID"}

@m90
Copy link
Author

m90 commented Jul 21, 2015

I'm using random image URLs from flickr.

I can save them to disk and do whatever with them so that should not be the
problem I guess.

Can you run the demo in `/examples? ? I'm getting the same error for any kind
of upload here.

Thanks!

@SerjoPepper
Copy link

Maybe it because of the lib make only GET requests, not POST. So large queries can be cut.

@m90
Copy link
Author

m90 commented Aug 6, 2015

@SerjoPepper I actually tried hacking on the lib to make it a POST as I was thinking the same thing as you, but it did not make a difference. I ended up "manually" (i.e. no lib) uploading the files which worked fine.

@yagop
Copy link
Owner

yagop commented Aug 6, 2015

In order to send form data, it sends a POST request. Could you please provide me the URL which you are testing? It works fine with URL with file format extension because Telegram needs an extension.

@m90
Copy link
Author

m90 commented Aug 6, 2015

I was using full image URLs like: https://farm1.staticflickr.com/323/19723079154_f405855a4c.jpg

But as I have already written above I also could not run the example bot in /examples/polling.js as it would fail with the exact same error.

@yagop
Copy link
Owner

yagop commented Aug 6, 2015

Did you try the test and passed them out? Clone the repository, get inside the folder and then:

DEBUG='node-telegram-bot-api' \
TEST_TELEGRAM_TOKEN=<YOUR_TOKEN> \
TEST_USER_ID=<YOUR_USER> ./node_modules/.bin/mocha test/index.js

@m90
Copy link
Author

m90 commented Aug 6, 2015

Ok so this is super weird and seems to be an issue with Telegram. I created a new bot where the token works perfectly fine, whereas when I use the "old" token it will still return the 400.

I'll try to use the two tokens with my own wrapper once I find the time to do so, so we can find out if this is a Telegram issue or not (sounds a lot like it).

@m90
Copy link
Author

m90 commented Aug 6, 2015

So this really is an issue with the token I am using. My own lib, test suites and everything fails when using that one single token. Everything else works. Going to contact Telegram regarding that.

Thanks for your input and sorry for all that noise.

@m90 m90 closed this as completed Aug 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants