bots - How to use the ThumbnailCard in IDialog Context -
hi developing 1 bot using microsoft botframework
project in using idialog
interface. in using thumbnailcard
displaying cards. here when attaching data cards , data attaching within postasync
method it’s not providing reply.
public virtual async task messagereceivedasync(idialogcontext context, iawaitable<imessageactivity> argument) { thumbnailcard plcard = null; imessageactivity replytoconversation =await argument; replytoconversation.type = "message"; replytoconversation.attachments = new list<attachment>(); replytoconversation.text = "welcome book show"; dictionary<string, string> cardcontentlist = new dictionary<string, string>(); cardcontentlist.add("jason bourne", "url"); cardcontentlist.add("the land", "url"); cardcontentlist.add("yoga hosers", "url"); foreach (keyvaluepair<string, string> cardcontent in cardcontentlist) { list<cardimage> cardimages = new list<cardimage>(); cardimages.add(new cardimage(url: cardcontent.value)); list<cardaction> cardbuttons = new list<cardaction>(); if (cardcontent.key == "jason bourne") { cardaction plbutton1 = new cardaction() { value = $"", type = "openurl", title = "book now" }; cardaction plbutton2 = new cardaction() { value = "tel:1-800-800-5705", type = "call", title = "show timings" }; cardbuttons.add(plbutton1); cardbuttons.add(plbutton2); plcard = new thumbnailcard() { title = $"jason bourne", subtitle = " ", images = cardimages, buttons = cardbuttons, }; attachment plattachment = plcard.toattachment(); replytoconversation.attachments.add(plattachment); } else if (cardcontent.key == "the land") { cardaction plbutton1 = new cardaction() { value = $"", type = "openurl", title = "book now" }; cardaction plbutton2 = new cardaction() { value = "tel:1-800-800-5705", type = "call", title = "show timings" }; cardbuttons.add(plbutton1); cardbuttons.add(plbutton2); plcard = new thumbnailcard() { title = $"the land", subtitle = "", images = cardimages, buttons = cardbuttons, }; attachment plattachment = plcard.toattachment(); replytoconversation.attachments.add(plattachment); } else if (cardcontent.key == "yoga hosers") { cardaction plbutton1 = new cardaction() { value = $"", type = "openurl", title = "book now" }; cardaction plbutton2 = new cardaction() { value = "tel:1-800-800-5705", type = "call", title = "show timings" }; cardbuttons.add(plbutton1); cardbuttons.add(plbutton2); plcard = new thumbnailcard() { title = $"yoga hosers", subtitle = "", images = cardimages, buttons = cardbuttons, }; attachment plattachment = plcard.toattachment(); replytoconversation.attachments.add(plattachment); } } replytoconversation.attachmentlayout = attachmentlayouttypes.list; await context.postasync(replytoconversation); }
when run bot show following error
can use cards in idialog context attachments?
the issue imessageactivity, trying send imessageacticity in context.postasync. that's reason failing.
do following changes make work
change method signature below
private async task messagereceived(idialogcontext context, iawaitable<object> argument)
and modify imessageactivity replytoconversation =await argument;
below
var message = await argument activity; activity replytoconversation = message.createreply("welcome." + "(hi)"); replytoconversation.recipient = message.from;
now should work, if still have issue please comment here.
-kishore
Comments
Post a Comment