【问题标题】:Proactive Teams message - trustServiceUrl The "url" argument must be of type stringProactive Teams 消息 - trustServiceUrl “url”参数必须是字符串类型
【发布时间】: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


【解决方案1】:

请确保您的 conversationRef 具有 serviceUrl 属性。它可能与您为trustServiceUrl() 设置的相同

【讨论】:

  • 再次感谢您的帮助 - 我认为我正在接近 conversationRef 都错了,我实际上是通过从 docs.microsoft.com/en-us/microsoftteams/platform/graph-api/… 文章中获得的 ChatID 到 ConversationRef 看起来它需要是一个对象根据您的反馈。我在没有任何入站交互的情况下处理此问题以从中获取上下文,因此将研究更多内容:如何在知道 chatID 时建立 conversationRef 对象。
  • @Timbo13 This should help。任何带有 ? 的属性都是可选的,但 Teams 需要更多。我建议尝试this sample 并查看the conversation reference it builds
  • 感谢@mdrichardson - 对延迟回复表示歉意,您的上述提示让我得到了整理。查看示例中的对话参考是缺少的链接。再次感谢。
【解决方案2】:

请参阅@mdrichardson 的 cmets - 我的参考资料格式不正确,并且未包含所有必需的属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-02
    • 2020-09-19
    • 1970-01-01
    • 2020-05-03
    • 2019-11-27
    • 2022-01-04
    • 2021-12-24
    • 1970-01-01
    相关资源
    最近更新 更多