我正在尝试使用机器人在频道中发送消息,但出现以下错误。
错误:TypeError:无法读取未定义的属性“创建”
在调试时我发现那context.adapter.ConnectorFactoryKey
是空的
我从这里的源代码中获取代码的动机:
团队机器人.js
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];
}
}
清单.json
{
"$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"
}
}
我在上面做错了什么?