LUIS 聊天机器人与 Power BI 的集成

LUIS chatbot integration with Power BI

是否有任何方法可以通过 API 调用从 Power BI 获取图表?我发现 Power BI API 调用返回了嵌入 URL,但是有什么方法可以发送这个嵌入 URL 并在聊天机器人(Skype 或团队)中显示图表或报告?

您有几个选项可供选择,但每个选项都有不同的限制。鉴于您的特定要求(即聊天中显示的图表),所有这些都不完美。您需要决定哪个最适合您。

1) 发送包含可点击 link 的自适应卡片(或英雄卡片)(通过您的机器人) - 这将打开一个单独的 tab/window 显示 linked 内容。下面包括 link 旁边的图标图像,但您可以包括指示 graph/report 的完整图像。您可以尝试设计自适应卡片 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 清单) - 这可以在选项卡中显示 linked 内容。但是,这可能需要某种程度的身份验证,而我却缺少这种身份验证。从技术上讲,这是可行的,因为选项卡显示了访问内容所需的登录按钮。但是,我的登录按钮可以快速打开和关闭浏览器 window,而不允许选项卡发生实际登录。不确定这是我特有的还是更大的问题(开发人员的控制台显示错误...可能是需要适当修复的错误)。有一个在浏览器中打开按钮,单击该按钮后, 在用户浏览器中打开报表。您可以参考自定义标签文档 here.

{
  [...],
  "staticTabs": [
    {
      "entityId": "powerBITab",
      "name": "Power BI Report Tab",
      "contentUrl": "<<some link>>",
      "websiteUrl": "<<some link>>",
      "scopes": [
        "personal"
      ]
    }
  ],
  [...]
}

3) 创建任务模块(通过您的 Teams 清单和机器人) - 这类似于选项 #1。不同之处在于它成为您的机器人和团队的功能,而不是严格意义上的您的机器人。换句话说,它可以从你的 bot 访问,但要响应 Teams 中采取的某些操作(相对于从你的 bot 发送的瀑布步骤或组件对话框 activity)。您可以参考任务模块文档 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 清单) - 这将创建一个模式,其中嵌入了报告。目前,它遇到了与选项卡相同的问题,即它显示了报告登录按钮,但仅闪烁打开浏览器 window 并立即关闭。同样,我不确定此错误是否是我特有的。没有在浏览器中打开按钮选项。您可以参考消息扩展文档 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;

应用程序清单 - 最后,应用程序清单需要包含某些属性,您的机器人或消息传递扩展才能与 Teams 充分协作。看看app manifest checklist, including the snippet at the bottom regarding Submission extras for bots. Always good to reference the manifest schema,还有。

希望得到帮助!

我找到了解决问题的方法。我将其张贴在这里,以便其他人可以获得这些知识。 没错,Microsoft bot 框架目前不支持 Power BI 的交互式图表或嵌入式图表,因此要在 bot 上显示 charts/graphs 我们可以使用图表 APIs。图表 APIs return 我们图表图像作为对我们请求 URL 的响应。示例代码:

在上述代码的结果中,我得到输出:

目前查到的ChartAPI服务很少,但都是付费服务。

  1. QuickChart

  2. ChartURL

  3. ImageChart

希望此解决方案对您有所帮助。