1

Is there any way to adjust this function for use with ARRAYFORMULA in spreadsheets?

function SendTelegram(botSecret, chatId, body) {
  var response = UrlFetchApp.fetch("https://api.telegram.org/bot" + botSecret + "/sendMessage?text=" + encodeURIComponent(body) + "&chat_id=" + chatId + "&parse_mode=HTML");
}

Instead of using a formula for each line like this:

=SendTelegram($H$1,$I$1,F2)
=SendTelegram($H$1,$I$1,F3)
=SendTelegram($H$1,$I$1,F4)
=SendTelegram($H$1,$I$1,F5)

By using this way:

=ARRAYFORMULA(SendTelegram($H$1,$I$1,F2:F))

Returns the following message:

Limit Exceeded: URLFetch URL Length. (line 22).
2
  • Are you asking to modify it or asking how to use it? Commented Nov 24, 2019 at 3:53
  • Guidelines for Custom Functions Commented Nov 24, 2019 at 4:36

1 Answer 1

2

Something like this, you might have to adjust to the particular behavior you want.

function SendTelegram(botSecret, chatId, body) {
  if (body.map) { // is array?
  var response = body.map(function(b) {return SendTelegram(botSecret,chatId,b);});
   } else {
  var response = UrlFetchApp.fetch("https://api.telegram.org/bot" + botSecret + "/sendMessage?text=" + encodeURIComponent(body) + "&chat_id=" + chatId + "&parse_mode=HTML");
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.