- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在将 Microsoft 团队机器人与 Node.js 一起使用。我正在渲染自适应卡的轮播,并在每张卡上执行操作。我的要求是删除单击该操作的单个卡片。是否可以?
当前代码如下所示。我尝试过删除事件,但这会删除整个轮播
const {
TurnContext,
TeamsActivityHandler,
CardFactory,
AttachmentLayoutTypes,
ActionTypes
} = require('botbuilder');
class TeamsConversationBot extends TeamsActivityHandler {
constructor() {
super();
this.onMessage(async (context:any, next:any) => {
TurnContext.removeRecipientMention(context.activity);
console.log("context activigty at the begin is:" + JSON.stringify(context.activity))
let msg = context.activity.text
let action = context.activity.value
if(msg.startsWith('lead')){
msg = 'lead'
}
if(action !== undefined){
console.log("user did some action on a card")
msg = action.action
}
switch (msg) {
case 'lead':
await this.lead(context)
break;
case 'qualify_lead':
await this.qualifyLead(context)
break;
}
await next();
});
}
/**
*
* @param context this method does a lead qualification
*/
async qualifyLead(context:any){
console.log("in qualifyLead:" + JSON.stringify(context.activity))
//await context.deleteActivity(context.activity.replyToId)
const leadId = context.activity.value.objectId
console.log("Lead to qualify is:" + leadId)
await context.sendActivity('Lead is qualified')
}
/**
* Search contact by name
* @param context
* @param keyword
*/
async lead(context:any){
console.log("Start of lead with context:" + JSON.stringify(context))
const cardArr = []
let items = [
{"Name": 'x', "LeadId": "1"},
{"Name": 'a', "LeadId": "2"},
{"Name": 'b', "LeadId": "3"},
{"Name": 'c', "LeadId": "4"},
{"Name": 'd', "LeadId": "5"}
]
for(const item of items){
const header = {
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": item.Name
}
const actions = [
{
"type": "Action.Submit",
"title": "Qualify",
"data": { "action" : "qualify_lead", "objectId" : item.LeadId }
}
]
const acard = CardFactory.adaptiveCard(
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
header,
''
],
"actions": actions
}
)
cardArr.push(acard)
console.log("payload is::::" + JSON.stringify(acard))
}
const reply = {
"attachments" : cardArr,
"attachmentLayout" : AttachmentLayoutTypes.Carousel
}
await context.sendActivity(reply);
}
}
module.exports.TeamsConversationBot = TeamsConversationBot;
最佳答案
与this other answer一样,答案将类似于 this one 。我可以看到您正在尝试使用 TypeScript,但您的代码与 JavaScript 的偏差很小,因此我将用 JavaScript 编写我的答案。
First, you'll need a way of saving state for your [carousel] so you can update the [carousel]'s activity.
this.carouselState = this.conversationState.createProperty('carouselState');
You'll want a consistent way to generate your [carousel] that you can use when you send the [carousel] initially and when you update the [carousel].
createCarousel(batchId, leads)
{
const cardArr = [];
let items = [
{ "Name": 'x', "LeadId": 1 },
{ "Name": 'a', "LeadId": 2 },
{ "Name": 'b', "LeadId": 3 },
{ "Name": 'c', "LeadId": 4 },
{ "Name": 'd', "LeadId": 5 }
];
items = items.filter(item => leads.includes(item.LeadId));
for (const item of items) {
const header = {
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": item.Name
};
const actions = [
{
"type": "Action.Submit",
"title": "Qualify",
"data": { [KEYACTION]: ACTIONQUALIFYLEAD, [KEYOBJECTID]: item.LeadId, [KEYBATCHID]: batchId }
}
];
const acard = CardFactory.adaptiveCard(
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
header
],
"actions": actions
}
);
cardArr.push(acard);
}
return {
"type": "message",
"attachments": cardArr,
"attachmentLayout": AttachmentLayoutTypes.Carousel
};
}
这与您的代码类似,但有一些重要的区别。首先,我过滤项目数组以允许更少的项目,这就是您最终从轮播中删除卡片的方式。其次,我在每个操作的数据中包含一个“批处理 ID”,这样您的机器人在收到操作的有效负载时就会知道要更新哪个事件。另外,这与您的问题无关,但我在大多数地方都使用字符串常量而不是字符串文字,我希望多次使用该字符串,这是我遵循的做法,以避免与拼写错误相关的错误等。
Using this function, you can send the [carousel] initially like this
async testCarousel(turnContext) {
const batchId = Date.now();
const leads = [1, 2, 3, 4, 5];
const reply = this.createCarousel(batchId, leads);
const response = await turnContext.sendActivity(reply);
const dict = await this.carouselState.get(turnContext, {});
dict[batchId] = {
[KEYACTIVITYID]: response.id,
[KEYLEADS]: leads
};
}
And you can update the [carousel] in response to the card's [qualify] submit action like this
async handleSubmitAction(turnContext) {
const value = turnContext.activity.value;
switch (value[KEYACTION]) {
case ACTIONQUALIFYLEAD:
const dict = await this.carouselState.get(turnContext, {});
const batchId = value[KEYBATCHID];
const info = dict[batchId];
if (info) {
const leads = info[KEYLEADS];
const objectId = value[KEYOBJECTID];
var index = leads.indexOf(objectId);
if (index !== -1) leads.splice(index, 1);
const update = this.createCarousel(batchId, leads);
update.id = info[KEYACTIVITYID];
if (update.attachments.length) {
await turnContext.updateActivity(update);
} else {
await turnContext.deleteActivity(update.id);
}
}
break;
}
}
关于node.js - 微软团队机器人自适应卡片轮播删除卡片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59405348/
让我们开始吧,3 个类(Card、Start、Deckofcards) 1° 卡: public class Card { private String type; private i
我要创建一个二十一点游戏,我正在尝试弄清楚如何发牌并让它显示值和名称。我选择两个属性的原因纯粹是基于逻辑,当涉及到将 A 视为 1 或 11 时。还没有达到这一点,只是想如果有人想知道的话我会包括在内
我正在尝试使用 twitter 元标记(以及 Facebook 等其他网站的 Open Graph)创建 Twitter 卡片。当我看到来自其他人(例如 NPR 新闻)的推特提要时,卡片会默认展开。
我正在开发一个玩基本扑克游戏的程序,但这并不重要。我有一组 52 张牌,包含花色和等级。我想打印 4 行 13 行的值(花色和等级)。这可能是一个简单的问题,但我整天都在努力解决这个问题。因此,我非常
我开发了一个包含三列(两列相等,一列较小)的网格。我的问题是我无法在卡片上设置高度,我在 px 中使用了它们并且它起作用了,但这不是最好的方法。我希望这三列具有相同的高度(页面的 100%)并且一些卡
我在 4 个不同的列中开发了 4 个 Bootstrap 卡。在每张卡片中,我创建了一张包含某种类型信息的新卡片。 我的问题是,当我缩小屏幕尺寸(响应测试)时,文本会从卡片中溢出。我的问题是什么,我该
我怎样才能达到 固定高度 具有垂直可滚动 的 bootstrap 4 卡卡片文字部分? Card title This portion and
在我的程序中,我有一个大 Canvas ,我在其中提取多个选定区域并将这些区域绘制到单独的新小 Canvas 上。 我想使用此 API 将新创建的 Canvas 作为附件发布到 trello POST
我想在卡片 View 中显示联系信息,如果需要,应该调整卡片 View 的大小以包含所有信息。 这是布局部分: 但是 an
这是我的card_view。我已经提到了 card_view:cardElevation。但是仍然没有显示阴影。 我搜索了很多链接。他们在任何地方都提到要使用 card_view:cardElevat
我正在使用此处的框架 - cardsui 如何在卡片顶部添加分享按钮。我已经使用点击方法在 xml 中实现了它,但是当我按下它时应用程序崩溃并说该方法不存在(是的,我将该方法添加到主 java 文件中
我正在将 cardview 与 recycler view 一起使用。但早些时候我使用相同的代码来做事没有任何问题。但现在我正在使用 fragment 。现在我得到卡片 View 之间的距离更大。我的
我的卡片 View 设置如下: android:layout_marginTop="2dp" android:layout_marginLeft="6dp" android:layout_margin
我正在制作一个二十一点游戏,并创建了一个数组来充当用户发牌的手牌。我希望能够对其进行排序,以便手按数字顺序排序,这样可以更简单地确定用户的手的类型。这是我的卡片结构: struct ACard{
我希望在一个运行在 Wordpress 上的网站上实现 Twitter Cards(关于 Twitter Cards 的文档在这里:https://dev.twitter.com/docs/cards
我需要帮助解决这个难题。在 bootstrap 4.1 中使用卡片列和卡片时,当我不想这样做时,行会中断。我将列数设置为 4,当有 4 张卡片时,它看起来很完美。当添加第五张牌时,它会将行分成顶部的
我有一个 android ListView ,它显示类似卡片的 View ,正如您在这张图片中看到的,我的卡片之间有一条灰色细线: 我怎样才能摆脱灰线? 我实现这个卡片 View 的xml是这样的:
我正在尝试添加带有回收站 View 的卡片 View 。但它没有显示任何内容,只是一个空白 View 。 我在这里看到了这方面的问题,它有为回收站 View 和卡片 View 添加依赖项的答案。这出现
我在 android 中通过回收站 View 实现卡片 View ,但我的卡片 View 没有显示。我正在使用自定义适配器将数据填充到卡片 View 。我已经尝试了所有方法,但没有显示卡片 View
在我的应用程序中,我有一个卡片 View ,其中包含一个 TextView 和一个按钮,该按钮最初是隐藏的,当单击卡片 View 时,会显示该按钮。我不知道如何在显示按钮时将其设置为动画。任何人都可以
我是一名优秀的程序员,十分优秀!