[英]How to wait for the next POST request
So what I am trying to do is when the bot receives /uploadPhoto message it waits for the next message and checks if it contains photo. 所以我想做的是当机器人收到/ uploadPhoto消息时,它等待下一条消息并检查是否包含照片。 I have tried many different loops including do..while, if, while and other solutions.
我尝试了许多不同的循环,包括do..while,if,while和其他解决方案。 Now what I think is that I need to call the doPost function from the doPost function.
现在我想的是,我需要从doPost函数中调用doPost函数。 Is there any way to do that?
有什么办法吗?
Tried do..while, if, while and other loops. 尝试过..while,if,while和其他循环。
function doPost(e){
var contents = JSON.parse(e.postData.contents);
var id = contents.message.id;
var text = contents.message.text;
case "uploadPhoto":
sendText(id, "Upload a photo...");
//endText(id, "Upload a photo to be displayed as your product%0AUsage: upload a photo with a caption /uploadPhoto");
/**const zinutes_id = contents.message.message_id;
const zinutes_id_opa = zinutes_id + 1;
while (true) {
if (zinutes_id == zinutes_id_opa){
if ("photo" in contents.message) {
var photo = contents.message.photo[3].file_id;
sendText(id, "okay " + photo);
sendPhoto(id, photo);
break;
}
}
} */
/** if ("photo" in contents.message){
var photo = contents.message.photo[3].file_id;
sendText(id, "okay " + photo);
sendPhoto(id, photo);
} else {
sendText(id, "Upload a photo!");
}*/
break;
} }
EDIT: 编辑:
This is what I managed to do: 这是我设法做到的:
doPost(e){
if(contents.message.includes("photo")){
var fotke = contents.message.photo[3].file_id;
}
if (checkLastCommand(id) == "uploadPhoto") {
if (fotke !== "undefined") {
// @ts-ignore
sheet.getRange(searchUser(id),6).setValue(fotke);
sendText(id, fotke);
// @ts-ignore
sheet.getRange(searchUser(id),7).clear();
} else {
sendText(id, "this is not a photo");
// @ts-ignore
sheet.getRange(searchUser(id),7).clear();
} else if (firstChar === '/') {
case "uploadPhoto":
sendText(id, "Upload a photo...");
sheet.getRange(searchUser(id), 7).setValue("uploadPhoto");
break;
}
}
function checkLastCommand(x) {
// @ts-ignore
var z = sheet.getRange(searchUser(x), 7).getValue();
return z;
}
Now it waits for the photo but for some reason it does not find photo in the POST request. 现在它在等待照片,但是由于某种原因在POST请求中找不到照片。 I get "undefined" in the cell and the bot does not respond to photo but instead to /(command) with undefined
我在单元格中得到“未定义”,并且机器人不响应照片,而是使用未定义来响应/(command)
So apparently I came up with a solution. 所以显然我想出了一个解决方案。
if ("photo" in contents.message) {
var fotke = contents.message.photo[3].file_id;
} else {
var text = contents.message.text;
var firstChar = text.substr(0,1);
}
The program did not want to read file_id of a sent photo because it kept on waiting for a text message. 该程序不希望读取已发送照片的file_id,因为它一直在等待文本消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.