1

I'm having a problem retrieving the activityID of a Choice prompt once the selection has been made within a waterfall dialog. Im currently making use of a Teams channel.

An example my code can be found below. In the step after the selection, if I have a look at the stepContext object(found further below), there is reference of an Activity.id, but this id is infact the Activity id for the current step. I'm sure I'm missing something simple, but cant figure it out.

async step1(step) {

    const choice1 =  await step.prompt(CHOICE_PROMPT, {

        prompt: 'Please select one of the following:',

        choices: ChoiceFactory.toChoices(['Option1', 'Option2', 'Option3'])

    });

   return choice1
}

async step2(step) {
    console.log(step)
    console.log("...........................................................................")

    return await step.prompt(NAME_PROMPT, 'Please insert your name')
} 

WaterfallStepContext {
  dialogs:
   DialogSet {
     dialogs:
      { NAME_PROMPT: [Object],
        CHOICE_PROMPT: [Object],
        CONFIRM_PROMPT: [Object],
        ATTACHMENT_PROMPT: [Object],
        WATERFALL_DIALOG: [Object] },
     dialogState: undefined },
  context:
   TurnContext {
     _respondedRef: { responded: false },
     _turnState:
      Map {
        Symbol(BotIdentity) => [Object],
        Symbol(ConnectorClient) => [Object],
        Symbol(OAuthScope) => 'https://api.botframework.com',
        'botCallbackHandler' => [AsyncFunction],
        Symbol(state) => [Object],
        Symbol(ActivityReceivedEmitted) => true },
     _onSendActivities: [],
     _onUpdateActivity: [],
     _onDeleteActivity: [],
     bufferedReplyActivities: [],
     _adapter:
      BotFrameworkAdapter {
        middleware: [Object],
        BotIdentityKey: Symbol(BotIdentity),
        OAuthScopeKey: Symbol(OAuthScope),
        ConnectorClientKey: Symbol(ConnectorClient),
        TokenApiClientCredentialsKey: Symbol(TokenApiClientCredentials),
        settings: [Object],
        credentials: [Object],
        credentialsProvider: [Object],
        isEmulatingOAuthCards: false,
        authConfiguration: [Object],
        turnError: [AsyncFunction] },
     _activity:
      { text: 'Option1',
        textFormat: 'plain',
        type: 'message',
        timestamp: 2020-05-05T13:32:42.187Z,
        localTimestamp: 2020-05-05T13:32:42.187Z,
        id: '1588685562137',
        channelId: 'msteams',
        serviceUrl: 'https://smba.trafficmanager.net/za/',
        from: [Object],
        conversation: [Object],
        recipient: [Object],
        entities: [Array],
        channelData: [Object],
        locale: 'en-US' } },
  stack: [ { id: 'WATERFALL_DIALOG', state: [Object] } ],
  state: DialogStateManager { dialogContext: [Circular] },
  _info:
   { index: 1,
     options: {},
     reason: 'endCalled',
     result: { value: 'Option1', index: 0, score: 1, synonym: 'Option1' },
     values: { instanceId: 'b5bef7ce-1c43-e1db-abc0-651ed2b5bb8f' },
     onNext: [Function: onNext] },
  parent:
   DialogContext {
     dialogs: DialogSet { dialogs: [Object], dialogState: [Object] },
     context:
      TurnContext {
        _respondedRef: [Object],
        _turnState: [Object],
        _onSendActivities: [],
        _onUpdateActivity: [],
        _onDeleteActivity: [],
        bufferedReplyActivities: [],
        _adapter: [Object],
        _activity: [Object] },
     stack: [ [Object] ],
Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
lefty23
  • 21
  • 1
  • Are you trying to get the activity that contains the card so you can update/delete it? – Kyle Delaney May 05 '20 at 17:08
  • Hi Kyle, yes, that's correct. – lefty23 May 05 '20 at 21:26
  • Thanks Kyle, I'll try and implement something similiar in the link that you've posted. The main reason for me wanting to update/delete the card is due to the card's button not disabling itself once selected on Android devices - On PC and IPhones, it works perfectly fine. – lefty23 May 06 '20 at 09:11
  • I've implemented the fix in the link you sent Kyle, and it's working - I can now update or delete the previous Activity Card, so thanks alot for that. There's a few seconds delay between the submit button being selected and the card updating\deleting, which give users an opportunity to hit the submit button more than once (on Android). Do you know of any other fixes or workarounds for this? Perhaps I should post a new Stackoverflow question? – lefty23 May 06 '20 at 14:18
  • Teams is supposed to disable a button until the request has finished processing. If this doesn't happen on Android, you should submit that to Teams as a bug. In the meantime you might be able to code your bot so that it recognizes the message as a duplicate, but that can be difficult to do. The Bot Framework is designed to allow the user to send messages while the bot is still processing a previous message. – Kyle Delaney May 06 '20 at 19:18

1 Answers1

0

You're not missing anything simple. This is actually sort of difficult to do because Microsoft Teams does not include any information about the button that sent an action to your bot.

In order to get the activity ID that an action came from, you have to save the ID in bot state on the turn that you send the activity. The ID can be found in the resource response returned by whichever method you use to send the activity. Unfortunately, this means you can't let the prompt send the card for you because then you wouldn't be able to access the resource response.

If you want to save more than one activity ID at a time, you'll need a way of knowing which one is associated with each incoming action. This means you'll have to include metadata in the actions you put in your cards and save that metadata along with the activity ID in your bot state.

If you'd like an easier or even an automatic way of doing all this, please voice your support for the cards library that I'm currently working on: https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/issues/137

Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66