SOLVED

Getting a past activity's card attachment

Brass Contributor

Hi,

Our parent bot displays an adaptive card with a submit button.  When the user clicks on the submit button, a skill dialog bot's skill is invoked.  When the parent bot invokes a skill, sometimes the skill bot does not complete the invocation and nothing gets returned to the parent.  When the user tries the card again, the action ends up with the skill dialog bot because control was not returned to the parent.  

 

In the following code snippet, our skill dialog bot's processActivity is routing processing logic based on the ActivityType

 

    async processActivity(stepContext) {
        const activity = stepContext.context.activity;
        switch (activity.type) {
            case ActivityTypes.Event:
                return await this.onEventActivity(stepContext);
			default:
				// We didn't get an event name we can handle.
				await stepContext.context.sendActivity(
					`Unrecognized EventName: "${ stepContext.context.activity.name }".`,
					undefined,
					InputHints.IgnoringInput
				);
				return { status: DialogTurnStatus.complete };
			}
        }
    }

When the control is stuck with the skill dialog bot, we see the 'Unrecognized Eventname' in our logs.  To remediate this, we replaced the default section with the following

            default:
                return await stepContext.context.sendActivity({
                    type: ActivityTypes.EndOfConversation,
                    code: EndOfConversationCodes.CompletedSuccessfully,
                    value: {
                        action: 'abort',
                        conversationId: activity.conversationId,
                        activityId: activity.activityId
                    }
                });

Our parent bot has a finalStep that processes the results returned from the skill dialog bot.  

if (stepContext.result.action === 'abort') {
                    console.log('ooops, skil dialog bot encountered an error and triggered an abort')
                    await stepContext.context.sendActivity('I am sorry but looks like one of my skills encountered an error.  Can you try again?')
                } 

Instead of displaying a separate message to the user, we were hoping there would be a way to retrieve the card attachment of the activity the user acted on so that we can append the "retry" message to the card.

Does anyone know if we can retrieve a past activity in a conversation based on an activity Id? 

Thank You

3 Replies

Hi @voonsionglum, yes it is possible to retrieve the ID of the past activity conversation and can also update the activity using UpdateActivityAsync method. Could you please have a look at this sample code.

@Mallipriya_MSFT Thanks for the response.  We want to retrieve the actual card body of a previous activity.  With a given activity Id, do you know if we can get the content that was sent for that activity?  We would like to be able to amend the content of a previous activity (especially when the activity is sending a card) so that we can add in error messages if something went wrong with the bot.  

 

It would be like how cards show the "Unable to reach app" red text message on adaptive cards when submit actions for cards are unable to complete when the corresponding web app is down.

best response confirmed by voonsionglum (Brass Contributor)
Solution

Hi @voonsionglum, To retrieve the actual card body of a previous activity, there is no direct way to achieve it. Rather, you can try using messageID/ Conversation ID (we get in TurnContext object), build the conversation reference and save it in Azure Table Storage or Azure Blob Storage and update the previously posted card using updateActivityAsync method.  

1 best response

Accepted Solutions
best response confirmed by voonsionglum (Brass Contributor)
Solution

Hi @voonsionglum, To retrieve the actual card body of a previous activity, there is no direct way to achieve it. Rather, you can try using messageID/ Conversation ID (we get in TurnContext object), build the conversation reference and save it in Azure Table Storage or Azure Blob Storage and update the previously posted card using updateActivityAsync method.  

View solution in original post