I am trying to build a simple log of telegram messages in a Group to a Google sheet. Initially I started with text messages and they logged into the sheet fine. however, when i added functionality for pictures, the code is logging only pictures and ignoring text messages. I dont understand why?
Here is the Code:
'''
var token = "<my_token>";
var url = "https://api.telegram.org/bot" + token;
var webAppUrl = "<webapp url";
function setWebhook(){
var response = UrlFetchApp.fetch(url + "/setWebhook?url=" + webAppUrl);
Logger.log(response.getContentText());
}
function doPost(e){
var contents = JSON.parse(e.postData.contents);
var text = contents.message.text;
var caption = contents.message.caption;
var id = contents.message.from.id;
var name = contents.message.from.first_name + " " + contents.message.from.last_name;
var ss= SpreadsheetApp.openByUrl("<sheet url>");
var fileid = contents.message.photo[contents.message.photo.length - 1]["file_id"];
var response = UrlFetchApp.fetch(url + '/getFile?file_id=' + fileid);
var urlphoto = 'https://api.telegram.org/file/bot' + token + '/' + JSON.parse(response.getContentText()).result["file_path"];
var resa = UrlFetchApp.fetch(urlphoto);
var blob = resa.getBlob();
var jum = DriveApp.createFile(blob).setName(new Date().toLocaleString());
var fileLink = jum.getUrl();
ss.appendRow([new Date(), id, name, text, caption, fileLink, contents]);
}
Thanks in Advance for your help.