gpt4 book ai didi

node.js - BotBuilder、Direct Line API 返回 "tokenParameters is missing User"并具有增强的身份验证选项

转载 作者:太空宇宙 更新时间:2023-11-03 22:05:10 24 4
gpt4 key购买 nike

我在 Azure 帐户上发布了一个机器人,我试图从中取出魔法代码,因此请遵循 Direct Line documentation我改进了代码以隐藏 token 。但是,一旦启用增强型身份验证选项,我总是会得到相同的响应。

{
"error": {
"code": "BadArgument",
"message": "tokenParameters is missing User."
}
}

而且我无法弄清楚如何使用用户数据完成 HTTP 请求。

该机器人基于 BotFramework SDK v4,加上一些用于使用封装的 key 请求和刷新 token 的 Controller 。我通过不同且错误的方式将 userId 数据添加到请求中,但始终得到相同的结果。

请求 token 代码

server.post('/dl/tokenRequest', async (_, res) => {
try {
const userId = "dl_testuser1";
const askToken = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
headers: {
authorization: Bearer ${ process.env.DIRECT_LINE_SECRET }
},
//HERE THE userId INFORMATION,
method: 'POST'
});
const json = await askToken.json();
if ('error' in json) {
console.log('Requesting token - Error');
res.send(500);
} else {
console.log(`Requesting token ` + json.token);
res.send(json);
}
} catch (err) {
res.send(500);
}
});

在启用增强型工具之前,我应该如何输入用户信息才能从 DL API 获得“确定”?

最佳答案

您的 header 中似乎缺少 Content-Type。看看下面的代码片段。

try {
const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate',
{
method: 'POST',
headers: {
'Authorization': `Bearer <SECRET>`,
'Content-Type': 'application/json'
},
body: {
user: {
id: "dl_123", // user id must start with 'dl_'
name: "user"
}
}
});

const json = await res.json();

} catch (error) {
console.log(error)
}

注意,您不必检查 JSON 响应中是否存在“错误” - try-catch block 应该处理该问题。

希望这有帮助!

关于node.js - BotBuilder、Direct Line API 返回 "tokenParameters is missing User"并具有增强的身份验证选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56026764/

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