您有几个选项可供您选择,但每个选项都有不同的限制。鉴于您的特定要求(即聊天中显示的图表),所有这些都是不完美的。您需要决定哪个最适合您。
1) 发送包含可点击链接的自适应卡片(或英雄卡片)(通过您的机器人) - 这将打开一个显示链接内容的单独选项卡/窗口。下面包含链接旁边的图标图像,但您可以包含指示图表/报告的完整图像。您可以尝试设计自适应卡片here。
async sendCardStep (stepContext) {
const adaptiveCard = {
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Power BI Report",
"size": "Large"
},
{
"type": "TextBlock",
"text": "Description of the report..."
},
{
"type": "Container",
"items": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "stretch",
"minHeight": "200px",
"id": "column1",
"items": [
{
"type": "Image",
"altText": "",
"url": "<<some link>>",
"height": "200px",
"width": "20px"
}
]
},
{
"type": "Column",
"width": "stretch",
"selectAction": {
"type": "Action.OpenUrl",
"id": "powerBIAction",
"title": "Click to Open",
"url": "<<some link>>"
},
"id": "colum2",
"style": "default",
"items": [
{
"type": "ActionSet",
"actions": [
{
"type": "Action.OpenUrl",
"title": "Click to Open",
"url": "<<some link>>",
"id": "openUrl"
}
]
}
],
"verticalContentAlignment": "Center"
}
],
"id": "columnSet",
"minHeight": "200px",
"horizontalAlignment": "Left"
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
}
const adaptiveMessage = CardFactory.adaptiveCard(adaptiveCard);
await context.sendActivity({attachments:[adaptiveMessage]});
}
2) 创建一个静态选项卡(通过您的 Teams 清单) - 这可以在选项卡中显示链接的内容。但是,这可能需要我缺乏的某种级别的身份验证。从技术上讲,这是因为该选项卡显示了访问内容所需的登录按钮。但是,我的登录按钮会快速打开和关闭浏览器窗口,而不允许实际登录该选项卡。不确定这是特定于我还是更大的问题(开发人员的控制台显示错误......可能是需要适当修复的错误)。有一个在浏览器中打开的按钮,当点击该按钮时,将在用户的浏览器中打开报告。您可以参考自定义标签文档here。
{
[...],
"staticTabs": [
{
"entityId": "powerBITab",
"name": "Power BI Report Tab",
"contentUrl": "<<some link>>",
"websiteUrl": "<<some link>>",
"scopes": [
"personal"
]
}
],
[...]
}
3) 创建任务模块(通过您的 Teams 清单和机器人) - 这类似于选项 #1。不同之处在于它成为您的机器人和团队的功能,而不是严格来说是您的机器人。换句话说,它可以从您的机器人访问,但响应团队中采取的某些操作(相对于从您的机器人发送的瀑布步骤或组件对话活动)。您可以参考任务模块文档here。
{
[...],
"composeExtensions": [
{
"botId": "613ed145-a6da-4412-9435-30ac5325c84e",
"commands": [
{
"id": "openPowerBI",
"type": "action",
"context": [
"compose"
],
"description": "Command to run action to open Power BI graph",
"title": "Open Power BI Report",
"fetchTask": true,
"taskInfo": {
"title": "Card title",
"width": "medium",
"height": "medium",
"url": "<<some link>>"
}
}
]
}
],
[...]
}
const { TeamsActivityHandler, CardFactory, MessageFactory } = require('botbuilder');
class TeamsMessagingExtensionsActionBot extends TeamsActivityHandler {
constructor() {
super();
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
this.onMessage(async (context, next) => {
const heroCard = this.getHeroCardMenu();
const heroMessage = MessageFactory.attachment(heroCard);
await context.sendActivity(heroMessage);
// By calling next() you ensure that the next BotHandler is run.
await next();
});
this.onMembersAdded(async (context, next) => {
const card = this.getGetHeroCardMenu();
const message = MessageFactory.attachment(card);
await context.sendActivity(message);
// By calling next() you ensure that the next BotHandler is run.
await next();
});
};
getHeroCardMenu() {
return CardFactory.heroCard('Open Power BI Report',
'Description of the report...',
null, // No images
[{ type: 'invoke', title: 'Click to Open', value: { type: 'task/fetch', data: 'adaptivecard' } }]);
}
handleTeamsTaskModuleFetch(context, taskModuleRequest) {
// taskModuleRequest.data can be checked to determine different paths.
return {
task: {
type: 'continue',
value: {
card: this.getTaskModuleAdaptiveCard(),
height: 220,
width: 400,
title: 'Adaptive Card: Inputs'
}
}
};
}
getTaskModuleAdaptiveCard() {
return CardFactory.adaptiveCard({
version: '1.0.0',
type: 'AdaptiveCard',
"body": [
{
"type": "TextBlock",
"text": "Power BI Report"
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.OpenUrl",
"title": "Click to Open",
"url": "<<some link>>",
"id": "powerBIAction",
"iconUrl": "<<some link>>"
}
]
}
]
});
}
}
module.exports.TeamsMessagingExtensionsActionBot = TeamsMessagingExtensionsActionBot;
4) 创建操作消息扩展(通过您的 Teams 清单) - 这将创建一个模式,其中嵌入了报告。目前,它遇到了与选项卡相同的问题,即显示报告登录按钮,但只闪烁打开一个立即关闭的浏览器窗口。同样,我不确定此错误是否特定于我。没有在浏览器中打开按钮选项。您可以参考消息扩展文档here。
const { TeamsActivityHandler } = require('botbuilder');
class TeamsMessagingExtensionsActionBot extends TeamsActivityHandler {
handleTeamsMessagingExtensionFetchTask(context, action) {
return {
task: {
type: 'continue',
value: {
width: 500,
height: 450,
title: 'Open Power BI Report',
url: '<<some link>>',
fallbackUrl: 'https://powerbi.microsoft.com/en-us/'
}
}
};
}
}
module.exports.TeamsMessagingExtensionsActionBot = TeamsMessagingExtensionsActionBot;
应用清单 - 最后,应用清单需要包含某些属性,您的 bot 或消息传递扩展程序才能与 Teams 充分配合。查看app manifest checklist,包括底部关于Submission extras for bots 的sn-p。也可以参考manifest schema。
希望有帮助!