c# - How to use cards within `Dialog` -


i trying use fluent api create simple flow. instead of using plain text want use rich visual components. here example.

    public async task<httpresponsemessage> post([frombody]activity activity)     {         var yn = chain             .posttochain()             .select(m => createyesnoprompt(activity)) //this dialog should provide buttons user             .posttouser()             .waittobot()             .select(x => x.text)             .switch             (                 chain.case                 (                     s => s == "s",                     new contextualselector<string, idialog<string>>((context, item) => chain.return("yes"))                 ),                 chain.default<string, idialog<string>>((context, text) => chain.return("no"))             )             .unwrap()             .posttouser();          await conversation.sendasync(activity, () => yn);          return request.createresponse(httpstatuscode.ok);     }       private static activity createyesnoprompt(activity activity)     {         var reply = activity.createreply();          var ybutton = new cardaction(type: "postback", title: "yes", value: "s");         var nbutton = new cardaction(type: "postback", title: "no", value: "n");          var buttons = new list<cardaction>() { ybutton, nbutton };          var card = new herocard("would start order?", "subtitle", buttons: buttons);          reply.attachments = new list<attachment> { card.toattachment() };          return reply;     } 

instead of expected output, bot outputting microsoft.bot.connector.activity, tostring() return of activity object.

how use cards within dialogs?

this shows card when passed dialogcontext:

    private static activity showbuttons(idialogcontext context, string strtext) {     // create reply activity     activity replytoconversation = (activity)context.makemessage();     replytoconversation.text = strtext;     replytoconversation.recipient = replytoconversation.recipient;     replytoconversation.type = "message";     // call createbuttons utility method      // create 5 buttons put on here card     list<cardaction> cardbuttons = createbuttons();     // create hero card , add buttons      herocard plcard = new herocard()     {         buttons = cardbuttons     };     // create attachment     // set attachmentlayout 'list'     attachment plattachment = plcard.toattachment();     replytoconversation.attachments.add(plattachment);     replytoconversation.attachmentlayout = "list";     // return reply calling method     return replytoconversation; } 

see: using images, cards, carousels, , buttons in microsoft bot framework


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -