var token = "651611557:AAHV5wBEwTw1d9v-tD5iJ6WOGjtaI";
var telegramUrl = "https://api.telegram.org/bot"+token;
var webAppUrl = "https://script.google.com/macros/s/AKfycbwG52kyemggxcPWQTSh0sHDsvoqX0zneIXU0MENFd5l4FMOhrQ0g/exec";
var ssId = "196GxmWJT8cTsRrnSBohSx77YFKYCRtjDu7OCuDkg_JI";
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);
}
function sendText(id, text){
var url = telegramUrl + "/sendMessage?chat_id=" + id +"&text="+text;
var response = UrlFetchApp.fetch(url);
}
function doGet(e){
return HtmlService.createHtmlOutput("Hi there");
}
function doPost(e){
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 = "Салам " + name + "! Спасибо за обращение "+ text;
sendText(id, answer);
SpreadsheetApp.openById(ssId).getSheets()[0].appendRow([new Date(), id, name, answer]);
}
function sendMessage(from_chat_id, text, keyboard, id_msg) { // Отправляет сообщение используя sendMessage
var data = {
method: "sendMessage",
chat_id: String(from_chat_id),
text: text,
parse_mode: "HTML",
reply_markup: JSON.stringify(keyboard),
reply_to_message_id: String(id_msg)
};
var options = {
method: 'POST',
payload: data,
muteHttpExceptions: true
};
var response = UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/sendMessage', options);
console.log(JSON.parse(response.getContentText(), null, 7))
}
let keyboard_contact = {
keyboard: [
[{
text: "Авторизоваться",
request_contact: true
}]
],
resize_keyboard: true,
one_time_keyboard: true
};
let keyboard_menu_inline = {
inline_keyboard: [
[{
text: "Услуги ",
callback_data: "services"
}, {
text: "Оплата ",
url: "https://google.com",
callback_data: "pay"
}],
[{
text: "Статус ✅ ",
url: "https://google.com"
}, {
text: "Обратная связь ",
callback_data: "support"
}]
]
};
sendMessage(from_chat_id, text, keyboard)