0

I'm assembling a bot using the sample code of BotFramework v4.
I'm trying to receive a value using an AdaptiveCard, but I can't receive a value.

Currently, AdaptiveCard can be sent. An error occurs when you press Submit.
AddressjsonAsync finishes successfully and sends an AdaptiveCard.
However, there is a problem with the subsequent AddressAsync.

The following error occurs:

[OnTurnError] unhandled error: Object reference not set to an instance of an object.System.NullReferenceException: Object reference not set to an instance of an object.

I went to various sites and tried various solutions, but it was no good.
I don't know what caused it, nor what value it returned.
I want to get the result from AdaptiveCard somehow.
I want you to tell me what to do.
Please help me.

Language: C#
Framework: BotFramework v4

AdaptiveCard

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "body": [
    {
      "type": "Container",
      "items": [
        {
          "type": "Input.ChoiceSet",
          "placeholder": "Placeholder text",
          "choices": [
            {
              "title": "aaa",
              "value": "aaa@address.jp"
            },
            {
              "title": "bbb",
              "value": "bbb@address.jp"
            }
          ],
          "style": "expanded",
          "spacing": "None",
          "id": "Address",
          "isMultiSelect": true
        }
      ]
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "title": "OK",
      "data": { "Address": "Address" }
    }
  ]
}

MainDialog

    private static async Task<DialogTurnResult> AddressjsonAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
        var tokenResponse = (FoundChoice)stepContext.Result;
        if (tokenResponse != null)
        {
            var adaptiveCardJson = File.ReadAllText("./AdaptiveJsons/toaddres_adaptivecard.json");
            var adaptiveCardAttachment = new Attachment()
            {
                ContentType = "application/vnd.microsoft.card.adaptive",
                Content = JsonConvert.DeserializeObject(adaptiveCardJson),
            };
            var reply = stepContext.Context.Activity.CreateReply();
            reply.Attachments = new List<Attachment>() { adaptiveCardAttachment };
            return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = reply }, cancellationToken);
        }
        await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken);
        return await stepContext.EndDialogAsync();

    }

    private async Task<DialogTurnResult> AddressAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {

        var input = JsonConvert.DeserializeObject<Address>(stepContext.Context.Activity.Value.ToString());

        stepContext.Values["address"] = input.Address[0];

        return await stepContext.BeginDialogAsync(nameof(OAuthPrompt), null, cancellationToken);
    }

` Address

using System;
using System.Collections.Generic;

public class Address
{
    public List<string> Address { get; set; }

}
Mikhail Zhuikov
  • 1,213
  • 2
  • 9
  • 19
stkhr
  • 71
  • 1
  • 12

1 Answers1

0

I flagged this as a duplicate because I've answered this too many times. For you, specifically, I recommend reading the Additional Context section of this answer, then reading the how-to at the top.

The short version of what you're doing wrong is that you should be reading stepContext.Result after first intercepting the user's submit and converting Activity.Value to Activity.Text. Again, read the above links for more info.

If you still struggle with it, read the Other Resources section of this answer.

mdrichardson
  • 7,141
  • 1
  • 7
  • 21
  • Thank you for teaching me. It was helpful because I didn't know at all what the problem was related to. I was able to solve it by referring to what you taught me. – stkhr Nov 05 '19 at 03:17
  • @stkhr Glad you got it working! I'm generally very happy to help with pretty in-depth answers; I've just seen this question a lot, so sorry if I came off a bit short. I understand being new to an SDK and not really knowing what to search for. If you feel my answer was sufficient, please "accept" and upvote it so others can quickly find the answer and I can clear this from my support tracker. If not, let me know how else I can help! – mdrichardson Nov 05 '19 at 16:23