首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用bot框架在通道中发送主动消息时出错

使用bot框架在通道中发送主动消息时出错
EN

Stack Overflow用户
提问于 2021-12-28 18:02:37
回答 1查看 168关注 0票数 0

,我正在尝试使用bot在通道中发送一条消息,但是得到了下面的错误。

错误: TypeError:无法读取未定义的属性“创建”

调试时,我发现context.adapter.ConnectorFactoryKey为空

我从源代码中获取代码的动机如下:

nodejs/58.团队-启动-新线程-通道

teamsBot.js

代码语言:javascript
运行
复制
    const {
        TurnContext,
        MessageFactory,
        TeamsActivityHandler,
        teamsGetChannelId
    } = require('botbuilder');
    
    class TeamsStartNewThreadInChannel extends TeamsActivityHandler {
        constructor() {
            super();
    
            this.onMessage(async (context, next) => {
                const teamsChannelId = teamsGetChannelId(context.activity);
                const message = MessageFactory.text('This will be the first message in a new thread');
                const newConversation = await this.teamsCreateConversation(context, teamsChannelId, message);
    
                await context.adapter.continueConversationAsync(process.env.MicrosoftAppId, newConversation[0], async turnContext => {
                    await turnContext.sendActivity(MessageFactory.text('This will be the first response to the new thread'));
                });
    
                await next();
            });
        }
    
        async teamsCreateConversation(context, teamsChannelId, message) {
            const conversationParameters = {
                isGroup: true,
                channelData: {
                    channel: {
                        id: teamsChannelId
                    }
                },
    
                activity: message
            };
    
            const connectorFactory = context.turnState.get(context.adapter.ConnectorFactoryKey);
            const connectorClient = await connectorFactory.create(context.activity.serviceUrl);
    
            const conversationResourceResponse = await connectorClient.conversations.createConversation(conversationParameters);
            const conversationReference = TurnContext.getConversationReference(context.activity);
            conversationReference.conversation.id = conversationResourceResponse.id;
            return [conversationReference, conversationResourceResponse.activityId];
        }
    }

Manifest.json

代码语言:javascript
运行
复制
{
    "$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.11/MicrosoftTeams.schema.json",
    "manifestVersion": "1.11",
    "version": "1.0.0",
    "id": "ef2axxx-xx-xx-xxx-4810d",
    "packageName": "com.microsoft.teams.extension",
    "developer": {
        "name": "Teams App, Inc.",
        "websiteUrl": "https://www.example.com",
        "privacyUrl": "https://www.example.com/index.html#/privacy",
        "termsOfUseUrl": "https://www.example.com/index.html#/termsofuse"
    },
    "icons": {
        "color": "resources/color.png",
        "outline": "resources/outline.png"
    },
    "name": {
        "short": "heloo-local-debug",
        "full": "heloo-local-debug"
    },
    "description": {
        "short": "Short description of heloo-local-debug",
        "full": "Full description of heloo-local-debug"
    },
    "accentColor": "#FFFFFF",
    "bots": [
        {
            "botId": "ddd5e0xxx-xxx-xxx-xxxx-5e89c1a83d",
            "scopes": [
                "personal",
                "team",
                "groupchat"
            ],
            "supportsFiles": false,
            "isNotificationOnly": false,
            "commandLists": [
                {
                    "scopes": [
                        "personal",
                        "team",
                        "groupchat"
                    ],
                    "commands": [
                        {
                            "title": "welcome",
                            "description": "Resend welcome card of this Bot"
                        },
                        {
                            "title": "learn",
                            "description": "Learn about Adaptive Card and Bot Command"
                        }
                    ]
                }
            ]
        }
    ],
    "composeExtensions": [],
    "configurableTabs": [],
    "staticTabs": [],
    "permissions": [
        "identity",
        "messageTeamMembers"
    ],
    "validDomains": [
        "d510-xxx-xxx-215.ngrok.io"
    ],
    "webApplicationInfo": {
        "id": "6-xxx-xxx-xxx7",
        "resource": "api://botid-dd-xxxxx-xxx-xxx565e89c1a83d"
    }
}

我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2021-12-28 18:45:48

记住,可以在很多情况下使用,团队只是其中之一。但是,当您在团队中时,没有与用户“创建”对话的概念。只有一次“对话”,你基本上是在“继续”对话。因此,您需要调用continueConversation。看一看这个样本,我发布了一段时间-我已经链接到最相关的线路。

请注意,正如我上面提到的,这要求用户已经安装了你的机器人应用程序--如果没有现有的上下文,你就不能与用户开始积极的对话。如果您想了解如何预装机器人,请参阅以下问题:积极主动地为多个用户团队安装/推送应用程序

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70510823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档