使用Node.js的团队的Microsoft机器人在更新相同活动时失败,缺少活动ID [英] microsoft bots to teams using nodejs fails with missing activityid when updating the same activity

查看:70
本文介绍了使用Node.js的团队的Microsoft机器人在更新相同活动时失败,缺少活动ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有一个简单的卡片轮播,其中有如下操作按钮:

My code has a simple card carousel which has action button like below:


 actions = [
        {
            "type": "Action.Submit",
            "title": "Qualify",
            "data": { "action" : "qualify_lead" }
        },
        {
            "type": "Action.OpenUrl",
            "title": "Retire",
            "url": "{viewUrl}"
        },
        {
            "type": "Action.ShowCard",
            "title": "Add Note",
            "card":   this.noteCard(item.LeadId, "leads")
        }
       ]

我有一种方法来处理qualify_lead动作,如下所示

I am having a method to handle qualify_lead action like below

async qualifyLead(context:any){
        console.log("in qualifyLead:" + JSON.stringify(context.activity))
        await context.updateActivity(this.successCard('Lead is qualified'))
    }

我所要做的只是用一条简单的短信替换整个轮播.但是它失败并显示错误:

All I am doing on purpose is to replace entire carousel with a simple text message. But it fails with error:

错误:BotFrameworkAdapter.updateActivity():缺少activity.id

Error: BotFrameworkAdapter.updateActivity(): missing activity.id

我在哪里得到的?

我正在为此使用google firebase,并且包装器代码如下

I am using google firebase for this and the wrapper code is like below

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

class TeamsConversationBot extends TeamsActivityHandler {
    constructor() {
        super();
        this.leadState = 
          this.conversationState.createProperty('leadCarouselState');

        this.onMessage(async (context:any, next:any) => {
            TurnContext.removeRecipientMention(context.activity);
            let msg = context.activity.text
            const action = context.activity.value
            let objNum = ''
            let keyword = ''


            if(msg === undefined && action === undefined)
                msg  = 'help'
            else if(msg !== undefined){
                msg = msg.trim().toLowerCase()
                if(msg.indexOf("help") > -1)
                    msg = 'help'
                else{

                   if(msg.startsWith('lead')){

                        msg = 'lead'
                    } 
                }
            }

            switch (msg) {
                case 'lead':
                        await this.lead(context, userKey, platform)
                        break;
                case 'qualify_lead':
                        await this.qualifyLead(context)
                        break;
            }
            await next();
        });
    }

推荐答案

正如我在我对您的其他问题的回答中所述,您需要将活动ID保存为漫游器状态,然后将其应用于要发送的更新. Bot Framework无法更新活动,除非您告诉它要更新的活动,并使用活动ID进行操作.

As I explained in my answer to your other question, you need to save the activity ID in bot state and then apply it to the update that you're sending. The Bot Framework can't update an activity unless you tell it which activity to update, and you do that using an activity ID.

这是保存ID的部分:

const dict = await this.carouselState.get(turnContext, {});

dict[batchId] = {
    [KEYACTIVITYID]: response.id,
    [KEYLEADS]: leads
};

这是将其应用于更新后的活动的部分:

And this was the part that applies it to the updated activity:

            const update = this.createCarousel(batchId, leads);
            update.id = info[KEYACTIVITYID];

这篇关于使用Node.js的团队的Microsoft机器人在更新相同活动时失败,缺少活动ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆