-1

I need to create a form in which the user has to fill it and to send it. So i have to create a submit button that calls another method but i couldn't find the link between the submit action and the call to another method.

The script of my form is :

public Attachment CreateAdaptiveCardwithEntry()
        {
            var submitActionData = JObject.Parse("{ \"Type\": \"SaveFunction\" }");
            var card = new AdaptiveCard()
            {

                Body = new List<CardElement>()
                {  
                    // Hotels Search form  

                    new TextBlock() { Text = "Titre de la note des frais" },
                    new TextInput()
                    {
                        Id = "titre",
                        Speak = "<s>Veuillez saisir le titre</s>",
                        Placeholder = "Veuillez saisir le titre",
                        Style = TextInputStyle.Text
                    },

                },

                Actions = new List<ActionBase>()
                {
                    new SubmitAction()
                    {
                       DataJson = submitActionData.ToString()

                    }
                }
            };

The script of my card is :

    var replyMessage = context.MakeMessage();
    replyMessage.Attachments = new List<Attachment> { FraisDialog.CreateAdaptiveCardwithEntry() };
    await context.PostAsync(replyMessage, CancellationToken.None);
    context.Wait(MessageReceived);

the script in MessageReceivedAsync is :

public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            var message = await result;

            if (message.Value != null)
            {
                // Got an Action Submit
                dynamic value = message.Value;
                string submitType = value.Type.ToString();
                switch (submitType)
                {
                    case "SaveFunction":
                        await context.PostAsync("Please complete all the search parameters:\n");
                        return;
                }
            }
        }

In this example i need to send the information with the Id = "titre" and pprocess it afterwards, i don't know how to send it(DataJson ?) and where(MessageReceivedAsync ?). Can someone help me ? do i need to create another dialog just for the card ?

Ps : all this code is in rootDialog.

Soufien Hajji
  • 477
  • 1
  • 8
  • 24
  • You just want to process the fields entered in the adaptive card? – Anita George May 07 '18 at 08:56
  • yes that's what i want, but i can't trigger the submit action. Can you show me how ? – Soufien Hajji May 07 '18 at 08:57
  • what do you mean by trigger submit action ? Aren't you getting a message 'Please complete all the search parameters' ? – Anita George May 07 '18 at 09:18
  • Thta's exactly where my problem is, i'm not getting the message 'Please complete all the search parameters' instead i'm getting "Sorry, my bot code is having an issue" which is a 500 internal server error. – Soufien Hajji May 07 '18 at 09:20

1 Answers1

0

i'm not getting the message 'Please complete all the search parameters'

If all of your code is in RootDialog then please use context.Wait(MessageReceivedAsync); after sending your attachment.

i need to send the information with the Id = "titre" and process it afterwards

When clicking the submit button, the form data is send to MessageReceived method as usual. If you want to just access the fields in the adaptive card you can access the dynamic variable value. Here is an example.

var message = await result;

if (message.Value != null)
{
    // Got an Action Submit
    dynamic value = message.Value;
    string submitType = value.Type.ToString();
    switch (submitType)
    {
        case "SaveFunction":
            if(value.titre == "")
            {
                await context.PostAsync("Please complete all the search parameters:\n");
            }
            else
            {
                await context.PostAsync($"You entered {value.titre}");
            }
            return;
    }
}
Anita George
  • 1,145
  • 6
  • 18
  • I already used context.Wait(MessageReceivedAsync); after sending my attachement as indicated in my code above. It's as if the method MessageReceivedAsync is never called, i already sat a breakpoint there but it was never hit. Do you think that the problem because of the dialog is a LuisDialog and not a regular Dialog ? because i have never seen the method MessageReceivedAsync in LuisDialog before. – Soufien Hajji May 07 '18 at 09:40
  • 1
    Luis Dialog? You didn't specify anything about Luis Dialog and you mentioned everything was in Root Dialog? Luis Dialogs does not have MessageRecievedAsync. Please change your question with details of your problem. – Anita George May 07 '18 at 09:43
  • okay thank you i'll change it. So just to confirm we can't trigger the submit action in Luis dialog, we just have to create another dialog in which we manage the adaptive cards ? – Soufien Hajji May 07 '18 at 11:54
  • 1
    Try using a root dialog and forwarding to a LUIS dialog with a `Context.Forward` that way you can manipulate the `value` and `activity` as needed before you hit LUIS – D4RKCIDE May 08 '18 at 20:22