i trying implement bot using bot framework microsoft. followed documentation doesn't seem adding buttons properly. on skype shows sort of thumbnail opens skype download page. on facebook messenger doesn't show anything.
any advice? thank you!
yes can achieve add custom button work on every channel of bot framework.
there 2 approach achieve that: 1) use cards feature of bot buttons. (quick , easy) 2) use direct line channel , add custom button. (complex)
lets start approach 1
you need create hero card , call in dialog. hero card contains text response bot , thumbnail image url. (you can remove thumbnail if not required). below running code help.
public async task startasync(idialogcontext context) { context.wait(imgcardresponse); } private async task imgcardresponse(idialogcontext context, iawaitable<imessageactivity> argument) { var message = await argument; //responsemsgonly used pass bot reply message //responseimage used pass thumbnail image var attachment = botbuttoncard(responsemsgonly, responseimage); cardmsg.attachments.add(attachment); await context.postasync(cardmsg); } private static attachment botbuttoncard(string responsemsgonly, string responseimage) { var herocard = new herocard { title = "here go response", subtitle = "subtitle goes here", text = responsemsgonly, images = new list<cardimage> { new cardimage(responseimage) } buttons = new list<cardaction> { new cardaction(actiontypes.openurl, "your button label", value: "https://www.google.com") } }; return herocard.toattachment(); } private async task resumeafteraction(idialogcontext context, iawaitable<object> result) { context.done(new object()); }
lets start approach 2
the direct line api simple rest api connecting directly single bot. api intended developers writing own client applications, web chat controls, or mobile apps talk bot. direct line v3.0 nuget package simplifies access underlying rest api.
you need create html page , put below code
in head part
<link href="../botchat.css" rel="stylesheet"/> <script src="../js/botchat.js"></script>
in body part
<div id="bot"></div> <script> var firstname; var emailaddress; var environment; try{ firstname = _sppagecontextinfo.userdisplayname; emailaddress = "manoj.resources@resources.in"; environment= _sppagecontextinfo.webabsoluteurl ; } catch(ex) { spcontext = 'you'; environment = 'local system'; } botchat.app({ directline: { secret: 'your direct line secret' }, user: { id: firstname,name: environment}, name: spcontext, value: firstname, from: '', bot: { id: 'bot id' }, resize: 'detect' }, document.getelementbyid("bot")); </script>
do let me know in case need help
Comments
Post a Comment