Answer the question
In order to leave comments, you need to log in
Pull rows by search in tables?
Guys, help with such a problem, We write to the bot "Fio" and the bot looks in the table and pulls out the line and writes to the chat
Answer the question
In order to leave comments, you need to log in
You need to put the webhook in Google sheets. getMe() and setWebhook() are the main ones.
Then through @ you can call the things you need.
There is a video on YouTube "Telegram Bot Tutorial - 1 - Setting up the Bot and Google Apps Script".
// добавь в Google Apps Script
var token = ""; // 1. FILL IN YOUR OWN TOKEN
var telegramUrl = "https://api.telegram.org/bot" + token;
var webAppUrl = ""; // 2. GOOGLE WEB APP ADDRESS
var ssId = ""; // 3. SPREADSHEET ID https://docs.google.com/spreadsheets/d/{ID_HERE}/edit
var adminID = ""; // 4. Твой Telegram ID для дебага
function getMe() {
var url = telegramUrl + "/getMe";
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function setWebhook() {
var url = telegramUrl + "/setWebhook?url=" + webAppUrl;
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function sendText(id,text) {
var url = telegramUrl + "/sendMessage?chat_id=" + id + "&text=" + encodeURIComponent(text);
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function doGet(e) {
return HtmlService.createHtmlOutput("Hi there");
}
function doPost(e) {
try {
// this is where telegram works
var data = JSON.parse(e.postData.contents);
var text = data.message.text;
var id = data.message.chat.id;
var name = data.message.chat.first_name + " " + data.message.chat.last_name;
var answer = "Hi " + name;
sendText(id,answer);
SpreadsheetApp.openById(ssId).getSheets()[0].appendRow([new Date(),id,name,text,answer]);
if(/^@/.test(text)) {
var sheetName = text.slice(1).split(" ")[0];
var sheet = SpreadsheetApp.openById(ssId).getSheetByName(sheetName) ? SpreadsheetApp.openById(ssId).getSheetByName(sheetName) : SpreadsheetApp.openById(ssId).insertSheet(sheetName);
var newText = text.split(" ").slice(1).join(" ");
sheet.appendRow([new Date(),id,name,newText,answer]);
sendText(id,"your text '" + newText + "' is now added to the sheet '" + sheetName + "'");
}
} catch(e) {
sendText(adminID, JSON.stringify(e,null,4));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question