gpt4 book ai didi

javascript - 如何等待下一个POST请求

转载 作者:行者123 更新时间:2023-12-02 23:18:21 24 4
gpt4 key购买 nike

所以我想做的是,当机器人收到/uploadPhoto 消息时,它会等待下一条消息并检查它是否包含照片。我尝试了许多不同的循环,包括 do..while、if、while 和其他解决方案。现在我认为我需要从 doPost 函数调用 doPost 函数。有什么办法可以做到吗?

尝试过 do..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;

}

  1. 向机器人发送文本/上传照片
  2. 机器人回复短信“上传照片...”
  3. 机器人等待下一条消息并解析其内容

编辑:

这就是我设法做到的:

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;
}

现在它正在等待照片,但由于某种原因它在 POST 请求中找不到照片。我在单元格中得到“未定义”,并且机器人不响应照片,而是响应未定义的/(命令)

最佳答案

显然我想出了一个解决方案。

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);
}

程序不想读取已发送照片的 file_id,因为它一直在等待短信。

关于javascript - 如何等待下一个POST请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57065657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com