Home > database >  Possible to update one google appscript that affects other google appscript?
Possible to update one google appscript that affects other google appscript?

Time:10-04

I have created a working telegram bot using google apps script. However, i've ran into an issue whereby i have to update multiple different apps scripts when I make an update to the main code.

The reason I need to have more than 1 google apps script is that only 1 bot can be webhook onto one web app URL. And I need multiple bots because it's for different groups of users, but the functions are identical.

The code is about 700 lines long.

Is there any way that I can update the main google apps script without the need to update other google apps scripts?

Edit 1:

To better explain my problem, i'll illustrate it in terms of the code i've made.

var token = "1xxx"; // bot 1
var token2 = "yyy" // bot 2
var telegramUrl = "https://api.telegram.org/bot"   token; 
var telegramUrl2 = "https://api.telegram.org/bot"   token2;

function setWebhook() {
  var url = telegramUrl   "/setWebhook?url="   webAppUrl;
  var response = UrlFetchApp.fetch(url);
}

 function setWebhook2() {
 var url = telegramUrl2   "/setWebhook?url="   webAppUrl;
 var response = UrlFetchApp.fetch(url);
 }

function doPost(e) {
  var contents = JSON.parse(e.postData.contents);
}

so this is what ive tried to do, by having 2 bots webhooked to a single google apps script. However when i send a message , an event is created which is known as 'e', which is the parameter for doPost function. Such that if i send a message to bot1, bot 1 and bot 2 both will send a message to me. What i want is that if i send a message to bot 1 , only bot 1 will reply me.

if that problem is solve , then it solves the original problem because i do not have to edit multiple google apps script , because right now every bot is ran by an independent google apps script and all the google apps script has the same code , the only difference are the tokens and webappURL

CodePudding user response:

Google apps script web app doesn't support path parameters(https://script.google.com/*/exec/{path/token/unique_bot_id}) in the url. So I don't think you can use the same script project for multiple bots. The data received from bots don't seem to specify the bot it's addressing the data to either. So you don't have any unique identifying factors on the data received.

You may however use multiple script projects with each script pointing to a parent script. This way, when the parent script is updated, all child scripts use the parent script. The parent script maybe published as a library or hosted in a another web app or a web host and evald in the child scripts.

  • Related