如何解决Botframework / Botbuilder-js-发送HTTP请求
我使用BotFramework和Botbuilder-js创建了一个JavaScript Bot。
对于这个机器人,我使用了自适应对话框。 在对话框中的某个时刻,我需要发送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-Request步骤时,出现以下错误消息:
Error: TypeError: path.indexOf is not a function
很遗憾,我没有更多的信息。谁能帮我 ?
最好的问候,
BufferOverflow
解决方法
由于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();
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。