Hi,
I'm trying to send tree questions via Telegram, collect the answers and post them to Google Forms.
I have a working bot and the posting part figured out, the part that am struggling with is the function.
It should work like this:
The user sends a message, and by default that's the answer to the first question, function stores it in a variable, then asks YES or NO for the second question (as question 2 and 3 are optional )if you responds with YES it asks the second question and stores it in a second variable, and sends again YES or NO for third question and stores it ...
When it's done with the questions asks YES or NO to post. When done flush variables.
This is the code for YES no NO
var opts = {
reply_markup: JSON.stringify({
keyboard: [
['/YES'],
['/NO']],
'resize_keyboard' : true,
'one_time_keyboard' : true
})
};
msg.error = false;
// Dialogaufbau
msg.payload.content = 'Utrošen materijal?'; // QUESTION
msg.payload.options = opts;
msg.payload.chatId = msg.payload.chatId;
msg.payload.messageId = 99;
msg.payload.sentMessageId = 99;
msg.payload.type = "message";
Work in progress flow
[{"id":"d76bd423.63fc68","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"6f374a8b.b68764","type":"telegram receiver","z":"d76bd423.63fc68","name":"","bot":"93994684.5d2958","saveDataDir":"","filterCommands":false,"x":210,"y":280,"wires":[["54d4a7d9.bbf5d8"],[]]},{"id":"54d4a7d9.bbf5d8","type":"function","z":"d76bd423.63fc68","name":"Sorting chatID","func":"var ID = msg.payload.chatId;\nvar Miljan = xxxxxxxxxx;\nvar Lepi = xxxxxxxx;\nvar Milos = xxxxxxxxx;\nvar Dejan = xxxxxxxxx;\n\nif (ID == Miljan) {\n \n return [msg,null,null,null]\n}\nif (ID == Lepi) {\n \n return [null,msg,null,null]\n}\nif (ID == Dejan) {\n \n return [null,null,msg,null]\n}\nif (ID == Milos) {\n \n return [null,null,null,msg]\n}\n\nelse\n\nreturn null;","outputs":4,"noerr":0,"initialize":"","finalize":"","x":420,"y":280,"wires":[["9d95a85b.e3aae8"],[],[],[]],"outputLabels":["Miljan","Lepi","Dejan","Milos"]},{"id":"cd81b3ec.f705","type":"telegram sender","z":"d76bd423.63fc68","name":"","bot":"93994684.5d2958","haserroroutput":false,"outputs":1,"x":950,"y":220,"wires":[[]]},{"id":"7dd4e3c9.85a1dc","type":"http request","z":"d76bd423.63fc68","name":"Post to Google Forms","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://docs.google.com/forms/d/e/xxxxxxxxxCzaKRqQ/formResponse?entry.1765987963={{payload.unos}}","tls":"","persist":false,"proxy":"","authType":"","x":960,"y":300,"wires":[[]]},{"id":"9d95a85b.e3aae8","type":"function","z":"d76bd423.63fc68","name":"user 1 function","func":"\n\n\n// work in progres\nvar opts = {\n reply_markup: JSON.stringify({\n keyboard: [\n ['/YES'],\n ['/NO']],\n 'resize_keyboard' : true, \n 'one_time_keyboard' : true\n })\n};\n\nmsg.error = false;\n// Dialogaufbau\nmsg.payload.content = 'Utrošen materijal?'; // QUESTION\nmsg.payload.options = opts;\n\nmsg.payload.chatId = msg.payload.chatId;\nmsg.payload.messageId = 99;\nmsg.payload.sentMessageId = 99;\nmsg.payload.type = \"message\";\n\nreturn [ msg ];\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":660,"y":220,"wires":[["cd81b3ec.f705"],["7dd4e3c9.85a1dc"]]},{"id":"93994684.5d2958","type":"telegram bot","botname":"NatalySpa","usernames":"","chatids":"1026277503,1457589930,5020608523,5234937789,","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":true}]