简体   繁体   English

更新已在 javascript 的 Bot Framework v4 中发布 Adaptive Card

[英]Update already posted Adaptive Card in Bot Framework v4 in javascript

I am new to botframework and microsoft teams.我是 botframework 和微软团队的新手。 I am trying to build a bot that will post an adaptive card.我正在尝试构建一个将发布自适应卡的机器人。 On submit of the card i want to perform some action and update the existing card.在提交卡时,我想执行一些操作并更新现有卡。

I was able to create post an adaptive card in microsoft teams and when a user submit's an action, I am able to capture the data.我能够在微软团队中创建张贴自适应卡片,当用户提交操作时,我能够捕获数据。 The place where i am stuck in not able to get the update the existing card with a new card.我被困的地方无法用新卡更新现有卡。

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const {
    TurnContext,
    MessageFactory,
    TeamsInfo,
    TeamsActivityHandler,
    CardFactory,
    ActionTypes
} = require('botbuilder');

const TextEncoder = require('util').TextEncoder;


const WELCOME_TEXT = 'This bot will introduce you to Adaptive Cards. Type anything to see an Adaptive Card.';

var replyToID = "";

class AdaptiveCardsBot 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 replyText = `Echo: ${ context.activity.text }`;
            var txt = context.activity.text;
            var val = context.activity.value;
            

            if (!txt && val) {
                await this.sendUpdatedCard(context);
            } else
            {
                const sampleCard = require('./resources/adaptiveSample.json');
                console.log (JSON.stringify(context.activity));
                console.log ("---------------------");
                console.log ("---------------------");
                //console.log("Core ID" + context.activity.replyToId);
                var reply = await context.sendActivity(
                    {
                        text: 'Here is an Adaptive Card:',
                        attachments: [CardFactory.adaptiveCard(sampleCard)]
                    });
                
                console.log (JSON.stringify(reply));
                console.log ("---------------------");
                console.log ("---------------------");
                replyToID = reply.id;
                var reference = TurnContext.getReplyConversationReference(context.activity, reply)
                replyToID = reference.activityId;       
                
            }
            // By calling next() you ensure that the next BotHandler is run.
            await next();
        });

        this.onMembersAdded(async (context, next) => {
            const membersAdded = context.activity.membersAdded;
            for (let cnt = 0; cnt < membersAdded.length; ++cnt) {
                if (membersAdded[cnt].id !== context.activity.recipient.id) {
                    await context.sendActivity(`Welcome to Adaptive Cards Bot  ${ membersAdded[cnt].name }. ${ WELCOME_TEXT }`);
                }
            }
            // By calling next() you ensure that the next BotHandler is run.
            await next();
        });
    }
    async sendUpdatedCard(context)
        {
            const data = context.activity.value;
            console.log("Call Submit to Asana");
            console.log (JSON.stringify(context.activity));
            console.log ("---------------------");
            console.log ("---------------------");
            console.log ("replyToID :" + replyToID);
            const returnCard = require('./resources/returnSample.json');

            const card2 = CardFactory.adaptiveCard(returnCard);
            card2.id = replyToID;
            const newActivity = MessageFactory.attachment(card2);
            newActivity.id = replyToID;
            newActivity.type = "message";
            await context.updateActivity(newActivity);
        }
}


// await context.sendActivity({
//     text: 'Here is a return card',
//     attachments: [CardFactory.adaptiveCard(returnCard)]
// });
//const newActivity = MessageFactory.attachment(CardFactory.adaptiveCard(returnCard));
module.exports.AdaptiveCardsBot = AdaptiveCardsBot;


Any help would be greatly appreciated.任何帮助将不胜感激。

Attached image of the emulator附上模拟器图片在此处输入图像描述

@Pawan Please go through Updating Bot Messages . @Pawan 请通过更新机器人消息go 。 Here is a sample code in Node to update an already existing card with a new card on button click.这是Node 中的示例代码,用于在单击按钮时使用新卡更新现有卡。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 机器人框架 V4 订阅以接收 Javascript 上的对话 ID - Bot framework V4 Subscribe to receive conversation Id on Javascript Microsoft bot 框架 v4 作为最小化 window 嵌入到带有 javascript 的网站中 - Microsoft bot framework v4 embed as minimizable window in website with javascript 如何在 C# 中使用 Microsoft Bot Framework SDK V4 开发的 ChatBot 中添加条件 w.r.t 自适应卡片? - How to add conditions w.r.t Adaptive cards in ChatBot developed using Microsoft Bot Framework SDK V4 in C#? BotFramework V4 nodejs 中的自适应卡片(用户输入表单)在用户提交后得到重新提示 - Adaptive card(user input form) in BotFramework V4 nodejs gets reprompted after user submit bot框架网络聊天v4中的字体自定义 - Font Customization in bot framework web chat v4 在回调中使用await(Microsoft Bot Framework v4 nodejs) - use await inside callback (Microsoft Bot Framework v4 nodejs) 如何在Bot Framework v4中实施触发动作? - How to implement trigger action in bot framework v4? Bot Framework v4 - 发起与用户的聊天(主动消息) - Bot Framework v4 - initiate chat with a user ( proactive messages ) Bot Framework V4 - 类型错误:无法在已撤销的代理上执行“获取” - Bot Framework V4 - TypeError: Cannot perform 'get' on a proxy that has been revoked Bot Framework(v4)-如何从自定义提示验证中获取状态 - Bot framework (v4) - How to get state from custom prompt validation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM