botframework - Search Message Extension 的 Select Item 事件上的自适应卡片
问题描述
在搜索消息扩展中选择搜索结果时,我正在尝试返回自适应卡片。以下是我退卡的课程:
import { IEntity } from '../model/IEntity';
import { Attachment, CardFactory } from "botbuilder";
export class AccountResultCard {
public static getCard(account: IEntity): Attachment {
// Get map
let logo = `https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg`;
let url = `https://pbs.twimg.com/docs/test.aspx?GoPage=AccountCard.aspx?AccountID='${account.ID}'&_Division_='${account.Division}'`;
const accountDetail = account.Code ? account.Code + ' - ' + account.Description : '';
const accountcontextinfo1 = account.ContextInfo[1] ? account.ContextInfo[1] : '';
const accountcontextinfo2 = account.ContextInfo[3] ? account.ContextInfo[3] + ' '+ account.ContextInfo[2] : '';
const card = CardFactory.adaptiveCard(
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Large",
"weight": "Bolder",
"text": "Title"
},
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": accountDetail
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": accountcontextinfo1,
"wrap": true
},
{
"type": "TextBlock",
"spacing": "None",
"text": accountcontextinfo2,
"wrap": true
},
{
"type": "TextBlock",
"spacing": "None",
"text": "Missing state and country",
"wrap": true
}
],
"width": "stretch"
},
{
"type": "Column",
"items": [
{
"type": "Image",
"style": "Person",
"url": logo,
"size": "Small"
}
],
"width": "auto"
}
]
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Open in Aurora",
"url": url,
"width": "Small",
"style": "default"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2"
}
);
return card;
}
}
以下是我的选择项目事件:
public async handleTeamsMessagingExtensionSelectItem(
context: TurnContext,
obj: any
): Promise<any> {
const item = this.response.find(e => e.ID == obj.name);
return {
composeExtension: {
type: "result",
attachmentLayout: "list",
attachments: [AccountResultCard.getCard(item)],
},
};
}
但它永远不会返回任何东西。我从 get card 中删除了所有内容,只发送了一个带有硬编码值的文本块。那也没用。你们能建议我哪里做错了吗?
解决方案
通过将代码更改为,我能够在 SelectItem 事件中发送自适应卡:
return {
composeExtension: {
type: "result",
attachmentLayout: "list",
attachments: [{preview: CardFactory.heroCard("title", ""),
...yourAdaptiveCard}],
},
};
这已经回答here。
推荐阅读
- spring-security - 如何为 spring webflux 应用程序配置 oauth2 资源服务器?
- ruby-on-rails - Gem::LoadError: 加载“sqlite3”Active Record 适配器时出错
- android - 在 Android 应用程序中使用 Google 表单
- javascript - 如何告诉 Webpack 什么都不输出?
- python - 如何使用 np.where 检查行级别的条件
- javascript - 如何在 VueJS test-utils parentComponent 中模拟 Vuex 商店
- ios - UIBezierpaths 没有在它们被绘制的地方绘制
- apache - 无法在 apache2 中创建 .htaccess 文件
- dart - 调用 Process.run 时如何加载 .bash_profile?
- python - pubnub asyncio 不发布数据