S
S
Sergey2019-06-27 14:47:16
Bots
Sergey, 2019-06-27 14:47:16

Accepting reports in a telegram bot and structuring them?

Good afternoon, tell me how to do / what to see, read.
I want to do something so that the telegram bot I made with the help BotFather + ManyBotof sends data from the survey form data to Google spreadsheets.
It has different menu items, poll is one of them.
The bottom line is that I want

ставить задачи людям и отчет принимать в телеграм в виде опроса (пошаговая форма)
and structure it in google spreadsheets.
Perhaps there are more adequate and не сложныеoptions for receiving / checking reports?
Communication will be in a cart, I don’t want people to go to some kind of CRM or applications, it will not be convenient.
From languages ​​I understand only a little in JS.
Now the problem with the script is that if I connect it to the bot, then all its menus do not work, but it only works with this script in Google docs.
var token       = "880958063:qqqqqqqqqqqqqqqqqqqqqqq";
var telegramUrl = "https://api.telegram.org/bot" + token;
var webAppUrl   = "https://script.google.com/macros/s/qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq/exec";
var ssId        = "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq";

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=" + text;
  var response = UrlFetchApp.fetch(url);
  Logger.log(response.getContentText());
}

function doGet(e) {
  return HtmlService.createHtmlOutput("Hi there");
}

function doPost(e) {
  // this is where telegram works
  var data = JSON.parse(e.postData.contents);
  Logger.log(data);
  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 + ", thank you for your comment " + text;
  sendText(id,data);
  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 comment = text.split(" ").slice(1).join(" ");
    sheet.appendRow([new Date(),id,name,comment,answer]);
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Noir, 2019-06-28
@1Sergey1

https://www.youtube.com/watch?v=XoTpdxbkGGk
ocordova.me/blog/telegram-bot-with-apps-script
https://medium.com/@grclubpoker/bot-happens-telegr...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question