an introduction to the microsoft bot framework: create facebook and skype chatbots using microsoft...
TRANSCRIPT
![Page 1: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/1.jpg)
![Page 2: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/2.jpg)
![Page 3: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/3.jpg)
AnIntroductiontotheMicrosoftBotFramework
CreateFacebookandSkypeChatbotsusingMicrosoftVisualStudioandC#
(ThisbookcoverstheMicrosoftBotFrameworkPreviewEdition)
Copyright2016
PublishedBy
TheAiHelpWebsite
http://AiHelpWebsite.com
![Page 4: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/4.jpg)
Copyright
Copyright©2016byMichaelWashington
Coverandinternaldesign©MichaelWashington
EditingbyAndreaDickinson(www.QualityBookServices.com)
Allrightsreserved.Nopartofthisbookmaybereproducedinanyformorbyanyelectronicormechanicalmeansincludinginformationstorageandretrievalsystems–exceptinthecaseofbriefquotationsinarticlesorreviews–withoutthepermissioninwritingfromitspublisher,AiHelpWebsite.com.
Allbrandnamesandproductnamesusedinthisbookaretrademarks,registeredtrademarks,ortradenamesoftheirrespectiveholders.Wearenotassociatedwithanyproductorvendorinthisbook.
MicrosoftVisualStudioisaregisteredtrademarkofMicrosoftCorporation.
SkypeisaregisteredtrademarkofMicrosoftCorporation.
FacebookisaregisteredtrademarkofFacebookInc.
![Page 5: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/5.jpg)
![Page 6: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/6.jpg)
TableofContents
Copyright
TableofContents
Dedication
MichaelWashington
ThankYou
Microsoft
Community
Preface
Requirements
Chapter1:UnderstandingtheMicrosoftBotFramework
WhatIstheMicrosoftBotFramework?
Chapter2:CreateaHelloWorld!Bot
CreatingAHelloWorld!Bot
UsingTheBotEmulator
SavingUserData
PublishingTheBot
RegisteringTheBotWithTheMicrosoftBotFrameworkDeveloperPortal
Chapter3:UsingFormFlow
AWalkThrough
CreatingTheProject
TestTheApplication
SavingTheData
Chapter4:UsingDialogs
WalkThrough
CreatingTheApplication
TestTheApplication
DialogPrompts
Chapter5:UsingImages,Cards,Carousels,andButtons
HeroCard
Carousel
![Page 7: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/7.jpg)
RichCardAttachmentsInDialogs
CreateTheHeroCardInTheDialogClass
CreatingARe-UsableHeroCard
Chapter6:ImplementingASQLServerDatabaseWithYourBot
CreateTheSQLServerDatabase
CreateAnADO.NETEntityDataModel
LogToTheDatabase
LogMessagesInTheDialogClass
TestTheDatabaseLoggingCode
ViewTheData
LoggingHighScores
UpdateADO.NETEntityDataModel
AlterCodeToLogHighScores
DisplayTheHighScores
TestTheCode
PublishingAMicrosoftBotFrameworkApplicationThatUsesaDatabase
Chapter7:ImplementingLanguageUnderstandingIntelligentService(LUIS)
CreateTheLUISApplication
UpdateTheBotApplication
ImplementHighScores
Chapter8:CallingTheMicrosoftBotFrameworkUsingTheDirectLineAPI
ConfiguringTheDirectLineConnector
CreateTheWebApplication
CompleteTheWebApplication
RunTheApplication
Chapter9:UsingApplicationInsightsToMonitorYourBot
EnableApplicationInsights
DebugTheApplication
UsingTheBotEmulator
CustomTelemetry
ApplicationInsightsAPIsummary
ApplicationInsightsPortal
![Page 8: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/8.jpg)
MonitoringAPublishedApplication
Chapter10:CreatingaSkypeBot
PublishingTheBot
RegisteringTheBotWithTheBotConnector
ConfigureSkype
Chapter11:CreatingAFacebookMessengerBot
Set-UpFacebook
CreateAFacebookDeveloperAccount
CreateAFacebookApp
ConfigureTheCallbackURLandVerifyToken
GetPageToken
ConfigureTheMicrosoftBotConnector
TalkingToYourBot
AboutTheAuthor
![Page 9: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/9.jpg)
Dedication
![Page 10: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/10.jpg)
MichaelWashington
Asalways,forValerieandZachary
![Page 11: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/11.jpg)
![Page 12: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/12.jpg)
ThankYouMicrosoft
DanDriscoll
JimLewallen
SimonMichael
AnnaRoth
RebeccaDuffy
DanielEgan
![Page 13: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/13.jpg)
Community
EzequielJadib
JoeMayo
RobinOsborne
GaryPretty
MaheshChand
JohnathanLightfoot
![Page 14: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/14.jpg)
Preface
![Page 15: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/15.jpg)
Requirements
YoumusthaveacomputerrunningMicrosoftWindowswithMicrosoftVisualStudio2015(orhigher)withUpdate3(orhigher)tocreatetheapplicationsdescribedinthisbook.
YoucandownloadthefreeVisualStudioCommunityEditionfromhttps://www.visualstudio.com/vs/community/
YouwillalsoneedtodownloadandinstalltheVisualStudio2015Bottemplatefromhttp://aka.ms/bf-bc-vstemplate
![Page 16: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/16.jpg)
![Page 17: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/17.jpg)
![Page 18: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/18.jpg)
Chapter1:UnderstandingtheMicrosoftBotFramework
ThisbookcoversusingVisualStudio2015tocreateChatbotsusingtheMicrosoftBotFramework.Thepurposeofthisbookistodemonstrate,provideexamplesof,andtoexplainimportantconceptsofthetechnology.
![Page 19: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/19.jpg)
WhatIstheMicrosoftBotFramework?
TheMicrosoftBotFrameworkallowsyoutoeasilycreateBots.
Youcancreatebotsthatinteractwithyourusersnaturallywherevertheyare,includingFacebook,text,Skype,Office365email,andotherpopularservices.
![Page 20: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/20.jpg)
TheMicrosoftBotFrameworkcontainsthefollowingcomponents:
BotFrameworkDeveloperPortal–AservicethatconnectsyourBottocommunicationchannelssuchasFacebook,Skype,andemail.BotBuilderSDK–AC#andNode.jslibrarythatprovidesapowerfulframeworkforconstructingbotsthatcanhandlefreeformandguidedinteractions.BotDirectory–AdirectoryofBotsthatyoucanconnectto.
TheBotFrameworkDeveloperPortalhelpsyouconnectyourBottocommunicationchannels.YoucanwriteaBotandexposetheMicrosoftBotFramework-compatibleAPIontheInternet.TheBotFrameworkDeveloperPortalwillforwardmessagestousers,andwillsendtheusermessagesbacktoyourBot.
TheBotBuilderSDKisanopensourceSDKhostedonGitHub(https://github.com/Microsoft/BotBuilder-Samples)thatprovideseverythingyouneedtobuilddialogs.BotdevelopersatMicrosoftcreatedthislibrarytoencapsulatefunctionalityrequiredforconversationalbots.
TheBotDirectory(locatedathttps://bots.botframework.com/)featuresBotsthatyoucancommunicatewiththroughchannelsexposedthroughtheBotConnector.
![Page 21: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/21.jpg)
![Page 22: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/22.jpg)
![Page 23: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/23.jpg)
Chapter2:CreateaHelloWorld!Bot
Thesamplecodeforthischaptercanbeobtainedatthelink“CreatingaHelloWorld!BotUsingTheMicrosoftBotFramework”athttp://AiHelpWebsite.com/Downloads
ThepurposeofthischapteristodemonstratehowtogetstartedusingtheMicrosoftBotFramework,howtocreateasimpleBot,andhowtopublishittotheMicrosoftBotFrameworkDeveloperPortal.
![Page 24: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/24.jpg)
CreatingAHelloWorld!Bot
DownloadtheVisualStudio2015templatefromhttp://aka.ms/bf-bc-vstemplate
Savethe.zipfileinthetemplatesdirectoryofyourwindowscomputerlocatedat%USERPROFILE%\Documents\VisualStudio2015\Templates\
ProjectTemplates\VisualC#
ThiscreatesatemplatethatyoucanuseinVisualStudiotocreateBotprojects.
OpenVisualStudio.
CreateanewProject.
![Page 25: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/25.jpg)
SelecttheBotApplicationtemplateandnametheprojectHelloWorldBot.
OpentheMessagesController.csfileintheControllersfolder.
ChangethePostmethodtothefollowing:
![Page 26: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/26.jpg)
HitF5toruntheproject.
Notethewebaddress.Youwillneeditinthenextstep.
![Page 27: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/27.jpg)
UsingTheBotEmulator
Download,install,andruntheBotFrameworkEmulatorfromhttps://aka.ms/bf-bc-emulator
Whentheemulatorstarts,connecttotheBotbysettingtheaddresstotheaddressindicatedinthewebbrowser.However,add/api/messagestotheend.
IntheBotEmulator,enterHellointhetextboxandclickthesendkey(orpressenter).
YouwillseetheresponseintheChatwindowandtheJSONcontentsoftheresponseintheJSONwindow.
![Page 28: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/28.jpg)
SavingUserData
Animportantpartofanyconversationisrememberingwhatauserhaspreviouslysaid.
WecandothisusingGetPrivateConversationDataandSetPrivateConversationData.
Todemonstratehowthisishandled,addthefollowingtothetopoftheMessagesController.csfileintheControllersfolder:
![Page 29: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/29.jpg)
Next,changethePostmethodintheMessagesController.csfiletothefollowing:
![Page 30: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/30.jpg)
Finally,alterthefollowingsectionintheHandleSystemMessagemethod(intheMessagesController.csfile)tothefollowing:
NowwhenwechatwiththeBot,itcanrememberourname.
![Page 31: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/31.jpg)
IfwetellittoDeleteUserData…
Itwillrespectourwishes.
![Page 32: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/32.jpg)
PublishingTheBot
ToconnectyourBotthroughchannelssuchasSkypeandFacebookMessenger,youneedtoconfigureitontheMicrosoftBotFrameworkDeveloperPortal.Todothat,youwillfirstneedtopublishitinapubliclyaccessiblelocation.
Thiscanbeanyserver;however,publishingtoAzureisrecommendedbecausepublishingtoithasbuilt-insupportinVisualStudio.
First,gotohttps://azure.microsoft.comandcreateanaccountandasubscriptionifyoudon’talreadyhaveone.
Next,Right-clickontheProjectnode(nottheSolutionnode)inVisualStudioandselectPublish.
![Page 33: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/33.jpg)
SelectMicrosoftAzureWebApps.
SignintoyourAzureaccount.
Selectasubscription.
ThenclicktheNewbutton.
![Page 34: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/34.jpg)
EnterauniqueWebAppname.
Selectyoursubscription.
Selectorcreateaserviceplan,resourcegroupandregion.
ThenclicktheCreatebutton.
Afterthewebapphasbeencreated,clickthePublishbutton.
![Page 35: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/35.jpg)
Thewebappwillopeninthewebbrowser.
Notethewebaddress.Youwillneeditinalaterstep.
![Page 36: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/36.jpg)
RegisteringTheBotWithTheMicrosoftBotFrameworkDeveloperPortal
GototheMicrosoftBotFrameworkDeveloperPortalathttps://www.botframework.comandsigninwithyourMicrosoftAccount.
SelectRegisterabot.
![Page 37: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/37.jpg)
Fillinallofthefields.
Note:Theendpointwebaddressiswhatyousawwhenthewebbrowseropenedinthepreviousstep.However,rememberyouhavetoadd“/api/messages”totheendoftheaddressandusehttps://ratherthanhttp://.
Duringtheprocess,youwillbepromptedtoclickalinktogotohttps://apps.dev.microsoft.com.
ItistherethatyouwillgetanApplicationIDandapassword.
MakeanoteofthembecauseyouwillneedtousethemtoupdatetheVisualStudioprojectinlaterstep.
ClicktheRegisterbutton.
![Page 38: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/38.jpg)
TheBotregistrationwillbecreated.
CopytheBotID,MicrosoftAppId,andMicrosoftAppPasswordfromthehttps://apps.dev.microsoft.comsitetotheweb.configoftheBotinVisualStudio.
Note:IfyouforgottonotetheMicrosoftAppPasswordintheearlierstep,youcanclicktheGenerateNewPasswordbuttontocreateanotherone.
![Page 39: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/39.jpg)
PublishtheBotagain.
YouaredoingthisbecausetheBotFrameworkwillpasstheBotID,MicrosoftAppId,andMicrosoftAppPasswordwhenitcommunicateswithit.
YoucannowtestyourBotusingtheBotFrameworkDeveloperPortalwebpage.
![Page 40: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/40.jpg)
Ifyoudesire,youcanclickthePublishbuttontosubmityourBottotheBotDirectory.
YoucanalsoconfigurechannelsforyourBot.
EvenifyoudonotpublishyourBottotheBotDirectory,youcanstillcallitfromyourownapplicationsandthroughanychannelsyouconfigure.
Note:Chapters10and11coverhowtousetheBotFrameworkDeveloperPortaltoconfiguretheSkypeandFacebookMessengerchannelstodeployyourBotonthosenetworks.
![Page 41: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/41.jpg)
![Page 42: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/42.jpg)
![Page 43: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/43.jpg)
Chapter3:UsingFormFlow
Thesamplecodeforthischaptercanbeobtainedatthelink“IntroductionToFormFlowWithTheMicrosoftBotFramework”athttp://AiHelpWebsite.com/Downloads
UsingFormFlowwiththeMicrosoftBotFrameworkallowsyoutoquicklycreateaguidedconversationtogatherinformationfromauserwiththeleastamountofcode.WhileitislessflexiblethanusingDialogs(Dialogsarecoveredinthenextchapter),itcanbecombinedwithDialogstoincreaseitsfunctionality.
![Page 44: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/44.jpg)
AWalkThrough
WhenauserbeginsaconversationwiththeBot,itintroducesitselfandaskstheuser’sname.
TheBotproceedstoaskquestionsandgathertheresponses.
![Page 45: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/45.jpg)
AfeatureofFormFlowisthattheusercantypehelpatanytimetoobtainassistancewithanyquestionortheFormFlowitself.
Asadeveloper,yougetthisfunctionalitywithouttheneedtowriteanyadditionalcode.
TheFormFlowcontinuesuntiltheformiscomplete.
![Page 46: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/46.jpg)
CreatingTheProject
OpenVisualStudio.
CreateanewProject.
SelecttheBotApplicationtemplateandnametheprojectHelloFormFlowBot.
Theprojectwillbecreated.
![Page 47: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/47.jpg)
Right-clickontheproject.SelectAddandthenNewItem.
WewillnowcreatetheclassthatwillcontainthelogicforourFormFlow.
AddanewC#classcalledProfileForm.cs.
![Page 48: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/48.jpg)
Replaceallthecodewiththefollowingcode:
ThiscodeindicatesthefieldswewillgatherwithourFormFlow.
Noticethattheclass,aswellastheGenderenumthatitconsumes,ismarked[Serializable].
TheMicrosoftBotFrameworkrequiresthattheclassesmustbeserializable,sotheBotcanbestateless.
Savethefile.
![Page 49: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/49.jpg)
OpentheMessagesController.csfile.
Addthefollowingusingstatementsatthetopofthefile(tosupporttheFormFlowcode):
![Page 50: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/50.jpg)
AddthefollowingMakeRootDialogmethodtotheMessagesControllerclasstocalltheBuildFormmethodintheProfileFormclasswecreatedearlier:
Finally,alterthePostmethodintheMessagesControllerclasstothefollowing:
Savethefile.
![Page 51: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/51.jpg)
TestTheApplication
HitF5toruntheapplication.
Thewebbrowserwillopen.
Notetheportnumberandthewebaddress.
OpenandruntheMicrosoftBotFrameworkEmulator.
Whentheemulatorstarts,connecttotheBotbysettingtheaddresstotheoneindictedinthewebbrowser;however,add/api/messagestotheend.
![Page 52: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/52.jpg)
EnsurethattheBotURLisconnectingtothecorrectaddress.
Typeamessageandclickthesendkey(orpressEnter).
YoucannowconversewiththeBotandfillouttheFormFlow.
![Page 53: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/53.jpg)
SavingTheData
Currentlytheapplicationdoesnotsavetheresponsesfromtheuser.Infact,afteryoufilltheFormFlowout,itwillsimplyaskyoutofillitoutagain.
WecanusetheBotStateServicetosaveandretrievethevalues.
![Page 54: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/54.jpg)
AltertheBuildFormmethodintheProfileForm.csfiletothefollowingtosavethevaluesenteredintotheform:
Wearenotonlystoringthevaluesprovidedbytheuser,butwearealsosettingaflag(ProfileComplete),sowedon’tasktheusertofillouttheformagain.
![Page 55: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/55.jpg)
Finally,alterthePostmethodintheMessagesControllerclasstothefollowing:
![Page 56: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/56.jpg)
NowtheapplicationwillonlyasktheusertofillintheformonetimeanddisplaythevaluesreceivedusingtheBotStateService.
ThevalueswillbepersistedbytheMicrosoftBotFrameworkkeyedtothatuserinthatconversation.
![Page 57: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/57.jpg)
Inourexample,weusedPrivateConversationData,buttheBotStateServiceexposesthefollowingmethods,eachwithadifferentscope:
Method Scoped Description
SetUserData() User Rememberingcontextobjectwithauser
SetConversationData() Conversation Rememberingcontextobjectwithaconversation
SetPrivateConversationData() User&Conversation
Rememberingcontextobjectwithapersoninaconversation
![Page 58: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/58.jpg)
![Page 59: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/59.jpg)
![Page 60: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/60.jpg)
Chapter4:UsingDialogs
Thesamplecodeforthischaptercanbeobtainedatthelink“IntroductionToUsingDialogsWithTheMicrosoftBotFramework”athttp://AiHelpWebsite.com/Downloads
UsingDialogswiththeMicrosoftBotFrameworkallowsyoutomodelaconversationwithauser.WhiletheyaremoreflexiblethanusingaFormFlow(coveredintheprecedingchapter),Dialogsrequiremorecode.
ADialogisaclassthatimplementstheIDialoginterface.Dialogscanbecomposedwithotherdialogstomaximizereuse.
ADialoghasacontextthatcontainsastackofdialogsactiveinaconversationandwillmaintainthestateoftheconversation.ADialogsendsmessagestoauserandissuspendedwhenitiswaitingforaresponsefromauser.
ADialogusesastatestoredinitscontexttoresumeaconversation.ThisstateisstoredinthestateserviceprovidedbytheMicrosoftBotFrameworkservice.
![Page 61: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/61.jpg)
WalkThrough
TheconversationstartswhentheUsertypesinamessage.
TheBotrespondswithagreetingandthedirectionsofthegame,whichistoguessanumberfrom1to10(chosenatrandom).
TheUserguessesanumber,andtheBotinformstheUseriftheyarecorrectornot.
![Page 62: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/62.jpg)
WhentheUserguessesthenumbercorrectly,theyareofferedachancetoplaythegameagain.
IftheUserchoosesnottoplaythegameagain,theBottellsthemgoodbye.
![Page 63: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/63.jpg)
CreatingTheApplication
OpenVisualStudio.
CreateanewProject.
SelecttheBotApplicationtemplateandnametheprojectAiNumberGuesserBot.
![Page 64: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/64.jpg)
Theprojectwillbecreated.
Right-clickontheproject.SelectAddandthenNewItem.
WewillnowcreatetheclassthatwillcontainthelogicfortheDialog.
![Page 65: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/65.jpg)
AddanewC#classcalledNumberGuesserDialog.cs.
![Page 66: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/66.jpg)
Replaceallthecodewiththefollowingcode:
ADialogisaclassthatinheritsfromIDialog.
Notethatwemustdecoratethisclassas[Serializable].
ThisrequiresyoutoimplementaStartAsyncmethod.
Toimplementthis,hoverthemouseoverIDialog<object>,waitafewseconds,andtheinterfaceoptionwindowwillappear.
![Page 67: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/67.jpg)
ClicktheblackarrownexttothelightbulbandselectImplementinterface.
TheStartAsyncmethodwillbecreated.
ThiswillbecalledwhentheDialogisfirstinstantiated.
Wewantthecodetorunasynchronously,soaddasynctothemethodsignature.
![Page 68: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/68.jpg)
Now,changethecodeinsidethemethod,sothecompletemethodiscodedasfollows:
Thelastlineinthemethodiscontext.Wait.ThissuspendsthecurrentDialoguntiltheuserhassentamessagetotheBot.
TheWaitmethodtakesamethodasaparameter(inthiscaseMessageReceivedAsync)tobecalledtoresumetheconversationwhentheresponsehasbeenreceived.
Toimplementit,hoverthemouseoverMessageReceivedAsync,waitafewseconds,andtheinterfaceoptionwindowwillappear.
ClicktheblackarrownexttothelightbulbandselectGeneratemethod‘NumberGuesserDialog.MessageReceivedAsync.
TheMessageReceivedAsyncmethodwillbecreated.
NoticeittakesthecontextoftheDialogandanargument(result).
![Page 69: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/69.jpg)
ChangethetypeoftheargumentfromobjecttoIMessageActivityandchangethenameofthevariablefromresulttoargument.
Again,wewantthecodetorunasynchronously,soaddasynctothemethodsignatureandmarkitasvirtual.
Alterthecodeinthemethod,sothecompletemethodiscodedasfollows:
Noticethelastline(context.Wait(MessageReceivedAsync))simplycallsthemethodthecodeiscontainedinagainandagain.
Weareonlydoingthistomakethisexampleassimpleaspossible.WewillexploreamorerealisticexampleinthenextsectionwhenweaddaPromptDialog.
![Page 70: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/70.jpg)
Next,opentheMessagesController.csfileat…\AiNumberGuesserBot\AiNumberGuesserBot\Controllers\
MessagesController.cs
Replacethedefaultcodeinthecodeblockthatbegins:
Withthecode:
ThistellstheBottodirectanymessagestotheNumberGuesserDialogclass.
![Page 71: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/71.jpg)
Finally,addthefollowingusingstatementtothetopofthecodefile:
![Page 72: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/72.jpg)
TestTheApplication
HitF5toruntheapplication.
Thewebbrowserwillopen.Notetheportnumberandthewebaddress.
OpenandruntheMicrosoftBotFrameworkEmulator.
Whentheemulatorstarts,connecttotheBotbysettingtheaddresstotheoneindictedinthewebbrowser;however,add/api/messagestotheend.
EnsurethattheBotURLisconnectingtothecorrectaddress.
![Page 73: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/73.jpg)
Typeamessageandclickthesendkey(orpressEnter).
TheBotwillrespond.
ThisisalltheBotwilldoatthispoint;however,thisexampleshowstheminimalcodetocreateandconsumeaDialogclass.
![Page 74: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/74.jpg)
DialogPrompts
APromptDialogisessentiallyaDialogfactoryforcreatingsimpleprompts.ItallowsyoutoasktheUserforaresponseandindicatewhatcodewillrunwhentheresponseisgiven.APromptDialogspawnsasub-dialogthathasitsownprivatestate.Thissub-dialogissuspendedbytheMicrosoftBotFrameworkservicewhileitwaitsforaresponse.Whenitgetsaresponse,itresumesatthepointinthecodeitwasatwhenitwassuspended.
ThisistheprimarymeansofcontrollingprogramflowwithinaDialogclass.
APromptDialogcanbeoneofthefollowingtypes:
PromptforanattachmentPromptforoneofasetofchoicesAskayes/noquestionPromptforalongPromptforadoublePromptforastring
WewillenhanceourapplicationtoimplementaPromptDialogthatasksayes/noquestion.
![Page 75: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/75.jpg)
First,addthefollowingcodetotheMessageReceivedAsyncmethod:
Thiscodewillsimplykeeploopingandcountingtheguessingattemptsiftheuserdoesnotguesstherandomnumber.
Iftheuserdoesguessthenumber,thecodeintheelseblockwillbecalled.
Rightnow,thecodeisnotcomplete.WeneedtoaddaPromptDialogundertheline//PutPromptDialoghere.
![Page 76: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/76.jpg)
TypePromptDialogandpresstheperiod(.)key.TheautocompleteoptionswillshowandwewillseetheoptiontoimplementthevarioustypesofPromptDialogs.
ChoosetheConfirmoption.
Wecanlookintheofficialdocumentationathttps://docs.botframework.com/en-us/csharp/builder/sdkreference/andseethemethodsignaturerequiresustopassthecurrentcontext,indicatethemethodtobecalledwhenwegetaresponse(resumehandler),provideamessagetoshowtheuser(prompt),andprovideamessagetodisplayiftheresponsetypeisnotcorrect(retry).Theotherparametersareoptional.
Thefollowingshowsthecompletecodeforourimplementation:
![Page 77: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/77.jpg)
Wenowneedtoimplementtheresumehandlermethodtohandletheresponse(PlayAgainAsync).
Toimplementit,hoverthemouseoverPlayAgainAsync,waitafewseconds,andtheinterfaceoptionwindowwillappear.
ClicktheblackarrownexttothelightbulbandselectGeneratemethod‘NumberGuesserDialog.PlayAgainAsync’.
Themethodwillbecreated.
Addasynctothemethodsignature.
Alterthemethod,sothecompletecodeisasfollows:
![Page 78: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/78.jpg)
HitF5toruntheprogramandconnecttoit,usingtheBotFrameworkEmulator…
Whenweguessthecorrectnumber,thePromptDialogwillappear.Whenweprovideananswer,thePlayAgainAsyncmethodwillimmediatelyruntoprocessouranswer.
WecanspawnanotherPromptDialoginsidethePlayAgainAsyncmethodifwechoose,effectivelycreatinganendlesschainofPromptDialogstocreatebranchesofcodeforaconversation.
![Page 79: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/79.jpg)
![Page 80: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/80.jpg)
![Page 81: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/81.jpg)
![Page 82: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/82.jpg)
Chapter5:UsingImages,Cards,Carousels,andButtons
Thesamplecodeforthischaptercanbeobtainedatthelink“UsingImages,Cards,Carousels,andButtonsInTheMicrosoftBotFramework”athttp://AiHelpWebsite.com/Downloads
Note:TheimageaboveshowstheBotinSkype.DeployingaBottoSkypeiscoveredinChapterTen.
ImplementingimagesinyourMicrosoftBotFrameworkapplicationaddsavisualelementtotheinteractionwithyourusers.
Youcaneasilypassamediaattachment(image/audio/video/file)toamessageusingcodesuchasthis:
![Page 83: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/83.jpg)
Dependingonthechannelusedandthemediatype,animagewillbedisplayedoralinkwillbedisplayedfortheusertodownloadthemediaelement.
However,realpowerisprovidedwhenyouuserichcardattachments.
Therearefourcardtypes:
CardType Description SingleorCarousel/List
(MultipleCards)
HeroCard Abigimagewithtext SingleorCarousel/List
ThumbnailCard
Asmallimagewithtext SingleorCarousel/List
ReceiptCard Aninvoiceorreceipt Single
Sign-InCard Ausersign-inform Single
![Page 84: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/84.jpg)
HeroCard
Inthischapter,wewillcoverHeroCard.
AHeroCardandaThumbnailCarddifferonlyinthesizeoftheirimageandcard.
Eachconsistsofthefollowingproperties:
Property Description
Title Titleofthecard
Text Texttodisplayonthecard
Subtitle Alinkforthetitle
Images Actually,onlyasingleimage
Buttons Oneormorebuttons(InSkype,only5buttonswilldisplayonacard.Ifyouhavemorebuttons,itwillcreatetwocards.)
Tap Anactionthatistriggeredwhenausertapsonthecard(ThisdoesnotworkinsomeSkypeclients,soforSkype,useahyperlinkfortheSubtitleproperty.)
![Page 85: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/85.jpg)
TodemonstrateimplementingaHeroCard,wewillstartwiththecodefromthepreviouschapter.
Note:First,youwillhavetouseManageNuGetPackagesinVisualStudiotoupdateMicrosoft.Bot.Buildertothelateststableversionbeforeyoucontinue.
Also,wewillmakesomesmallchanges,suchasmakingthenumbertoguessfrom1to5ratherthan1to10,soitshowsupwellinSkypebecauseSkypewillonlydisplay5buttonsonasinglecard.
OpentheprojectinVisualStudio.
AddanewfolderandcallitImages.
![Page 86: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/86.jpg)
AddtheNumberGuesserOpeningCard.pngfile(youcangetthecodeontheDownloadspageoftheAiHelpWebsite.com)totheImagesfolder.
OpentheMessagesController.csfile(intheControllersdirectory),andaddthefollowingusingstatementtothetopofthefile:
Next,locatetheelseif(message.Type==ActivityTypes.ContactRelationUpdate)sectionintheHandleSystemMessagemethod.
ThismethodfireswhentheBotisaddedtotheContactlistofauser.
Replaceallthecodeinthesectionwiththefollowingcode:
![Page 87: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/87.jpg)
SavethefileandhitF5toruntheapplication.
![Page 88: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/88.jpg)
OpenandruntheBotusingtheMicrosoftBotFrameworkEmulator.
IntheEmulator,invoketheContactRelationUpdate-addevent.
TheHeroCardwilldisplay.
ClickingonthecardwilltakeyoutotheAiHelpWebsite.comwebsite.
![Page 89: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/89.jpg)
Carousel
Acarouseldisplaysmultiplecards(eitherHeroCardsorThumbnailCards)horizontally.
AList(thedefaultlayoutformultiplecards)displaysthecardsvertically.
TheimageaboveshowswhatacarouseloftwoHeroCardslookslikeintheSkypeclient.
Toimplementthis,firstaddtheAiLogo_smallSquare.pngfile(youcangetthecodeontheDownloadspageoftheAiHelpWebsite.com)totheImagesfolder.
![Page 90: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/90.jpg)
Next,addthefollowingcodetotheHandleSystemMessagemethod(abovethevarconnector=newConnectorClient(newUri(message.ServiceUrl));line):
Savethefile,runtheapplication,andconnecttoitintheEmulator.
IntheEmulator,invoketheContactRelationUpdate-addevent.
![Page 91: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/91.jpg)
Thefirstcardwillshow,butyouwillnowseeaslider.
Slideittotheright.
YouwillthenseethesecondHeroCard.
InSkype,theSubtitlepropertywilldisplayasahyperlinkandbeclickable.
![Page 92: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/92.jpg)
RichCardAttachmentsInDialogs
ThereareadditionalchallengeswhenimplementingrichcardattachmentsinDialogs.
Primarily,thebiggestchallengeisthat,insidetheDialogclass,youdonothaveaccesstothebaseURLoftheapplicationtodeterminewhereyourimagesare.
WecanaddressthisbyusingtheBotStateService.
OpentheMessagesController.csfile:
AddthefollowingcodetothetopofthePostmethod:
ThiswillstoretheCurrentBaseURLandtheRecipientusingtheBotStateService,sothevaluescanlaterberetrievedintheDialogclass.
![Page 93: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/93.jpg)
OpentheNumberGuesserDialog.csfile.
Addthefollowingcodeabovethenamespace:
Addthistothetopoftheclass:
ThiswillprovideaglobalvariablethatwillbeautomaticallyserializedandpersistedbetweencallstostoretheBaseURL.
AddthefollowingcodetothetopoftheMessageReceivedAsyncmethod:
ThiswillretrievethevalueofCurrentBaseURLthatwasstoredinBotStateServiceintheMessagesControllerclassandstoreitinthestrBaseURLglobalvariable.
AddthefollowingUtilitymethodtotheclass.Thismethodwillcreate5CardActionbuttonsthatwillbeattachedtotheHeroCard(thatwewillcreateinalaterstep):
![Page 94: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/94.jpg)
ThebuttonsaresettotheType“imBack”,whichmakesthebutton(CardAction)simplypostthevalue(inthiscase,thebuttonnumber)backtotheBot.
![Page 95: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/95.jpg)
CreateTheHeroCardInTheDialogClass
WewillnowdisplayaHeroCardwith5buttonsintheDialogclass.
First,addtheNumberGuesserCard.pngfile(youcangetthecodeontheDownloadspageoftheAiHelpWebsite.com)totheImagesfolder.
![Page 96: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/96.jpg)
Next,findthefollowingcodeintheMessageReceivedAsyncmethod:
![Page 97: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/97.jpg)
Replaceitwiththefollowingcode:
Savethefile,hitF5toruntheproject,andconnecttoitintheEmulator.
![Page 98: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/98.jpg)
TheBotwillnowdisplayanimageandbuttons.
Wecaneitherclickoneofthebuttonsorenteranumbertoplaythegame.
![Page 99: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/99.jpg)
ThefollowingimageshowswhatitlookslikeinSkype:
![Page 100: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/100.jpg)
CreatingARe-UsableHeroCard
IfthereareafewmoreplacesweneedtodisplaytheHeroCardwiththebuttons,
wewillwanttocreateare-usableHeroCard.
ThisHeroCardwillnothaveanimage,onlybuttons.
![Page 101: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/101.jpg)
First,addthefollowingutilitymethodtotheDialogclass:
NotethatitcallstheCreateButtonsutilitymethodthatwecreatedearlier.
![Page 102: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/102.jpg)
Now,locatethefollowingcode:
Replaceitwith:
ThecodewillnowcalltheShowButtonsmethodthatwillreturntheHeroCard.
Finally,findthefollowingcode:
Replaceitwith:
![Page 103: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/103.jpg)
TheBotwillnowdisplaytheHeroCard,withonlythebuttons,ineachsituationwherewecalledtheutilitymethod.
![Page 104: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/104.jpg)
![Page 105: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/105.jpg)
![Page 106: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/106.jpg)
Chapter6:ImplementingASQLServerDatabaseWithYourBot
Thesamplecodeforthischaptercanbeobtainedatthelink“ImplementingASQLServerDatabaseWithTheMicrosoftBotFramework”athttp://AiHelpWebsite.com/Downloads
MicrosoftBotFrameworkChatbotapplicationsthatrequireinformationtobestored,queried,andsharedwithmultipleuserswillrequireacentralstoragerepository.
UsingMicrosoftSQLServerandMicrosoftAzurewillallowyoutoeasilyimplementthisfeature.
![Page 107: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/107.jpg)
TodemonstrateimplementingadatabasewithaMicrosoftBotFrameworkapplication,wewillstartwiththecodefromthepreviouschapter.
![Page 108: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/108.jpg)
CreateTheSQLServerDatabase
WewillstartbycreatingadatabaseandloggingthemessagessenttoandfromtheBot.
OpentheprojectinVisualStudio.
IntheSolutionExplorerinVisualStudio,right-clickontheProject(nottheSolution),andselectAdd,thenAddASP.NETFolder,thenApp_Data.
Note:App_Dataisaspecialfolderthatwillcontainthedatabasewewillcreate.Weusethisfolderbecausewewillhaveanoptiontonotdeploythisfolder(andthedatabasethatitwillcontain)whenwepublishtheapplicationtoAzure.Thiswillbecoveredlater.
![Page 109: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/109.jpg)
Right-clickontheApp_Datafolder.SelectAddandthenNewItem.
![Page 110: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/110.jpg)
AddaSQLServerDatabase.
NameitBotData.mdf.
Wewillnowcreateatableinthedatabasetoholdourdata.
Right-clickonthedatabaseandselectOpen.
![Page 111: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/111.jpg)
Expandthedatabaseelementsinthetree.
Right-clickonTablesandselectAddNewTable.
PastethefollowingscriptinandclicktheUpdatebutton:
![Page 112: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/112.jpg)
ClickUpdateDatabase.
Thetablewillbecreated.
![Page 113: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/113.jpg)
Right-clickontheTablesnodeandselectRefresh.
Thetablewillshow.
![Page 114: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/114.jpg)
CreateAnADO.NETEntityDataModel
WewillnowcreateanEntityDataModeltoallowprogrammaticaccesstothedatabase.
SwitchtoSolutionExplorerview.
![Page 115: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/115.jpg)
CreateafoldercalledModels.
Right-clickontheModelsfolder.SelectAddandthenNewItem.
AddanADO.NETEntityDataModelandcallitBotData.
WhentheEntityDataModelWizardopens,selectEFDesignerfromdatabase.
ClickNext.
![Page 116: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/116.jpg)
SelectBotData.mdfinthedatabasedropdown(ifitisnotalreadyselected).
ChecktheboxnexttoSaveconnectionsettingsinWeb.Config.
ClickNext.
![Page 117: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/117.jpg)
SelectEntityFramework6.x.
ClickNext.
![Page 118: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/118.jpg)
ExpandthetreetorevealtheUserLogtableandclickthecheckboxnexttoit.
Accepttheotherdefaultvalues.
ClickFinish.
TheBotData.edmxanEntityDataModelwillbecreated.
YoucanclosetheBotData.edmxfornow.
![Page 119: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/119.jpg)
LogToTheDatabase
Wewillnowcreatecodethatwilllog(mostof)themessagestoandfromtheBottothedatabase.
![Page 120: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/120.jpg)
First,createafilecalledUtility.csandusethefollowingcode:
Thiscreatesautilitymethodtoallowustotrimanytextwestoreinthedatabase.Thisensuresthatnomessageistoolongtobestoredinthedatabase.Thiswouldcauseanerror.
![Page 121: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/121.jpg)
Next,findthefollowingcodeinMessagesController.cs:
Replaceitwith:
ThiscodelogsthemessagesbeingsentfromtheusertotheBot.
![Page 122: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/122.jpg)
LogMessagesInTheDialogClass
TheDialogclasscreatesaresponsetotheuser.
FindallcodeintheNumberGuessserDialog.csfile(therewillbemultipleplaces)thatsendatextresponsetotheuser,whichcontaintheselines:
![Page 123: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/123.jpg)
Addthefollowingcodeabovetheexistinglinesofcode(again,therewillbemultipleplacesyouwilldothis):
WhenwehaveaPromptDialog,wedon’thaveareplyActivity.Inthiscase,weneedtomakeone,sowehavethevaluesweneedtologtothedatabase.
FindthefollowingcodeintheDialogclass:
![Page 124: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/124.jpg)
Addthefollowingcodeabovetheexistinglinesofcode:
Note:TheCongratulationsStringPromptissetbytheexistingcodetoindicatethattheuserhaswonthegame.
![Page 125: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/125.jpg)
TestTheDatabaseLoggingCode
HitF5toruntheapplication.
Thewebbrowserwillopen.
Notetheportnumberandthewebaddress.
OpenandruntheMicrosoftBotFrameworkEmulator.
Whentheemulatorstarts,connecttotheBotbysettingtheaddresstotheoneindictedinthewebbrowser;however,add/api/messagestotheend.
![Page 126: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/126.jpg)
EnsurethattheBotURLisconnectingtothecorrectaddress.
EnterHelloandclickthesendbuttontostartaconversationwiththeBot.
PlaythegamewiththeBot.
ClosethewebbrowsertostoptheapplicationandreturntoVisualStudio.
![Page 127: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/127.jpg)
ViewTheData
Wewillnowviewthedatathatwasloggedtothedatabase.
IntheSolutionExplorerinVisualStudio,right-clickonBotData.mdfandselectOpen.
ThiswillopentheServerExplorer.
Right-clickontheUserLogtableandselectShowTableData.
![Page 128: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/128.jpg)
Theloggeddatawillbedisplayed.
![Page 129: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/129.jpg)
LoggingHighScores
WewillnowaddcodetologanddisplayHighScores.
Wehavetoalterthedatabasefirsttostorethenumberofturnsrequiredtowinandthenameofthewinner.
IntheServerExplorer,right-clickontheUserLogtableandselectOpenTableDefinition.
Note:Ifyoudon’thavethisoption,installthelatestSQLServerDataTools(SSDT)fromhttps://msdn.microsoft.com/library/mt204009.aspx
![Page 130: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/130.jpg)
Addthefollowingfields:
CountOfTurnsToWin[int]WinnerUserName[nvarchar(150)]
ClicktheUpdatebutton.
WhenthePreviewDatabaseUpdatesboxshows,clickUpdateDatabase.
![Page 131: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/131.jpg)
TheDataToolsOperationswindowwillindicatewhentheupdateiscomplete.
![Page 132: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/132.jpg)
UpdateADO.NETEntityDataModel
WehavetoupdatetheADO.NETEntityDataModeltohaveprogrammaticaccesstothenewlyaddedfields.
IntheSolutionExplorer,clickonBotData.edmxtoopenitinthedesigner.
Inthedesigner,right-clickontheUserLogtableandselectUpdateModelfromDatabase.
![Page 133: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/133.jpg)
WhentheUpdateWizardshows,selecttheRefreshtabandthenselecttheUserLogtable.ClickFinish.
![Page 134: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/134.jpg)
AlterCodeToLogHighScores
WewillnowalterthecodeintheDialogclasstologthewinninguserandthenumberofturnstheyrequiredtowin.
IntheNumberGuesserDialog.csfile,locatethefollowingcode:
Addthefollowinglinesofcodebelowthecodeabove:
![Page 135: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/135.jpg)
![Page 136: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/136.jpg)
DisplayTheHighScores
WewillnowaddcodetodisplaytheHighScoreswhenevertheusertypesHighScores.
![Page 137: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/137.jpg)
OpentheMessagesController.csfileandaddthefollowingmethodtotheclass:
WewillnowaddthecodethatwillcalltheShowHighScoresmethodwejustadded.
IntheMessagesController.csfile,locatethefollowingcode:
Replaceitwiththefollowingcode:
![Page 138: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/138.jpg)
Finally,tolettheuserknowtheycantypeHighScorestoseethehighscores,findthefollowingcodeintheDialogclass:
Changeitto:
![Page 139: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/139.jpg)
TestTheCode
NowwhenwetypeHighScores,wecanseethehighscoresforthepastday.
TheimageaboveshowswhatthehighscoreslooklikewhentheBotispublishedandviewedthroughtheSkypeclient.
![Page 140: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/140.jpg)
PublishingAMicrosoftBotFrameworkApplicationThatUsesaDatabase
TopublishtheBot,wecanfollowthedirectionsinChapter2:CreateaHelloWorld!Bot.
However,unlikethischapter,thatchapterdoesnotcoverpublishingaBotthatusesadatabase.
IfyoudonothaveaMicrosoftAzureaccount,gotohttps://azure.microsoft.comandcreateanaccountandasubscription.
![Page 142: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/142.jpg)
Fillintheformtocreateanewdatabase.
Note:Ifyoudonotalreadyhaveaservertoputthedatabaseon,youwillbepromptedtocreateone.Atthattime,youwillcreateausernameandpassword.ThisistheusernameandpasswordyouwilluseintheconnectionstringtoconnecttothedatabasewhenyouusethedeploymentwizardinVisualStudio(coveredlater).
Afteryoucreatethedatabase,youcanviewtheADO.NET(SQLauthentication)connectionstringforthedatabaseintheOverviewsection.
![Page 143: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/143.jpg)
Note:Theconnectionstringwillnothavetheusernameandpassword.YouwillusetheusernameandpasswordoftheAzureserverthatcontainsthedatabase.
![Page 144: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/144.jpg)
IntheSolutionExplorerinVisualStudio,right-clickontheprojectnodeandselectPublish.
InthePublishwizard,filloutthefieldstopublishyourBottoAzure.
![Page 145: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/145.jpg)
OntheSettingstab:
1. SelectExcludefilesfromtheApp_Datafolder.ThiswillpreventtheBotData.mdfdatabasefilefrombeingpublishedtoAzure.Youaredoingthisbecausethe.mdffilecannotbeusedonAzure.
2. Entertheconnectionstringtothedatabase(runningonAzure)inBotDataEntities.YoucangettheADO.NET(SQLauthentication)connectionstringforthedatabaseintheOverviewsectionforthedatabaseintheAzureportal.Usethe“…”buttontohelpyouconnecttothedatabaseandconstructtheconnectionstring.
3. CheckUsethisconnectionstringatruntime.Thiswillupdatetheweb.configofthepublishedapplication,sothepublishedapplicationwillconnecttothedatabaseonAzure.
4. ClickthePublishbutton.
IntheServerExplorerinVisualStudio,right-clickonthedatabaseandselectOpeninSQLServerObjectExplorer.
Note:Ifyoudon’thavethisoption,installthelatestSQLServerDataTools(SSDT)fromhttps://msdn.microsoft.com/library/mt204009.aspx
![Page 146: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/146.jpg)
ThiswillopentheSQLServerObjectExplorer.
Right-clickontheTablesnodeunderthedatabaseandselectAddNewTable.
UsethefollowingscripttocreatetherequiredtableandclicktheUpdatebutton:
![Page 147: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/147.jpg)
WhenthePreviewDatabaseUpdatesboxshows,clickUpdateDatabase.
Note:YoucanalsousetheCloudExplorerforVisualStudio2015extensiontomanageyourAzuredatabasesinsideVisualStudio.
![Page 148: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/148.jpg)
![Page 149: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/149.jpg)
![Page 150: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/150.jpg)
Chapter7:ImplementingLanguageUnderstandingIntelligentService(LUIS)
Thesamplecodeforthischaptercanbeobtainedatthelink“ImplementingLanguageUnderstandingIntelligentService(LUIS)InMicrosoftBotFramework”athttp://AiHelpWebsite.com/Downloads
UsingLanguageUnderstandingIntelligentService(LUIS)inyourMicrosoftBotFrameworkapplicationallowsyoutocreatechatbotsthatareeasierforyourend-userstointeractwith.
Forthisexample,wewillstartwiththecodecreatedinthepreviouschapter.
![Page 151: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/151.jpg)
Thischaptercovershowtocreateanumberguessinggameandstoringanddisplayingthehighscores.Inthepreviouschapter,theuserisrequiredtotypeintheexactwordsHighScores,andtheycouldonlyseethehighscoresforthepastday.
Inthischapter,wewillalterthecodetoallowtheusertoseethehighscoresforthepastweek,thepastmonth,orthepastdaystheyspecify(upto30days).
Mostimportantly,wewillallowtheusertotypetheirrequestusingnormallanguageandthendetecttheintentoftheuserandtheimportantrelatedentities(suchasthenumberofdays).
WewilldothisbycreatinganapplicationusingtheLanguageUnderstandingIntelligentService(LUIS)andtheninterfacingthatapplicationwithourexistingBot.
![Page 152: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/152.jpg)
CreateTheLUISApplication
Thefirststepistogotohttps://www.luis.ai/andcreateanaccountontheLanguageUnderstandingIntelligentService(LUIS)siteandlogin.
CreateaNewApplication.
![Page 153: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/153.jpg)
WewillcallitHighScores,andafterfillingouttheotherfields,weclickAddApp.
NowweneedtocreateEntities.Theseareelementswewillneedtoidentifyandgather,soourBotcanperformoperationsbasedontheirvalue.Inourexample,wewanttocreatetwoEntities:
PeriodOfTime–Detectiftheuserenteredaworddescribingtheamountofdays(butnottheactualdays),forexample,weekormonthDays–Detectiftheuserenteredtheactualdayssuchas3orthree
ClicktheplusbuttonnexttotheEntitieslabel(ontheleft-handsideoftheeditor)toopenaboxthatwillallowyoutoaddeachEntity(oneatatime).
Whenyou’redone,theEntitieswillbedisplayed.
Next,wewilladdanIntent.
![Page 154: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/154.jpg)
Note:The“None”Intent,tobetriggeredwhenanutterancebytheuserdoesnotmatchaprogrammedintent,willbeautomaticallycreated)
ClicktheplusbuttonnexttotheIntentslabel.
EnterHighScoresfortheIntentname.
EnterShowmethehighscoresforthepastweekforEnteranexampleofacommandthattriggersthisintent.(Thisisalsoknownasasampleutterance.)
ClickSave.
TheutterancewillnowdisplayintheNewutterancestab.
WewantthisutterancetotriggertheHighScoresIntent,soselectitfromthedropdown.
![Page 155: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/155.jpg)
WealsowanttodetecttheassociatedEntity.
Clickonthewordweek,itwillthenbehighlighted,andapopupboxwillappear.
SelectPeriodOfTime.
Finally,clickSubmit.
Continuetoenterandlabeladditionalutterances.
Note:RemembertolabelanyEntitiesthatindicateanumberasDays.
![Page 156: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/156.jpg)
Continuetotraintheservice.
YouwillnoticethateventuallyitwillstartdetectingtheEntitiesonitsown.
However,manytimesyouwillstillhavetocorrectit.
Enterandcorrectatleasttendifferentutterances.
ClicktheTrainbuttoninthebottomleft-handcorneroftheinterfacetotrainthemodel.
![Page 157: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/157.jpg)
Next,clickthePublishbutton.
Finally,clickthePublishwebservicebutton.
Thepublishedend-pointwillbedisplayed.
MakenoteoftheAppIDandSubscriptionKey.YouwillneedtheselatertobeusedintheBotapplication.
![Page 158: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/158.jpg)
Note:Starting12/31/2016,AppIDwillnolongerbeused.YouwillonlyuseaSubscriptionKeytoconnecttoyourLUISapplication.
Note:Foraproductionapplication,youwillobtainyoursubscriptionkeyfromAzure.
Now,weneedtoupdatetheBottocalltheLUISservice…
![Page 159: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/159.jpg)
UpdateTheBotApplication
OpentheprojectfromthepreviouschapterinVisualStudio.
![Page 160: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/160.jpg)
AddanewfilecalledLUISDialogClass.cs,usingthefollowingcode:
ThiscodewillpasstextenteredintotheBottotheLUISapplicationandtriggertheNoneorHighScoresmethodsbasedonwhattheLUISapplicationdeterminestheIntentis,whichtheenteredtextmatches.
![Page 161: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/161.jpg)
WedecorateeachmethodwithaLuisIntentdecoration,settingthenameofanIntent(forexample,[LuisIntent(“HighScores”)])toindicatewhichmethodshouldbetriggered.
Note:Thecodeisnotcompleteatthispoint.Wewillcompletethecodeinlatersteps.
EnsurethatyouentertheAppIDandSubscriptionKeyfromyourLUISapplicationintheLuisModeldecorationatthetopoftheclass.
ThisishowthecodeknowswhatLUISapplicationtoconnectto.
WenowneedtocalltheLUISDialogClass,insteadofthepreviouslyconfiguredNumberGuesserDialogclass,whenausercommunicateswiththeBot.
ThenewLUIScode(LUISDialogClass)willcalltheNumberGuesserDialogclasswhenneeded,forexample,whentheuserhasnottriggeredtheHighScoresintent.
OpentheMessagesController.csfileintheControllersfolder.
Replacethefollowingcode:
![Page 162: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/162.jpg)
With:
![Page 163: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/163.jpg)
ThereareplaceswheretheNumberGuesserDialogwillneedtocallLUISDialogClass,forexample,whentheuserhasenteredaresponsethatisnotanumberbeingguessedaspartofthegame.
TheNumberGuesserDialogclasswillneedtoreturncontrolbacktotheLUISDialogClass.
ReplacethecodeintheNumberGuesserDialogclass(encapsulatedinthebrackets)thatbeginslikethetextbelow:
![Page 164: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/164.jpg)
Withthefollowingcode:
TheNumberGuesserDialogclassisnolongertherootclass,sowewillneedtoalteritslightlyagain,soitstartsupthegameproperlywhenitistriggeredbytheLUISDialogClass.
LocatethefollowingcodeintheStartAsyncmethod:
![Page 165: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/165.jpg)
![Page 166: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/166.jpg)
Replaceitwith:
Thiscodeshowsthewelcomescreentostartthenumberguessinggame.
![Page 167: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/167.jpg)
ImplementHighScores
Atthispoint,ifweruntheapplicationandconnecttoitintheMicrosoftBotFrameworkEmulator,wecanplaythegame.
However,ifwetypeanythingthattriggerstheHighScoresLUISIntent,wewillreceiveanerrorbecausethecodetohandlethishasnotbeenimplementedyet.
OpentheLUISDialogClass.csfileandlocatethefollowingcode:
![Page 168: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/168.jpg)
![Page 169: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/169.jpg)
Replaceitwith:
Thiscodewillsetthenumberofdaystheuserisaskingthehighscorestoinclude.Itfirsttriestodetectifaperiodoftimewaspassed(inthePeriodOfTimeentity).Ifithasbeen,thecodeconvertsaknownperiodoftimetoanumberofdays.
Ifanumberofdayswaspassed(intheDaysentity),thecodetriestoconvertthedaysintoanumber.Ifitcannot,itassumesthenumberofdayswaspassedasawordnotanumber.Ifthisisthecase,itpassesthevaluetotheParseEnglishmethodthatconvertsthewordtoanumber.
Note:YoucangettheParseEnglishmethodfromhttp://stackoverflow.com/questions/11278081/convert-words-string-to-int
Thenumberofdays(andthecurrentcontext)isthenpassedtotheShowHighScoresmethod.
![Page 170: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/170.jpg)
Asthefinalstep,enterthefollowingcodetoimplementtheShowHighScoresmethodintotheLUISDialogClass:
![Page 171: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/171.jpg)
![Page 172: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/172.jpg)
![Page 173: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/173.jpg)
Chapter8:CallingTheMicrosoftBotFrameworkUsingTheDirectLineAPI
Thesamplecodeforthischaptercanbeobtainedatthelink“CallingTheMicrosoftBotFrameworkUsingTheDirectLineAPI”athttp://AiHelpWebsite.com/Downloads
YoumayneedtocallyourMicrosoftBotFrameworkBotdirectlyfromacustomapplication,aservice,orawebsite.TheMicrosoftBotConnectorDirectLineRESTAPIallowsyoutodothis.Inaddition,itallowsyoutoauthenticateauserinyourapplicationandsecurelycommunicatewiththeBotasthatuser.
TheDirectLineAPIexposesaRESTAPIthatallowsyoutocommunicatewithasingleBotthathasbeenregisteredwiththeMicrosoftBotConnectorService.
ThisAPIisintendedfordeveloperswhowanttocommunicatewiththeirBotfromtheirownclientapplications,suchasmobileapps,aservice,orevenaHoloLens.
![Page 174: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/174.jpg)
TheprocedureforworkingwiththeAPIis:
1. RegisteryourBotwiththeBotFrameworkDeveloperPortal2. ConfiguretheDirectLineConnector3. UsethecredentialsobtainedfromtheBotFrameworkDeveloperPortaltomake
RESTbasedcallstocommunicatewiththeBotInourexample,wewillusetheMicrosoft.Bot.Connector.DirectLineNugetpackagetohelpusmakethecalls.
Note:TherenderingoftheoutputwillbetheresponsibilityofthedeveloperofthecustomapplicationthatiscallingtheDirectLineAPI.
![Page 175: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/175.jpg)
Mediasuchanimages,cards,andbuttonswillrequirecustomcodetorenderinamannerthatisappropriatefortheparticularapplication.
Theexampleapplicationwewillbuildwillcreateacustomclientthatwillallowausertocreateanaccount,sign-in,andsecurelycommunicatewiththeBotthatwascreatedinthepreviouschapter.
![Page 176: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/176.jpg)
ConfiguringTheDirectLineConnector
WewanttoconfiguretheDirectLineconnectorforourBot.
Gotohttps://dev.botframework.com/,login,andselectMyBots.
OpenaBotthathasbeendeployedtotheMicrosoftBotFrameworkDeveloperPortal.
ThefirststepistomakeanoteoftheBothandleyougaveyourBot.YouwillneedthislaterwhenyoucreatetheWebApplication.
![Page 177: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/177.jpg)
UnderAddanotherchannel,clicktheAddbuttonnexttoDirectLine.
WhentheConfigureDirectLinescreenappears,clicktheGenerateDirectLinesecretbutton.
![Page 178: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/178.jpg)
CopytheSecretcode.YouwillneedthislaterwhenyoucreatetheWebApplication.
ClickI’mdoneconfiguringDirectLinebutton.
Thescreenwillclose.
![Page 179: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/179.jpg)
CreateTheWebApplication
OpenVisualStudio.
FromthetoolbarinVisualStudio,selectFile,thenNew,andthenProject.
SelectWebandthenASP.NETWebApplication(.NetFramework).
EnterDirectLineBotfortheName.
SelecttheCreatedirectoryforsolutionbox.
PressOK.
![Page 180: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/180.jpg)
Whentheapplicationconfigurationboxappears,selecttheMVCtemplate.
EnsurethatIndividualUserAccountsisselectedforAuthentication.Ifnot,clicktheChangeAuthenticationbuttonandchangeit.
PressOK.
Theapplicationwillbecreated.
WeneedtoaddtheMicrosoft.Bot.Connector.DirectLineNuGetPackagethatwillallowustoeasilycommunicatewiththeDirectLineAPI.
![Page 181: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/181.jpg)
IntheSolutionExplorer,right-clickontheDirectLineBotprojectnode(nottheSolutionnode),andselectManageNuGetPackages.
WhentheNuGetPackageconfigurationwindowappears,clicktheBrowsebutton.
EnterMicrosoft.Bot.Connector.DirectLineinthesearchboxtoconductthesearch.
WhentheMicrosoft.Bot.Connector.DirectLinepackageshowsup,clickonit,soits
![Page 182: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/182.jpg)
propertiesappearinthewindowontheright.
ClicktheInstallbuttontoinstallthepackage.
ClickOKwhenthePreviewwindowshows.
ClicktheIAcceptbuttonwhentheLicenseAcceptancewindowappears.
![Page 183: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/183.jpg)
TheMicrosoft.Bot.Connector.DirectLineassemblywillbeinstalled.
HitF5todebugandruntheapplication.
Theapplicationwillopeninthewebbrowser.
YouwillseethedefaultwebapplicationcreatedbytheMVCtemplate.
![Page 184: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/184.jpg)
WecanclicktheRegisterbuttontocreateanewaccount.
WecanalsoclicktheLoginbuttontologinusingaregisteredaccount.
![Page 185: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/185.jpg)
CompleteTheWebApplication
WewillupdatethehomepagetoshowthechatboxandtheBotresponseonlyiftheuserhascreatedanaccountandloggedin.
StopdebuggingtheapplicationandopentheIndex.cshtmlfileintheViews/Homefolder.
Replaceallofthecodewiththefollowingcode:
![Page 186: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/186.jpg)
![Page 187: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/187.jpg)
OpentheHomeController.csfileintheControllersfolder,andreplaceallthecodewiththefollowingcode:
Atthispointthecodeisnotcomplete;however,itsetsupthebasicframework.
Replace**INSERTYOURSECRETCODEHERE**and**INSERTYOURBOTIDHERE**withthevaluesfromyouownpublishedBot.
WhenaloggedinuserloadsthepageorsubmitstexttotheBot,theTalkToTheBotmethodiscalled.
Toimplementit,addthefollowingmethodtotheHomeControllerclass:
![Page 188: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/188.jpg)
TheTalkToTheBotmethodcallstheReadBotMessagesAsyncmethodtoreadtheresponsefromtheBot.
Toimplementit,addthefollowingmethodtotheHomeControllerclass:
![Page 189: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/189.jpg)
WhenthereisanimagethatisreturnedbytheBot,theReadBotMessagesAsyncmethodcallstheRenderImageHTMLmethod.
Toimplementit,addthefollowingmethodtotheHomeControllerclass:
![Page 190: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/190.jpg)
![Page 191: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/191.jpg)
RunTheApplication
HitF5toruntheapplication.
Theapplicationwillopeninthewebbrowser.Initially,wearenotloggedin,sowewillbeunabletocommunicatewiththeBot.
ClicktheRegisterbuttontocreateanaccount.
![Page 192: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/192.jpg)
FillintherequiredinformationandclicktheRegisterbutton.
Afteryouhavecreatedanaccount,youcanclicktheLoginbuttontologin(ifyouarenotalreadyloggedin).
YouwillknowyouareloggedinwhenyouseeyouremailaddressinthemenubarandontheHomepage.
![Page 193: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/193.jpg)
YoucannowcommunicatewiththeBotandrunthesamecodethatwascreatedinthepreviouschapter.
![Page 194: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/194.jpg)
WhenwelookatthedatainthedatabaseonAzure,weseetheUserIDandUserNameformessagespostedtotheBotarecompletelyunderthecontrolofthefollowingcustomcode:
![Page 195: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/195.jpg)
![Page 196: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/196.jpg)
![Page 197: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/197.jpg)
Chapter9:UsingApplicationInsightsToMonitorYourBot
Thesamplecodeforthischaptercanbeobtainedatthelink“UsingApplicationInsightsWithMicrosoftBotFramework”athttp://AiHelpWebsite.com/Downloads
WithApplicationInsights,youcaninsertafewlinesofcodeinyourBottofindoutwhatyourusersaredoing.
WhenyouinstallApplicationInsights,youareinstallingasmallinstrumentationpackageinyourapplication.Next,yousetupanApplicationInsightsresourceintheMicrosoftAzureportal.
TheinstrumentationyouinstallmonitorsyourappandsendstelemetrydatatotheMicrosoftAzureportal.TheMicrosoftAzureportalshowsstatisticalchartsandhaspowerfulsearchtoolstohelpyoumonitoryourapplicationanddiagnoseanyproblems.
![Page 198: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/198.jpg)
Todemonstratethis,wewillstartwiththeBotcreatedinChapterSix.
![Page 199: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/199.jpg)
ThiswillrequireusingMicrosoftAzure.IfyoudonothaveaMicrosoftAzureaccount,gotohttps://azure.microsoft.comandcreateanaccountandasubscription.
![Page 200: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/200.jpg)
EnableApplicationInsights
OpentheAiNumberGuesserBotprojectinVisualStudio.
IntheSolutionExplorer,right-clickontheProject(nottheSolution),andselectAddApplicationInsightsTelemetry.
First,youwillberequiredtologintoyourMicrosoftAzureAccount.
![Page 201: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/201.jpg)
Afterdoingso,youwillbepresentedwithaformtocreateanApplicationInsightsresource(bychoosingtheNewresourceoptionintheSendtelemetrytodropdown)orconnecttoanexistingApplicationInsightsresource(byselectingitintheSendtelemetrytodropdown).
Afterselectingtheconfigurationoptions,clicktheAddbuttontoproceed.
![Page 202: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/202.jpg)
ApplicationInsightsassemblieswillbeaddedtotheproject.
Ifyougetanerror,mostlikelyyouhavecomponentsthatneedtobeupdated.
![Page 203: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/203.jpg)
IntheSolutionExplorerinVisualStudio,right-clickontheProject(nottheSolution),andselectManageNuGetPackages.
SelectUpdates,selectthecomponentsthattheerrormessageindicatesneedtobeupdated,andclicktheUpdatebutton.
![Page 204: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/204.jpg)
WhentheReviewChangesboxshows,clicktheOKbutton.
Next,right-clickontheProjectandselectAddApplicationInsightsTelemetryagaintore-starttheprocess.
TheApplicationInsightscomponentsshouldnowinstallsuccessfully.
![Page 205: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/205.jpg)
DebugTheApplication
Beforeyoutrytodebug,clearanyMicrosoftAppIdandMicrosoftAppPasswordsettingstheremaybeintheWeb.configfileandthensavethefile.
Thisisrequired,soyoucaneasilydebuglocally.
Remembertoreplaceanysettingsifyouneedtore-publishtheapplication.
HitF5toruntheproject.
![Page 206: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/206.jpg)
Theapplicationwillopeninthewebbrowser.
Notethewebaddress,asyouwillneeditinthenextstep.
![Page 207: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/207.jpg)
UsingTheBotEmulator
OpenandruntheMicrosoftBotFrameworkEmulator.
Whentheemulatorstarts,connecttotheBotbysettingtheaddresstotheoneindictedinthewebbrowser;however,add/api/messagestotheend.
IntheBotEmulator,enterHellointhetextboxandclickthesendkey(orpressenter).
YouwillseetheresponseintheChatwindowandtheJSONcontentsoftheresponseintheJSONwindow.
![Page 208: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/208.jpg)
Youshouldseeawindowpopupthatprovideslinkstothetelemetrydata.
YoucanalsoaccessthedatabyclickingonthelinksintheApplicationInsight.configsectionintheSolutionExplorerofVisualStudiowhiletheapplicationisrunning.
![Page 209: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/209.jpg)
Also,youcanright-clickontheProjectandselectApplicationInsightstoshowthemenuthatwillprovidealltheoptions.
SelectingSearchLiveTelemetryorSearchDebugSessionTelemetrywillopenawindowinVisualStudiothatwilldisplaytelemetrydata.
![Page 210: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/210.jpg)
Note:SeeLearnmoreaboutApplicationInsightstoolsinVisualStudioathttps://azure.microsoft.com/en-us/documentation/articles/app-insights-visual-studio/formoreinformationonusingthesewindows.
![Page 211: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/211.jpg)
ForfullTelemetryReadiness,ensureallthegreendotsarechecked.Ifanyaren’t,clickonthem.
Itwillstopdebuggingtoaddcomponents.
Youwillbeabletoclickabuttontoaddorconfigurethecomponents.
![Page 212: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/212.jpg)
Thecomponentswillbeadded.
Theresultwillbedisplayed.
![Page 213: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/213.jpg)
CustomTelemetry
OneofthemostpowerfulfeaturesofApplicationInsightsisbeingabletouseittotrackyourowncustomtelemetry.
Wewillnowdemonstrateusingittotrackwhenagameisstarted,completed,whatnumberauserneededtoguess,andhowmanyattemptstheyrequired.
![Page 214: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/214.jpg)
IntheAiNumberGuesserBotproject,opentheNumberGuesserDialog.csfileandaddthefollowingusingstatements:
Next,addthefollowinglinetotheclass:
Finally,addthefollowinglinestotheStartAsyncmethod:
Thiswilltrackagamebeingstartedandthenumbertheuserneedstoguess.
![Page 215: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/215.jpg)
Also,addthefollowingcodetotrackthegamecompleted:
ThereareanumberofAPIcallswecanusetotrackcustomeventsasthefollowingtableillustrates:
![Page 216: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/216.jpg)
ApplicationInsightsAPIsummary
From:https://azure.microsoft.com/en-us/documentation/articles/app-insights-api-custom-events-metrics/
Method Usedfor
TrackPageView Pages,screens,blades,orforms
TrackEvent Useractionsandotherevents.Usedtotrackuserbehaviorortomonitorperformance.
TrackMetric Performancemeasurementssuchasqueuelengthsnotrelatedtospecificevents
TrackException Logexceptionsfordiagnosis.Tracewheretheyoccurinrelationtoothereventsandexaminestacktraces.
TrackRequest Logthefrequencyanddurationofserverrequestsforperformanceanalysis.
TrackTrace Diagnosticlogmessages.Youcanalsocapture3rd-partylogs.
TrackDependency Logthedurationandfrequencyofcallstoexternalcomponentsonwhichyourappdepends.
Youcanattachpropertiesandmetricstomostofthesetelemetrycalls.
Runtheapplicationandentersomesampledata.
![Page 217: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/217.jpg)
WhenyouselecttheApplicationInsightsmenuinVisualStudioandselectExploreTelemetryTrends…
…youcanthenselectInspectyourcustomevents.
![Page 218: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/218.jpg)
ClicktheAnalyzeTelemetrybuttontoprocessthelatestdata.YouwillseewherethePropertiesandMetricshavebeentracked.
Note:Itwilltakeafewminutesforyourcustomeventstoshow.
Youcandouble-clickonatrendtodrillintothedata.
Thiswilltakeyoutothesearchscreenwhereyoucanfilterfurtherandviewthedetailsofeachindividualevent.
![Page 219: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/219.jpg)
ApplicationInsightsPortal
YoucanaccesstheApplicationInsightsPortalontheMicrosoftAzuresitebyselectingitfromthemenuinVisualStudio.
ItisthereyoucanseeandchangeyourPricingtier.
YoucanalsoobtainyourInstrumentationKey.
![Page 220: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/220.jpg)
![Page 221: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/221.jpg)
MonitoringAPublishedApplication
YoucanmonitoryourpublishedBot.
PublishyourBot.(SeeChapter2fordirectionsonthis.)AfteryourBotispublishedonthehttps://dev.botframework.com/site,selectMybots.
EdittheBotconfiguration.
![Page 222: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/222.jpg)
EntertheInstrumentationKey(fromtheMicrosoftAzuresite)andclickSavechanges.
Thiswillenableadditionalpropertiesandmetricstotrack.
ReturntotheApplicationInsightsresourceontheMicrosoftAzuresite.
Youcannowmonitoryourpublishedapplicationandcreatecustomchartsusingdefaulttrackingdataandyourcustompropertiesandmetrics.
![Page 223: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/223.jpg)
![Page 224: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/224.jpg)
![Page 225: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/225.jpg)
Chapter10:CreatingaSkypeBot
Thesamplecodeforthischaptercanbeobtainedatthelink“CreatingaSkypeBotUsingTheMicrosoftBotFramework”athttp://AiHelpWebsite.com/Downloads
YoucaneasilycreateaSkypeBotanddeployittoSkype.
Todemonstratethis,wewillstartwiththeBotcreatedinChapterSix.
Note:IfyouhavenotpreviouslydeployedyourBot,skipdowntothesectionlabeled
![Page 226: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/226.jpg)
“RegisterSkype”.
![Page 227: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/227.jpg)
PublishingTheBot
ThefirststepistoconnecttheAiNumberGuesserBottotheMicrosoftBotFrameworkDeveloperPortal.
Todothis,weneedtopublishitinapublicallyaccessiblelocation.Thiscanbeanyserver;however,publishingtoAzureisrecommendedbecausepublishingtoithasbuilt-insupportinVisualStudio.
First,gotohttps://azure.microsoft.comandcreateanaccountandasubscription(ifyoudon’talreadyhaveone).
![Page 228: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/228.jpg)
Next,opentheAiNumberGuesserBotprojectinVisualStudioandright-clickontheProjectnode(nottheSolutionnode),andselectPublish.
SelectMicrosoftAzureAppService.
![Page 229: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/229.jpg)
SignintoyourAzureaccountandthenclicktheNewbutton.
EnsurethetypeisWebApp.
EnterauniqueWebAppname,selectyoursubscription,selectorcreateaserviceplanandresourcegroupandclicktheCreatebutton.
![Page 230: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/230.jpg)
Afterthewebapphasbeencreated,clickthePublishbutton.
Thewebappwillopeninthewebbrowser.
Notethewebaddressasyouwillneeditinalaterstep.
![Page 231: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/231.jpg)
RegisteringTheBotWithTheBotConnector
GototheMicrosoftBotFrameworkportalathttp://dev.botframework.comandsigninwithyourMicrosoftAccount.
SelectRegisterabot.
![Page 232: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/232.jpg)
Fillinallofthefields.
![Page 233: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/233.jpg)
Note:Theendpointwebaddressiswhatyousawwhenthewebbrowseropenedinthepreviousstep.
However,youhavetoadd/api/messagestotheendoftheaddressandusehttps://ratherthanhttp://.
Atonepointintheform,youwillseealinkyouwillclicktogoto
https://apps.dev.microsoft.com
ItistherethatyouwillgetanApplicationIDandapassword.
![Page 234: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/234.jpg)
Makeanoteofthembecauseyouwillneedtousethemtoupdatetheweb.configfileintheVisualStudioprojectlater.
ClicktheRegisterbutton.
TheBotregistrationwillbecreated.
Whenyoureturntothehttp://dev.botframework.compage,youwillseetheMicrosoftAppIDfromthehttps://apps.dev.microsoft.comsitehasbeenenteredintoyourBot’sconfiguration.
![Page 235: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/235.jpg)
CopytheBotID(Bothandle)andMicrosoftAppIdandMicrosoftAppPasswordfromhttp://dev.botframework.comandhttps://apps.dev.microsoft.comtotheweb.configoftheBotinVisualStudio.
Note:IfyouforgottonotetheMicrosoftAppPasswordintheearlierstep,youcanclicktheGenerateNewPasswordbuttonathttps://apps.dev.microsoft.comtocreateanotherone.
InVisualStudio,PublishtheBotagain.
YouaredoingthisbecausetheBotConnectorwillpasstheBotIDandMicrosoftAppIdandMicrosoftAppPasswordwhenitcommunicateswithit.
![Page 236: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/236.jpg)
ReturntotheBotconfigurationpageathttp://dev.botframework.com.
YoucannowclicktheTestbuttononthatpagetotesttheconnectiontoyourBot.
YoucannowconfigurechannelstoyourBot.
Whenyouhaveconfiguredchannels,ifyoudesire,youcanclickthePublishbuttontosubmityourbottotheBotDirectory.
EvenifyoudonotpublishittotheBotDirectory,youcanstillcallitfromyourown
![Page 237: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/237.jpg)
applicationsandthroughanychannelsyouconfigure.
![Page 238: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/238.jpg)
ConfigureSkype
ToaddtheBottoSkype,clicktheAddtoSkypebuttonontheBotconfigurationpageathttp://dev.botframework.com.
YouwillbedirectedtoaSkypeconfigurationpagefortheBot.
ClickthebuttontoAddtoContacts.
![Page 239: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/239.jpg)
ClickAllowinthepopupbox.
Skypewillopen,andyoucanselecttheBotfromyourcontactsandconversewithit.
![Page 240: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/240.jpg)
![Page 241: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/241.jpg)
![Page 242: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/242.jpg)
Chapter11:CreatingAFacebookMessengerBot
Thesamplecodeforthischaptercanbeobtainedatthelink“CreatingAFacebookBotUsingMicrosoftBotFramework”athttp://AiHelpWebsite.com/Downloads
YoucaneasilycreateaBotanddeployitonFacebook.
![Page 243: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/243.jpg)
Todemonstratethis,wewillstartwiththeBotcreatedinChapterTwo.
![Page 244: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/244.jpg)
Set-UpFacebook
ThefirststepistologintoyourFacebook.comaccount(orcreateone).
SelectCreatePage.
Selectatemplate,fillintherequiredinformation,andclickGetStarted.
![Page 245: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/245.jpg)
TogettheFacebookPageID,whichyouwillneedlater,clickontheAbouttab.
![Page 246: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/246.jpg)
LocatetheFacebookPageID.
![Page 247: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/247.jpg)
![Page 248: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/248.jpg)
CreateAFacebookDeveloperAccount
Gotohttps://developers.facebook.com/docs/apps/registerandclickthebuttontocreateaFacebookDeveloperAccount.
ClicktheslidertoYestoacceptthepoliciesandclickRegister.
![Page 249: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/249.jpg)
![Page 250: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/250.jpg)
CreateAFacebookApp
Next,gotohttps://developers.facebook.com/andloginagainifneeded.
SelectAddaNewApp.
Selectbasicsetup.
![Page 251: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/251.jpg)
FillintheinformationandclickCreateAppID.
MakeanoteoftheAppIDasyouwillneeditinalaterstep.
ClicktheShowbuttontodisplaytheAppSecret.Makeanoteofitasyouwillneeditinalaterstep.
![Page 252: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/252.jpg)
NowthattheAppiscreated,youneedtoconfigureittouseFacebookMessenger.
ClickAddProduct.
SelectMessenger.
SelectGetStarted.
![Page 253: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/253.jpg)
FacebookMessengerhasbeenadded.
YounowneedtoconfigureittotalktotheMicrosoftBotConnector.
![Page 254: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/254.jpg)
ConfigureTheCallbackURLandVerifyToken
Gotohttps://dev.botframework.com/andSignin.
SelectMybots.
Selectapublishedbot.(SeeChapterTwofordirectionsonhowtodothis.)
![Page 255: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/255.jpg)
ClicktheAddbuttonnexttotheFacebookMessengerchannel.
ClicktheexpandernexttoSetwebhookcallbackurlandverifytoken.
![Page 256: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/256.jpg)
UsetheSelectbuttonstoindividuallyselectandcopytheCallbackUrlandVerifyToken.
Returntohttps://developers.facebook.com,selectyourapplication,andinthesettingsforMessenger,clicktheSetupWebhooksbutton.
EntertheCallbackURLandVerifyTokenyoucopied,checktheSubscriptionFieldsindicatedintheimageabove,andclicktheVerifyandSavebutton.
AftertheWebhookshavebeenset,clickthedropdownnexttoSelectaPage.
![Page 257: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/257.jpg)
SelecttheFacebookpageyoucreatedearlier.
Next,clicktheSubscribebutton.
![Page 258: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/258.jpg)
GetPageToken
IntheTokenGenerationsection,selectthepagethatyoupreviouslycreated.
APageAccessTokenwillbecreated.
CopythePageAccessToken.
![Page 259: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/259.jpg)
ConfigureTheMicrosoftBotConnector
Returntohttps://dev.botframework.com/andselectyourBotagain.ThenclicktheEditbuttonnexttotheFacebookMessengerchannel.
ClicktheexpandernexttoEnteryourcredentials.
EntertheinformationyougatheredintheearlierstepsandclicktheResubmitbutton.
ChecktheboxnexttoEnablethisbotonFacebookMessenger.
ClickI’mdoneconfiguringFacebookMessengerbutton.
![Page 260: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/260.jpg)
TalkingToYourBot
YoucannowtalktoyourBotbynavigatingto
https://www.messenger.com/t/{YourPageID}/
ThiswilltakeyoutoFacebookMessenger,andafterlogginginwithyourFacebookID,itwillallowyoutoconversewithyourBot.
UntilyourAppisapprovedandmadepublic,onlyyoucanchatwithyourBot.
Tocreateaccountstotestit,gotohttps://developers.facebook.com/s
![Page 261: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/261.jpg)
SelecttheAppandthenselectRolesandthenTestUsers.
Fillintheformthatdisplaystocreatetestusers.
ToallowrealFacebookuserstotestit,selectRolesandthenAddTesters.
Fillintheformthatdisplaystoallowaccessfortheusers.
TomaketheBotpublic,selectAppReview.ThenclicktheslidertochangeitfromNotoYes.
![Page 262: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/262.jpg)
Torequesttheneededpermissions,selectSettingsunderMessengerthenclicktheRequestPermissionsbutton.
![Page 263: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/263.jpg)
Selectpages_messagingandthenclicktheAdd1Itembutton.
SeethispageformoreinformationontheAppreviewprocess
https://developers.facebook.com/docs/messenger-platform/app-review
![Page 264: An Introduction to the Microsoft Bot Framework: Create Facebook and Skype Chatbots using Microsoft Visual Studio and C# - By Michael Washington - Year 2016 - Publisher CreateSpace](https://reader034.vdocument.in/reader034/viewer/2022051006/58e543f11a28ab3a468b4dfb/html5/thumbnails/264.jpg)
AboutTheAuthor
MichaelWashingtonisanASP.NET,C#,andVisualBasicprogrammer.Hehasextensiveknowledgeinprocessimprovement,billingsystems,andstudentinformationsystems.HeisaMicrosoftMVP.Hehasason,Zachary,andresidesinLosAngeleswithhiswife,Valerie.
Hehaswrittenseveraltutorialsthatarepostedathttp://AiHelpWebsite.com/Blog.
Heistheauthorofsixpreviousbooks:
CreatingHTML5WebsitesandCloudBusinessAppsUsingLightSwitchInVisualStudio2013-2015(LightSwitchHelpWebsite.com)CreatingWebPagesUsingtheLightSwitchHTMLClientInVisualStudio2012(LightSwitchHelpWebsite.com)ODataAndVisualStudioLightSwitch(LightSwitchHelpWebsite.com)CreatingVisualStudioLightSwitchCustomControls(BeginnertoIntermediate)(LightSwitchHelpWebsite.com)BuildingWebsiteswithVB.NETandDotNetNuke4(PacktPublishing)BuildingWebsiteswithDotNetNuke5(PacktPublishing)