Botframework/Botbuilder-js - 发送 HTTP 请求
Botframework/Botbuilder-js - Send HTTP request
我使用 BotFramework 和 Botbuilder-js 创建了一个 JavaScript 机器人。
对于这个机器人,我使用自适应对话框。
在对话框中的某个时刻,我需要发送一个 HTTP 请求。
目前,我的 HTTP 请求步骤如下所示:
new HttpRequest().configure({
resultProperty: new StringExpression("user.teamProfile.accessToken"),
url: new StringExpression('https://login.microsoftonline.com/myTenantId/oauth2/v2.0/token'),
method: HttpMethod.POST,
contentType: new StringExpression('application/x-www-form-urlencoded'),
headers: {
"Content-Type": new StringExpression("application/x-www-form-urlencoded")
},
body: new StringExpression("client_id: myClientId, scope: https://graph.microsoft.com/.default, client_secret: myclientSecret, grant_type: client_credentials"),
responseType: ResponsesTypes.Json
})
机器人本身可以正常工作,但是当它尝试执行 HTTP 请求步骤时,我收到以下错误消息:
Error: TypeError: path.indexOf is not a function
很遗憾,我没有得到更多信息。谁能帮我 ?
最好的问候,
缓冲区溢出
由于HttpRequest-Step没用,我改成CodeAction。
在这个 CodeAction 中,我然后执行我的 Http-Requests 并处理结果(转换它们或将它们保存在对话框变量中)。
代码片段可能如下所示:
new CodeAction(async (dc, options) => {
// Send your request
// options being the headers, body, etc.
const response = await this.fetch(url, options);
// Work on you result and if necessary, save it to a dialog variable
dc.state.setValue("user.yourPropertyName", value);
// Needed for the Bot to continue working
return await dc.endDialog();
})
我使用 BotFramework 和 Botbuilder-js 创建了一个 JavaScript 机器人。
对于这个机器人,我使用自适应对话框。 在对话框中的某个时刻,我需要发送一个 HTTP 请求。
目前,我的 HTTP 请求步骤如下所示:
new HttpRequest().configure({
resultProperty: new StringExpression("user.teamProfile.accessToken"),
url: new StringExpression('https://login.microsoftonline.com/myTenantId/oauth2/v2.0/token'),
method: HttpMethod.POST,
contentType: new StringExpression('application/x-www-form-urlencoded'),
headers: {
"Content-Type": new StringExpression("application/x-www-form-urlencoded")
},
body: new StringExpression("client_id: myClientId, scope: https://graph.microsoft.com/.default, client_secret: myclientSecret, grant_type: client_credentials"),
responseType: ResponsesTypes.Json
})
机器人本身可以正常工作,但是当它尝试执行 HTTP 请求步骤时,我收到以下错误消息:
Error: TypeError: path.indexOf is not a function
很遗憾,我没有得到更多信息。谁能帮我 ?
最好的问候,
缓冲区溢出
由于HttpRequest-Step没用,我改成CodeAction。
在这个 CodeAction 中,我然后执行我的 Http-Requests 并处理结果(转换它们或将它们保存在对话框变量中)。
代码片段可能如下所示:
new CodeAction(async (dc, options) => {
// Send your request
// options being the headers, body, etc.
const response = await this.fetch(url, options);
// Work on you result and if necessary, save it to a dialog variable
dc.state.setValue("user.yourPropertyName", value);
// Needed for the Bot to continue working
return await dc.endDialog();
})