Amit
Amit

Reputation: 36

Geting "Bad Request: there is no photo in the request" in Telegram BOT API Using Google App Script

I am using the below code in Google App Script to send Image in Telegram Group. Whenever I run this code the photo being sent to the group but I am getting below error:

Exception: Request failed for https://api.telegram.org returned code 400. Truncated server response: {"ok":false,"error_code":400,"description":"Bad Request: there is no photo in the request"} (use muteHttpExceptions option to examine full response). (line 27, file "Send Image")

Currently I am using google drive image link. I have tried images from different sources but same error

  var photo_url = "https://docs.google.com/uc?id=File_Id";
  
  var id = "Chat_Id";
  
  sendPhoto(id,photo_url)
  
   function sendPhoto(id,photo_url) {
   
   var API_TOKEN = "BOT_API_Code";
    
   var payload = {
          'method': 'sendPhoto',
          'chat_id': String(id),
          'photo': photo_url,
          'caption': "My Caption"
        }

        var data = {
          "method": "post",
          "payload": payload
        }
   UrlFetchApp.fetch('https://api.telegram.org/bot' + API_TOKEN + '/', data);
   
}

Upvotes: 1

Views: 1642

Answers (1)

I just added this line at the end of the data key

'muteHttpExceptions':true,

and the photo sends successfully without error.

    var data = {
      "method": "post",
      "payload": payload,
      'muteHttpExceptions':true,
    }

Upvotes: 0

Related Questions