【问题标题】:Unable to render bot framework prompt in slack using interactive messages无法使用交互式消息在 slack 中呈现机器人框架提示
【发布时间】:2019-06-20 18:39:53
【问题描述】:

我正在尝试使用 Slack 的交互式消息为部分和按钮发布 slack 块套件 JSON。但是我收到一条错误消息,提示 Invalid ChannelData

我尝试通过 slack api 测试器发布块 JSON,它可以工作,但不能通过我编写的代码。我写了一些自定义代码来覆盖bot框架中专门针对slack频道的提示功能。

覆盖提示

   public async prompt(stepContext: WaterfallStepContext, dialogId: string, options: PromptOptions): Promise<DialogTurnResult> {

        let promptText: string = '';
        if (isString(options.prompt)) {
            promptText = options.prompt;
        } else if (isActivity(options.prompt)) {
            promptText = options.prompt.text;
        }
        this.logger.log(`prompt: ${promptText}`);

        const choices = options.choices.map((choice) => {
            let text = '';
            this.logger.log(`choice: ${choice}`);
            if (isString(choice)) {
                text = choice;
            } else if (isChoice(choice)) {
                text = choice.value;
            }
            // return { name: text, type: 'button', text: text, value: text };
            return {
                type: 'button',
                text: {
                    type: "plain_text",
                    text: text
                },
                value: text
            };
        });

        const channelData = {
            text: '',
            blocks: [
                {
                    type: "section",
                    text:
                        {
                            type: "mrkdwn",
                            text: "Are you using a Mac or PC?"
                        }
                },
                {
                    type: "actions",
                    elements: choices
                }]
        };
        this.logger.log(`channelData: ${JSON.stringify(channelData)}`);

        return await stepContext.prompt('ChoicePrompt', { type: ActivityTypes.Message, channelData: channelData });
    }

辅助函数:

function isString(str: any): str is string {
    return typeof str === 'string';
}

function isActivity(obj: any): obj is Activity {
    return obj && obj.text !== undefined;
}

function isChoice(obj: any): obj is Choice {
    return obj && obj.value !== undefined;
}

调用:

const channel = getChannel(step.context);
        return await channel.prompt(step, 'ChoicePrompt', {
            choices: buttons,
            prompt: this.generateAssetInfoMessage(deviceType),
            retryPrompt: `Sorry, I didn't understand. Please choose one of the following:`,
        });

我希望看到带有两个按钮的消息,但我收到一条错误消息 [onTurnError]:错误:无效的 ChannelData 这是字符串化的通道数据

{"text":"","blocks":[{"type":"section","text":{"type":"mrkdwn","text":"Are you using a Mac or PC?"}},{"type":"actions","elements":[{"type":"button","text":{"type":"plain_text","text":"I'm using a Mac"},"value":"I'm using a Mac"},{"type":"button","text":{"type":"plain_text","text":"I'm using Windows"},"value":"I'm using Windows"}]}]}

【问题讨论】:

    标签: typescript botframework slack-api


    【解决方案1】:

    很遗憾,您并没有做错任何事。我们只是还不支持它。

    我已经提交了Design Change Request,以便我们可以将负载从channelData 映射到适当的 Slack API。 在本地也无能为力,因为这依赖于 API 的私有/安全部分。

    但是请注意,一旦实现,您可能会将其添加到您的消息的channelData 中,如下所示:

    "channelData": {
       "text": "Now back in stock! :tada:",
       "blocks": [
            [...]
       ]
    

    编辑:可以在本地执行此操作,但这会很困难,因为您无法直接使用 Bot Framework 执行此操作。你必须在你的机器人内部使用Slack's Conversation API。有可能,您将拥有所需的所有数据,但需要新的身份验证令牌。

    【讨论】:

    • 我目前正在尝试使用 slack 适配器作为解决方法,因此希望这会奏效。测试一下。我敢肯定,您对所有事情都有一个流程,但只是问...设计更改 ETA 是什么样的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    • 2018-06-05
    • 2020-12-08
    • 1970-01-01
    • 2016-12-26
    • 2015-03-25
    相关资源
    最近更新 更多