Reputation: 61
I've already this code working to send Polls from a Google Sheet, but I want to add the open_period
for one day, and if it is possible add the reply_markup
option to add buttons to choose the answer instead of a list, and plus, how can I read the JSON possible answers form a cell and not defined by 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);
};
Upvotes: 0
Views: 796
Reputation: 26
You can use variable for each option and use them in answers . I have little modify this code and this is working.
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);
};
Upvotes: 1