0

I'm following this youtube tutorial.

I am using a Google Apps Script to set up a Telegram Webhook, so that I can record all Private Messages, Group Messages, Channel Posts with the Bot into 1 Google Sheet.

  • Bot is admin of both the Group Chat and Channel
  • Bot Private Settings are turned off

The Bot system works perfectly with Private Messages, Group Messages.

But it doesnt seem to receive any new Channel Posts at all.

("Email Test Log" shown in code doesnt show any response from Channel Posts)

// THIS WORKS -bot token is ok
function getMe() {
  var response = UrlFetchApp.fetch(url+"/getMe");
}

// THIS WORKS -webhook is ok
function setWebhook() {
  var response = UrlFetchApp.fetch(url+"/setWebhook?url="+webAppUrl);
}

// THIS WORKS -webapp works
function doGet(e) {
  return HtmlService.createHtmlOutput("bye" + JSON.stringify(e));
}

// DOES NOT WORK WITH CHANNELS? WORKS WITH DM AND GROUP CHATS
function doPost(e) {
  var contents = JSON.parse(e.postData.contents);

  var text = contents.message.text;
  var msgid = contents.message.from.id;
  var first_name = contents.message.from.first_name;
  var last_name = contents.message.from.last_name;
  var name = first_name+" "+last_name;

  // Email Test Log
  GmailApp.sendEmail(Session.getEffectiveUser().getEmail(), "Telegram Bot Update", JSON.stringify(e, null, 4));

  // Fill in Google Spreadsheet
  data = [new Date(), msgid, name, text, contents]
  SpreadsheetApp.openById(ssId).appendRow(data)  
}

(Extra: The bot is able to SEND messages to Private Message, Group Chat, AND Channels. It just cannot read the posts from Channels?)

0 Answers0