【发布时间】:2020-08-21 23:33:05
【问题描述】:
我正在尝试使用节点向现有对话发送主动团队消息。
已按照https://docs.microsoft.com/en-us/microsoftteams/platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages?tabs=javascript 中描述的方法为用户安装了机器人,并且还检索了对话 chatId。
我的目标是创建一个“控制台”风格的应用程序,我可以在其中将主动消息推送到此对话,但我坚持将有效 URL 传递给 trustServiceUrl 方法并观察以下错误:
TypeError [ERR_INVALID_ARG_TYPE]:“url”参数必须是字符串类型。接收类型未定义
示例代码:
const path = require('path');
const botbuilder = require('botbuilder');
const ENV_FILE = path.join(__dirname, '.env');
require('dotenv').config({ path: ENV_FILE });
const { MicrosoftAppCredentials } = require('botframework-connector');
const adapter = new botbuilder.BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});
async function Main() {
var conversationRef = '[MY TEAMS CONVERSATION REFERENCE]';
let response = await sendMessage(conversationRef);
}
function sendMessage(conversationRef) {
var promise = new Promise(function(resolve, reject) {
adapter.continueConversation(conversationRef, async turnContext => {
const serviceUrl = 'https://smba.trafficmanager.net/uk/';
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);
await turnContext.sendActivity('proactive hello');
});
});
return promise;
}
Main();
我知道我忽略了一些明显的东西,但我遇到了上述错误 - 感谢任何指导。
谢谢!
跟踪如下:
(node:16504) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type undefined
at validateString (internal/validators.js:118:11)
at Url.parse (url.js:159:3)
at Object.urlParse [as parse] (url.js:154:13)
at Function.trustServiceUrl (C:\dev\demo\botFramework\node_modules\botframework-connector\lib\auth\appCredentials.js:68:25)
at BotFrameworkAdapter.<anonymous> (C:\dev\demo\botFramework\node_modules\botbuilder\lib\botFrameworkAdapter.js:153:57)
at Generator.next (<anonymous>)
at C:\dev\demo\botFramework\node_modules\botbuilder\lib\botFrameworkAdapter.js:14:71
at new Promise (<anonymous>)
at __awaiter (C:\dev\demo\botFramework\node_modules\botbuilder\lib\botFrameworkAdapter.js:10:12)
at BotFrameworkAdapter.continueConversation (C:\dev\demo\botFramework\node_modules\botbuilder\lib\botFrameworkAdapter.js:139:16)
(node:16504) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:16504) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
PS C:\dev\demo\botFramework>
【问题讨论】:
-
您有多确定它在
trustServiceUrl()上失败了?这看起来很好。您可以将完整的堆栈跟踪添加到您的问题中吗? -
感谢@mdrichardson - 已将全部详细信息添加到原始帖子中。
标签: node.js botframework microsoft-teams