'Telegram bot and google apps script not working

Good evening everyone, forgive the trouble, I tried to do a "search" on the site but I could not find the answer to my problem so I thought of opening a new discussion. I make two premises, the first is that I am not familiar with the English language and therefore I am writing to you via google translator, the second is that I am a novice programmer. Having said that, let's get to the tricky part immediately, the following is the code that I put by inserting the token and the webappurl

var token = "YOUR_TOKEN";
var telegramUrl = "https://api.telegram.org/bot" + token;
var webAppUrl = "YOUR_YO_URL";

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

function sendMessage (chat_id, text) {
  var url = telegramUrl + "/ sendMessage? chat_id =" + chat_id + "& text =" + text;
  var response = UrlFetchApp.fetch (url);
}

function doPost (e) {
  var contents = JSON.parse (e.postData.contents);
  var chat_id = contents.message.from.id;
  var answer = "Hello";
  sendMessage (chat_id, answer);
}

once this is done I publish it as a web application I imposed that a new version Execute the app as my account Who has access to the app anyone and press on update i go to my telegram bot and any message i send does not reply to me. I also tried to follow other tutorials (the codes are very similar to each other) but always the same story, I follow the procedures, but when I go to write on the bot it gives me no sign of life. I thank all those who want to help me and I apologize for what for the more experienced will be a very simple problem Thank you


I added the line of code you suggested to me

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

the result was the following

"[22-03-25 19: 00: 07: 208 CET] {" ok ": true," result ": true," description ":" Webhook is already set "}"

but my bot still keeps not responding.



Solution 1:[1]

you have no wrong in your code , you just need to deploy the web app using the old version of Google apps script to go to the old version find this and click on it

1

then deploy it

2

3

4

5

after u get the appurl use it in ur code and deploy it againe . after that go back to the new version of google app script , and every time you make changes and want to deploy use manage deployments

6

7

and you can contact me on telegram to help you , my username : @zedkrimo

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 krimo zerrouni