通过聊天栏调用时我想要该应用程序
首先检查用户是否在“groupChat”或“channel”中。如果在“groupChat”中,它应该显示一张带有“仅限频道”信息的卡片。如果在“频道”中,它应该显示其他可用选项,即搜索查询和创建卡片的可能性......如何做到这一点?
我尝试过在appPackage中配置manifest.json:
...more code
"bots": [
{
"botId": "${{BOT_ID}}",
"scopes": ["team"],
"supportsFiles": false,
"isNotificationOnly": false,
"commandLists": [
{
"scopes": ["team"],
"commands": [
{
"title": "welcome",
"description": "Resend welcome card of this Bot"
},
{
"title": "learn",
"description": "Learn about Adaptive Card and Bot Command"
}
]
}
]
}
],
.... more code
也在index.js中添加代码:
server.post('/api/messages', async (req, res) => {
await adapter.process(req, res, async context => {
const conversationType = context.activity.conversation.conversationType
if (conversationType === 'groupChat') {
const card = cardTools.AdaptiveCards.declareWithoutData(rawOnlyChannel).render()
await context.sendActivity({ attachments: [CardFactory.adaptiveCard(card)] })
} else if (conversationType === 'channel') {
await bot.run(context)
} else {
await context.sendActivity('Unknown type of conversation')
}
})
})
我在文件夹adaptiveCards中创建新卡:
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.4",
"body": [
{
"type": "TextBlock",
"text": "No authority",
"wrap": true,
"horizontalAlignment": "Center",
"size": "Large",
"weight": "Bolder",
"color": "Attention"
},
{
"type": "TextBlock",
"text": "Operation only available on channels",
"wrap": true,
"fontType": "Default",
"horizontalAlignment": "Center",
"color": "Warning"
}
],
"verticalContentAlignment": "Center"
}
但我不仅在控制台中收到此类错误:
[onTurnError] unhandled error: Error: The bot is not part of the conversation roster.
RestError: The bot is not part of the conversation roster.
at new RestError (D:\...\node_modules\@azure\ms-rest-js\dist\msRest.node.js:2479:28)
at D:\...\bot\node_modules\@azure\ms-rest-js\dist\msRest.node.js:3644:37
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'BotNotInConversationRoster',
statusCode: 403,
request: WebResource {
streamResponseBody: false,
url: 'https://smba.trafficmanager.net/emea/v3/conversations/19%3A7990a50d-8507-4843-967c-c85c7bbbada2_8d058514-b4c4-415b-bf87-346bfcbaf116%40unq.gbl.spaces/activities/f%3A0711bd76-0c16-608b-ab24-b788a8fd0a31',
method: 'POST',
headers: HttpHeaders { _headersMap: [Object] },
body: '{"type":"message","serviceUrl":"https://smba.trafficmanager.net/emea/","channelId":"msteams","from":{"id":"28:2a7dc32d-240a-4a73-bfe3-01bb14a08089","name":"..."},"conversation":{"isGroup":true,"conversationType":"groupChat","id":"...","tenantId":"..."},"recipient":{"id":"...","name":"...","aadObjectId":"..."},"locale":"...","text":"The bot encountered an unhandled error:\\n The bot is not part of the conversation roster.","inputHint":"acceptingInput","replyToId":"f:0711bd76-0c16-608b-ab24-b788a8fd0a31"}',
query: undefined,
formData: undefined,
withCredentials: false,
abortSignal: undefined,
timeout: 0,
onUploadProgress: undefined,
onDownloadProgress: undefined,
proxySettings: undefined,
keepAlive: undefined,
agentSettings: undefined,
redirectLimit: undefined,
operationSpec: {
httpMethod: 'POST',
path: 'v3/conversations/{conversationId}/activities/{activityId}',
urlParameters: [Array],
headerParameters: [Array],
requestBody: [Object],
responses: [Object],
serializer: [Serializer]
}
},
response: {
body: '{"error":{"code":"BotNotInConversationRoster","message":"The bot is not part of the conversation roster."}}',
headers: HttpHeaders { _headersMap: [Object] },
status: 403
},
body: {
error: {
code: 'BotNotInConversationRoster',
message: 'The bot is not part of the conversation roster.'
}
}
}
这也没有按我的预期运行,机器人仅在用户选择选项卡或搜索的操作后进行检查。
我使用 vs code 中的工具团队创建应用程序。我正在使用:机器人、个人应用程序和消息传递扩展
我已经为此苦苦挣扎了几天,但无法找到解决方案,因此我请求一些指导,了解我做错了什么以及如何正确配置应用程序,以便在运行之前commandId 检查在用户交互之前首先检查它们是否在频道中....
您需要确保群聊或频道中安装了机器人。您可以通过在安装应用程序时将机器人添加到对话名册中来完成此操作。这可以使用“OnTeamsMessagingExtensionFetchTaskAsync”方法来完成,通过获取成员信息来检查应用程序是否已安装。如果机器人不在对话名册中,则调用“GetAddMissedBotCard”方法来添加机器人。
这是示例代码片段:
server.post('/api/messages', async (req, res) => {
await adapter.processActivity(req, res, async (context) => {
if (context.activity.type === 'conversationUpdate' && context.activity.membersAdded[0].id !== context.activity.recipient.id) {
const members = await TeamsInfo.getMembers(context);
const botIsInConversation = members.some(member => member.id === context.activity.recipient.id);
if (!botIsInConversation) {
const card = CardFactory.adaptiveCard(GetAddMissedBotCard());
await context.sendActivity({ attachments: [card] });
}
} else if (context.activity.type === 'message') {
const conversationType = context.activity.conversation.conversationType;
if (conversationType === 'groupChat') {
const card = cardTools.AdaptiveCards.declareWithoutData(rawOnlyChannel).render();
await context.sendActivity({ attachments: [CardFactory.adaptiveCard(card)] });
} else if (conversationType === 'channel') {
await bot.run(context);
} else {
await context.sendActivity('Unknown type of conversation');
}
}
});
});
在此代码中,当新成员添加到对话中时,它会检查机器人是否是对话的一部分。如果没有,它会发送一张带有安装按钮的自适应卡,以将机器人添加到对话中。一旦机器人成为对话的一部分,它就可以检查对话的类型并做出相应的响应。
此外,请确保在manifest.json 文件中正确配置机器人,并在“botId”字段中正确设置机器人的ID。 “范围”字段应包括“团队”和“群聊”,以允许机器人安装在团队和群聊中。 确保机器人安装在您正在测试的 Teams 客户端中。您可以通过以下方法执行此操作:转到 Teams 客户端,单击左侧边栏上的“应用程序”图标,搜索您的机器人,然后单击“添加”。
参考文档-https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/channel-and-group-conversations?tabs=dotnet#channel-and-group-chat-与机器人对话