使用 open_period 时间和 reply_markup 按钮从 Google Sheets App Script sendPoll to Telegram
sendPoll to Telegram from Google Sheets App Script with open_period time and reply_markup buttons
我已经使用此代码从 Google Sheet 发送民意调查,但我想添加 open_period
一天,如果可能的话添加reply_markup
添加按钮来选择答案而不是列表的选项,另外,我如何从一个单元格中读取 JSON 可能的答案而不是由 var answers = ['✌️ VOY', 'NO PUEDO IR', 'POSIBLEMENTE SI VAYA'];
定义?
function sendPoll() {
var sheet = SpreadsheetApp.getActive().getSheetByName("DATA");
var question = sheet.getRange("B1").getValues();
//var answers = sheet.getRange("B2").getValues(); //How can I read the poll answers from a cell?
var answers = ['✌️ VOY', 'NO PUEDO IR', 'POSIBLEMENTE SI VAYA'];
var bot = sheet.getRange("B3").getValues();
var chatId = sheet.getRange("B4").getValues();
var payload = {
"method": 'sendPoll',
"chat_id": String(chatId),
"question": String(question),
"parse_mode": 'HTML',
"options": JSON.stringify(answers),
"is_anonymous": false,
"type": 'regular',
"allows_multiple_answers": false,
"open_period": 0
}
var data = {
"method": "post",
"payload": payload,
"muteHttpExceptions":true
};
var response = UrlFetchApp.fetch('https://api.telegram.org/bot' + bot + '/', data);
Logger.log(response);
};
您可以为每个选项使用变量并在答案中使用它们。我几乎没有修改这段代码,这是有效的。
function sendPoll() {
var sheet = SpreadsheetApp.getActive().getSheetByName("DATA");
var question = sheet.getRange("B1").getValues();
var option1 = sheet.getRange("C1").getValues();
var option2 = sheet.getRange("C2").getValues();
var option3 = sheet.getRange("C3").getValues();
var option4 = sheet.getRange("C4").getValues();
var answers = [''+option1+'', ''+option2+'', ''+option3+'', ''+option4+''];
var bot = sheet.getRange("B3").getValues();
var chatId = sheet.getRange("B4").getValues();
var explanation = sheet.getRange("B4").getValues();
var payload = {
"method": 'sendPoll',
"chat_id": String(chatId),
"question": String(question),
"parse_mode": 'HTML',
"options": JSON.stringify(answers),
"is_anonymous": true,
"type": 'quiz',
"allows_multiple_answers": false,
"open_period": 0,
"correct_option_id": 1,
"explanation": String(explanation)
}
var data = {
"method": "post",
"payload": payload,
"muteHttpExceptions":true
};
var response = UrlFetchApp.fetch('https://api.telegram.org/bot' + bot + '/', data);
Logger.log(response);
};
我已经使用此代码从 Google Sheet 发送民意调查,但我想添加 open_period
一天,如果可能的话添加reply_markup
添加按钮来选择答案而不是列表的选项,另外,我如何从一个单元格中读取 JSON 可能的答案而不是由 var answers = ['✌️ VOY', 'NO PUEDO IR', 'POSIBLEMENTE SI VAYA'];
定义?
function sendPoll() {
var sheet = SpreadsheetApp.getActive().getSheetByName("DATA");
var question = sheet.getRange("B1").getValues();
//var answers = sheet.getRange("B2").getValues(); //How can I read the poll answers from a cell?
var answers = ['✌️ VOY', 'NO PUEDO IR', 'POSIBLEMENTE SI VAYA'];
var bot = sheet.getRange("B3").getValues();
var chatId = sheet.getRange("B4").getValues();
var payload = {
"method": 'sendPoll',
"chat_id": String(chatId),
"question": String(question),
"parse_mode": 'HTML',
"options": JSON.stringify(answers),
"is_anonymous": false,
"type": 'regular',
"allows_multiple_answers": false,
"open_period": 0
}
var data = {
"method": "post",
"payload": payload,
"muteHttpExceptions":true
};
var response = UrlFetchApp.fetch('https://api.telegram.org/bot' + bot + '/', data);
Logger.log(response);
};
您可以为每个选项使用变量并在答案中使用它们。我几乎没有修改这段代码,这是有效的。
function sendPoll() {
var sheet = SpreadsheetApp.getActive().getSheetByName("DATA");
var question = sheet.getRange("B1").getValues();
var option1 = sheet.getRange("C1").getValues();
var option2 = sheet.getRange("C2").getValues();
var option3 = sheet.getRange("C3").getValues();
var option4 = sheet.getRange("C4").getValues();
var answers = [''+option1+'', ''+option2+'', ''+option3+'', ''+option4+''];
var bot = sheet.getRange("B3").getValues();
var chatId = sheet.getRange("B4").getValues();
var explanation = sheet.getRange("B4").getValues();
var payload = {
"method": 'sendPoll',
"chat_id": String(chatId),
"question": String(question),
"parse_mode": 'HTML',
"options": JSON.stringify(answers),
"is_anonymous": true,
"type": 'quiz',
"allows_multiple_answers": false,
"open_period": 0,
"correct_option_id": 1,
"explanation": String(explanation)
}
var data = {
"method": "post",
"payload": payload,
"muteHttpExceptions":true
};
var response = UrlFetchApp.fetch('https://api.telegram.org/bot' + bot + '/', data);
Logger.log(response);
};