我有一个部署到Microsoft Teams的机器人(基于旧的核心机器人示例)。有时,当团队中有一个通知事件时,例如“添加新频道”或“删除频道”(或可能的“用户添加/删除”),我收到以下onTurn错误:"error":"Cannot read property 'length' of undefined"
。通过查看代码,似乎应该归咎于欢迎消息代码。唯一的length属性是context.activity.member Leicester,因此必须引起该问题。但是我不知道到底发生了什么。根据以下声明,该事件必须触发一个ConversationUpdate活动,但不具有Memberwego属性。任何人都可以了解团队正在触发的活动是什么,以及我应该在此欢迎消息语句中添加哪些内容,以防止发生错误消息?为了明确起见,错误消息是在团队/渠道的“发布”渠道中出现的,例如渠道删除消息之类的事件即将到来。
代码部分:
} else if (context.activity.type === ActivityTypes.ConversationUpdate) {
// Handle ConversationUpdate activity type, which is used to indicates new members add to
// the conversation.
// see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
// Do we have any new members added to the conversation?
if (context.activity.membersAdded.length !== 0) {
// Iterate over all new members added to the conversation
for (var idx in context.activity.membersAdded) {
// Greet anyone that was not the target (recipient) of this message
// the 'bot' is the recipient for events from the channel,
// context.activity.membersAdded == context.activity.recipient.Id indicates the
// bot was added to the conversation.
if (context.activity.membersAdded[idx].id === context.activity.recipient.id) {
// Welcome user.
await context.sendActivity('Hi! I\'m the IT Innovation Bot. I can answer questions about the innovation team and capture your innovation ideas. Let me know how I can help!')
}
}
}
}
答案 0 :(得分:3)
对于任何类型为ConversationUpdate的活动,这似乎都将失败,但是JSON有效负载中不包含Member Transactions对象。这些事件的列表可以在这里找到:
您可以通过触发一个非会员的Attached事件来对此进行测试(例如,向团队添加新渠道或删除成员)。您可能可以通过对Member Transactions对象进行空检查来解决此问题。