我刚刚开始学习有关制作Slack应用程序的知识,并且试图验证为我的命令传递的参数是有效用户。我尝试使用val.ok并用try-catch包围它,但是我似乎无法弄清楚如果找不到它们该如何处理。
const { WebClient } = require('@slack/web-api');
const web = new WebClient(TOKEN);
exports.myCommand = (req, res) => {
let userId = req.body.text;
let message = {"text": ""};
res.status(200).send("Verifying user...");
(async () => {
let val = await web.users.info({user: userId});
if (!val.ok) {
message.text = "Error: "+ user +" not found";
} else {
message.text = "User: " + user;
}
})();
};
我会以正确的方式进行操作,还是有更好的选择?