我在使用 watson assistant 的聊天机器人 ap 中遇到 post 请求问题
i am have an issue with post request in the chatbot ap using watson assistant
在生成会话 ID 后向 postman 发送 post 请求时,它进入 catch 块,并显示错误
Error: Missing required parameters: sessionId
at Object.getMissingParams (E:\Projects\ChatBot App\node_modules\ibm-cloud-sdk-core\lib\helper.js:116:11)
at AssistantV2.message (E:\Projects\ChatBot App\node_modules\ibm-watson\assistant\v2.js:217:50)
at E:\Projects\ChatBot App\routes\api\watson.js:44:41
at Layer.handle [as handle_request] (E:\Projects\ChatBot App\node_modules\express\lib\router\layer.js:95:5)
at next (E:\Projects\ChatBot App\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (E:\Projects\ChatBot App\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (E:\Projects\ChatBot App\node_modules\express\lib\router\layer.js:95:5)
at E:\Projects\ChatBot App\node_modules\express\lib\router\index.js:281:22
at Function.process_params (E:\Projects\ChatBot App\node_modules\express\lib\router\index.js:335:12)
at next (E:\Projects\ChatBot App\node_modules\express\lib\router\index.js:275:10)
密码是:
router.post('/message', async (req, res) => {
payload = {
assistantId: process.env.WA_ASSISTANT_ID,
sessionId: req.headers.session_id,
input: {
message_type: "text",
text: req.body.input,
},
};
try {
const message = await assistant.message(payload);
res.json(message["result"]);
} catch (err) {
res.send("There was an error processing your request.");
console.log(err);
}
});
您的 Postman 屏幕截图显示您添加了 session_id 作为 URL 参数。那将是一个 GET 请求。您需要将 assistantId 和 session_id 作为 POST 请求的负载传输,即作为请求正文中的数据。然后它应该工作。
这与 IBM Watson Assistant 无关,而是 http requests 的工作方式。
在生成会话 ID 后向 postman 发送 post 请求时,它进入 catch 块,并显示错误
Error: Missing required parameters: sessionId
at Object.getMissingParams (E:\Projects\ChatBot App\node_modules\ibm-cloud-sdk-core\lib\helper.js:116:11)
at AssistantV2.message (E:\Projects\ChatBot App\node_modules\ibm-watson\assistant\v2.js:217:50)
at E:\Projects\ChatBot App\routes\api\watson.js:44:41
at Layer.handle [as handle_request] (E:\Projects\ChatBot App\node_modules\express\lib\router\layer.js:95:5)
at next (E:\Projects\ChatBot App\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (E:\Projects\ChatBot App\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (E:\Projects\ChatBot App\node_modules\express\lib\router\layer.js:95:5)
at E:\Projects\ChatBot App\node_modules\express\lib\router\index.js:281:22
at Function.process_params (E:\Projects\ChatBot App\node_modules\express\lib\router\index.js:335:12)
at next (E:\Projects\ChatBot App\node_modules\express\lib\router\index.js:275:10)
密码是:
router.post('/message', async (req, res) => {
payload = {
assistantId: process.env.WA_ASSISTANT_ID,
sessionId: req.headers.session_id,
input: {
message_type: "text",
text: req.body.input,
},
};
try {
const message = await assistant.message(payload);
res.json(message["result"]);
} catch (err) {
res.send("There was an error processing your request.");
console.log(err);
}
});
您的 Postman 屏幕截图显示您添加了 session_id 作为 URL 参数。那将是一个 GET 请求。您需要将 assistantId 和 session_id 作为 POST 请求的负载传输,即作为请求正文中的数据。然后它应该工作。
这与 IBM Watson Assistant 无关,而是 http requests 的工作方式。