0
votes

Iam working on Bot framework chatbot on msteams channel. In the waterfall dialogs, As a requirement in Adaptive cards i need to retain its values( in INPUT.text)in msteams once submit button is clicked. But msteams doesnt retain the values. As a workaround i tried to add the adaptive card in ActivityPrompt and when user clicks on submit button activityprompt validation ensures new values are send as an update activity in the old card.

Below code explains how i used ActivityPrompt in the waterfall step.

  async W2_showCard(step) {  //in the waterfall step
        const card = CardFactory.adaptiveCard(Json_adaptivecard);
        return await step.prompt('formPrompt', { prompt: MessageFactory.attachment(card) });
    }
.addDialog(new ActivityPrompt('formPrompt', async prompt => { // validation involved in activityprompt

            const recognizedValue = prompt.recognized.value;
            console.log(prompt.recognized.value)
            if (recognizedValue.type =='message') {
                if (recognizedValue.value) {
                   
                    const replyToId = recognizedValue.replyToId;

                    var oldCard = prompt.options.prompt.attachments[0];
                    console.log(oldCard)
                    var validated = true;
                    
                    for(let i=0;i<oldCard.content.body[0].columns[0].items.length;++i){// replace values
                      
                         if(oldCard.content.body[0].columns[0].items[i].type=="Input.Text"){
                              // preserve the user input
                            const newValue = 
                             recognizedValue.value[oldCard.content.body[0].columns[0].items[i].id];
                            oldCard.content.body[0].columns[0].items[i].placeholder = newValue;
                            
                          
                         }
                     }
                    
                    // update the card
                    const activity = prompt.context.activity;
                    
                    activity.attachments = [oldCard];// issue due to attachment Multiple skyp act error.
                    activity.id = replyToId;
                   
                    await prompt.context.updateActivity(activity); // issue is here

                    if (validated) {
                        // this is to make input available in next waterfall step
                        prompt.recognized.value = recognizedValue.value;
                        return true;
                    } else {
                        await prompt.context.sendActivity(`Please check the form. Some values are missing`);
                    }
                } else {
                    await prompt.context.sendActivity(`Please fill out form and press *"submit"* button or type *"cancel"* to stop.`);
                }

            }
            return false;

        }))

My issue is the updateactivity gives the ERROR: Activity resulted into multiple skype activities. On analyzing i was able to pinpoint the error to activity.attachment=[oldcard].

Is there any way to add attachment to text activity without having that error? Or why is prompt.context.activity a text activity instead of an attachment,clearly iam sending an attachment in the activityprompt in the waterfallstep

Any help would be much appreciated.

1
Thank you for reaching out to us We will investigate and if we require further information we will reach out. Best regards, Teams Platform - Trinetra-MSFT
Can you take a look at this Github - Trinetra-MSFT
Is my answer acceptable? (Since there are multiple other people in this thread, you will need to @ mention me if you want me to see your reply.) - Kyle Delaney

1 Answers

1
votes

You've mostly got the right idea, but you should never use an incoming activity as an outgoing activity. prompt.context will be the turn context, so prompt.context.activity will be the incoming user-to-bot activity rather than the activity your bot sent in the prompt. Instead of trying to update the prompt activity with the incoming activity, you should modify the prompt activity directly. It seems you've already figured out how to access that activity in another part of your code with prompt.options.prompt so it's unclear why you're not doing it that way consistently.

I also want to note that you may want to set the text inputs' values instead of their placeholders, but placeholders are fine if that's your intention.

You might be interested in an upcoming package called the cards library. You can voice your support for it here to get it released sooner: https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/issues/137