%3CLINGO-SUB%20id%3D%22lingo-sub-1821877%22%20slang%3D%22en-US%22%3EHow%20bots%20work%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1821877%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20bot%20developers%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20have%20recently%20decided%20to%20write%20blogposts%20about%20Bot%20framework%20technology%20to%20reflect%20my%20perspective%20on%20the%20subject%2C%20provide%20ideas%20on%20how%20it%20works%20and%20to%20troubleshoot%20common%20scenarios.%20The%20best%20start%20for%20this%2C%20is%20to%20make%20a%20good%20definition%20of%20%22Bot%20Framework%20SDK%22%2C%20and%20in%20general%20%22Azure%20Bot%20Service%22%2C%20that%20Microsoft%20offers.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EApart%20from%20the%20fancy%20description%20%3CA%20title%3D%22Bot%20Service%20Introduction%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Fbot-service-overview-introduction%3Fview%3Dazure-bot-service-4.0%23what-is-a-bot%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%2C%20a%20bot%20can%20be%20defined%20as%20an%20application%20%2C%20which%20uses%20%22Bot%20Builder%22%20and%26nbsp%3B%20%22Bot%20Connector%22%20libraries%2C%20to%20communicate%20through%20the%20Connector%20services%20and%20channels.%20While%20doing%20that%2C%20the%20dependent%20services%20being%20used%20on%20that%20bot%20application%2C%20like%20%22LUIS%22%20(%3CA%20title%3D%22Language%20Understanding%20Intelligent%20Service%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fcognitive-services%2Fluis%2Fwhat-is-luis%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ELanguage%20Understanding%20Intelligent%20Service%3C%2FA%3E)%20or%20%22%3CA%20title%3D%22What%20is%20QnA%20Service%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fcognitive-services%2Fqnamaker%2Foverview%2Foverview%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EQnA%20Service%3C%2FA%3E%22%2C%20makes%20the%20bot%20behave%20like%20an%20intelligent%20entity%2C%20since%20it%20will%20be%20able%20to%20understand%20your%20intentions%20easily%20and%20reply%20to%20them.%20All%20the%20communication%20between%20the%20human%20and%20the%20bot%2C%20is%20packaged%20into%20a%20serializable%20JSON%20based%20objects%20called%20%22%3CA%20title%3D%22Activity%20Processing%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Fbot-builder-concept-activity-processing%3Fview%3Dazure-bot-service-4.0%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EActivity%3C%2FA%3E%22%2C%20and%20it%20flows%20through%20different%20%3CA%20title%3D%22connect%20to%20different%20channels%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Fbot-service-manage-channels%3Fview%3Dazure-bot-service-4.0%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Echannels%3C%2FA%3E.%20%22Bot%20Builder%22%20libraries%20create%20a%20reply%20%22Activity%22%20to%20these%20incoming%20%22Activity%22%20objects%2C%20considering%20the%20state%20of%20%22Conversations%22%20and%20%22Dialogs%22%2C%20to%20provide%20you%20meaningful%20suggestions%20based%20on%20your%20previous%20interactions.%20Most%20popular%20type%20of%20an%20%22Activity%22%20is%20a%20%22Message%22%2C%20but%20activities%20can%20also%20provide%20meta%20information%2C%20like%20adding%2Fremoving%20users%20to%20a%20conversation.%20When%20activity%20reach%20out%20to%20bot%2C%20it%20will%20be%20put%20inside%20a%20%22TurnContext%22%20object%2C%20together%20with%20the%20%3CA%20title%3D%22State%20Concept%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Fbot-builder-concept-state%3Fview%3Dazure-bot-service-4.0%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Estate%20information%3C%2FA%3E%20of%20User%20and%20dialog.%20A%20Turn%20context%20%2C%20will%20be%20processed%20by%20the%20bot%20code%2C%20and%20it%20will%20be%20valid%20until%20the%20Turn%20of%20the%20bot%20is%20completed.%20You%20can%20find%20the%20activity%20processing%20stack%20with%20a%20nice%20diagram%20%3CA%20title%3D%22Activity%20Processing%20Stack%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Fbot-builder-basics%3Fview%3Dazure-bot-service-4.0%26amp%3Btabs%3Dcsharp%23the-activity-processing-stack%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%20if%20you%20want%20to%20see%20more%20on%20the%20activity%20processing.%26nbsp%3B%20Note%20that%2C%20these%20diagrams%20focus%20on%20the%20bot%20side%20of%20the%20communication%20and%20abstract%20the%20channel%2Fconnector%20side.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3BTo%20get%20more%20acquainted%20with%20the%20conversation%20based%20Bot%20communication%2C%20I%20can%20recommend%20you%20to%20start%20reviewing%20the%20REST%20API's%20documented%20%3CA%20title%3D%22REST%20Connector%20API%20Reference%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Frest-api%2Fbot-framework-rest-connector-api-reference%3Fview%3Dazure-bot-service-4.0%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%20Also%2C%20you%20can%20surf%20inside%20the%20%3CA%20title%3D%22Bot%20Builder%204.0%20Namespace%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fmicrosoft.bot.builder%3Fview%3Dbotbuilder-dotnet-stable%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EBot%20Builder%204.0%20Namespace%3C%2FA%3E%2C%20to%20understand%20what%20an%20activity%20object%20is%2C%20or%20how%20a%20%3CA%20title%3D%22TurnContext%20object%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fmicrosoft.bot.builder.turncontext%3Fview%3Dbotbuilder-dotnet-stable%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ETurnContext%20object%3C%2FA%3E%20relates%20with%20an%20activity%2C%20etc.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20finish%20the%20definition%20part%20here%20and%20If%20you%20want%20to%20play%20around%20with%20bots%2C%20you%20can%20start%20creating%20bots%2C%20and%20try%20understanding%20how%20they%20work.%20Assuming%20that%20you%20have%20an%20active%20Azure%20Subscription%2C%20you%20can%20deploy%20your%20bot%20to%20Azure%20or%20alternatively%20you%20can%20use%20our%20%22Bot%20Framework%20Emulator%22%20tool%2C%20to%20debug%20to%20bots%20locally.%20For%20the%20latter%2C%20I%20can%20give%20you%20a%20recipe%20below%2C%20to%20start%20with%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%231%20-%20Clone%20the%20Bot%20%3CA%20title%3D%22Builder%20samples%20repo%22%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FBotBuilder-Samples%2Ftree%2Fmain%2Fsamples%2Fcsharp_dotnetcore%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EBuilder%20samples%20repo%3C%2FA%3E%20to%20get%20all%20available%20samples.%20In%20my%20posts%2C%20I%20will%20mostly%20use%20%22dotnet%20core%22%20based%20samples%2C%20since%20I%20am%20more%20used%20to%20work%20with%20that%20language.%20But%20we%20have%20%3CA%20title%3D%22Other%20SDK%20Samples%22%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FBotBuilder-Samples%2Ftree%2Fmain%2Fsamples%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eother%20SDK's%3C%2FA%3E%20available%20and%20associated%20samples%26nbsp%3Bwith%20these%20SDK's%20as%20well.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%232%20-%20Once%20you%20clone%20the%20samples%20repo%2C%20you%20can%20locate%20to%20the%20easiest%20sample%2C%20which%20is%20%22%3CA%20title%3D%2202.echo-bot%22%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FBotBuilder-Samples%2Ftree%2Fmain%2Fsamples%2Fcsharp_dotnetcore%2F02.echo-bot%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E02.echo-bot%3C%2FA%3E%22%20which%20just%20echoes%20back%2C%20whatever%20you%20write%20to%20the%20bot.%20In%20the%20GitHub%20article%2C%20%22To%20try%20this%20sample%22%20section%20defines%20how%20to%20build%20and%20run%20this%20sample.%3C%2FP%3E%0A%3CP%3EInside%20all%20the%20bot%20samples%2C%20you%20will%20find%20a%20folder%20called%20%22Bots%22%20which%20contains%20the%20bot%20classes%2C%20that%20are%20derived%20from%20%3CA%20title%3D%22ActivityHandler%20classes%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fmicrosoft.bot.builder.activityhandler%3Fview%3Dbotbuilder-dotnet-stable%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EActivityHandler%20classes%3C%2FA%3E.%20These%20classes%20are%20injected%20as%20a%20dependency%20in%20the%20%3CA%20title%3D%22Startup%20Class%20for%20Echobot%22%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FBotBuilder-Samples%2Fblob%2Fmain%2Fsamples%2Fcsharp_dotnetcore%2F02.echo-bot%2FStartup.cs%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%22Startup.cs%22%3C%2FA%3E%20file.%20Once%20you%20find%20your%20bot%20class%20you%20can%20try%20putting%20a%20breakpoint%20to%20%22%3CA%20title%3D%22Bot%20turn%20on%20Message%22%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FBotBuilder-Samples%2Fblob%2Fmain%2Fsamples%2Fcsharp_dotnetcore%2F02.echo-bot%2FBots%2FEchoBot.cs%23L16%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EOnMessageActivityAsync()%3C%2FA%3E%22%20function%20which%20represent%20the%20bots%20turn.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%233-%20After%20you%20run%20the%20sample%2C%20you%20can%20go%20to%20%22Bot%20Framework%20Emulator%22%20and%20start%20communicating%20with%20your%20bot.%20you%20can%20visit%20this%20article%20%3CA%20title%3D%22Start%20emulator%20and%20connect%20to%20your%20bot%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Fbot-builder-tutorial-basic-deploy%3Fview%3Dazure-bot-service-4.0%26amp%3Btabs%3Dcsharp%252Cvs%23start-the-emulator-and-connect-to-your-bot%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%2C%20if%20you%20want%20to%20understand%20how%20you%20can%20define%20your%20bot%20endpoint%20and%20connect%20to%20your%20bot%20using%20the%20bot%20framework%20emulator.%20Once%20you%20connect%2C%20you%20should%20be%20observing%20that%20your%20breakpoint%20is%20hit.%20You%20can%20check%20the%20contents%20of%20%22TurnContext%22%20object%20with%20your%20debugger%2C%20and%20try%20understanding%20the%20structure%20of%20an%20activity.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22mertozturk_1-1603785045795.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F229478i89AEAB8FDA81B4F6%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22mertozturk_1-1603785045795.png%22%20alt%3D%22mertozturk_1-1603785045795.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20check%20more%20complex%20samples%2C%20you%20can%20see%20that%20the%20bot%20classes%20also%20implement%20other%20methods%20for%20%3CA%20title%3D%22Activity%20Handler%20Methods%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fjavascript%2Fapi%2Fbotbuilder-core%2Factivityhandler%3Fview%3Dbotbuilder-ts-latest%23methods%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eactivity%20handler%3C%2FA%3E%20class.%20Ie.%20one%20of%20my%20favorites%20%2221.corebot-app-insights%22%20sample%20also%20implement%20%22%3CA%20title%3D%22OnTurnAsync%20on%2021.corebot-app-insights%20sample%22%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FBotBuilder-Samples%2Fblob%2Fmain%2Fsamples%2Fcsharp_dotnetcore%2F21.corebot-app-insights%2FBots%2FDialogBot.cs%23L33%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EOnTurnAsync%3C%2FA%3E%22%20method%20of%20activity%20handler%20class.%20As%20you%20see%2C%20my%20ultimate%20recommendation%20for%20a%20bot%20SDK%20developer%20in%20this%20blogpost%20is%3A%20get%20more%20familiar%20with%20the%20samples%2C%20since%20they%20represent%20many%20different%20use%20cases%20for%20bot%20development.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat%20do%20you%20think%20can%20be%20the%20next%20step%3F%20That's%20right%2C%20you%20can%20now%20consider%20deploying%20your%20bot%20code%20to%20Azure%2C%20and%20start%20discovering%20the%20endless%20opportunities%20of%20cloud%20technologies%20%3A)%3C%2Fimg%3E%20Here%20is%20our%20standard%20documentation%20on%20%3CA%20title%3D%22deploying%20your%20bot%20to%20Azure%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Fbot-builder-deploy-az-cli%3Fview%3Dazure-bot-service-4.0%26amp%3Btabs%3Dcsharp%23deploy-code-to-azure%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Edeploying%20your%20bot%20to%20Azure%3C%2FA%3E.%20I%20think%20that%20is%20all%20for%20today.%20Hope%20you%20enjoyed%20the%20read.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EStay%20tuned%20for%20the%20next%20blogpost%2C%3C%2FP%3E%0A%3CP%3ESee%20you%20soon%2C%3C%2FP%3E%0A%3CP%3EMert%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1821877%22%20slang%3D%22en-US%22%3E%3CP%3EA%20brief%20introduction%20to%20Bot%20Framework%20SDK%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1821877%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Bot%20Service%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EBot%20Framework%20SDK%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Hello bot developers,

 

I have recently decided to write blogposts about Bot framework technology to reflect my perspective on the subject, provide ideas on how it works and to troubleshoot common scenarios. The best start for this, is to make a good definition of "Bot Framework SDK", and in general "Azure Bot Service", that Microsoft offers.

 

Apart from the fancy description here, a bot can be defined as an application , which uses "Bot Builder" and  "Bot Connector" libraries, to communicate through the Connector services and channels. While doing that, the dependent services being used on that bot application, like "LUIS" (Language Understanding Intelligent Service) or "QnA Service", makes the bot behave like an intelligent entity, since it will be able to understand your intentions easily and reply to them. All the communication between the human and the bot, is packaged into a serializable JSON based objects called "Activity", and it flows through different channels. "Bot Builder" libraries create a reply "Activity" to these incoming "Activity" objects, considering the state of "Conversations" and "Dialogs", to provide you meaningful suggestions based on your previous interactions. Most popular type of an "Activity" is a "Message", but activities can also provide meta information, like adding/removing users to a conversation. When activity reach out to bot, it will be put inside a "TurnContext" object, together with the state information of User and dialog. A Turn context , will be processed by the bot code, and it will be valid until the Turn of the bot is completed. You can find the activity processing stack with a nice diagram here if you want to see more on the activity processing.  Note that, these diagrams focus on the bot side of the communication and abstract the channel/connector side.

 

 To get more acquainted with the conversation based Bot communication, I can recommend you to start reviewing the REST API's documented here. Also, you can surf inside the Bot Builder 4.0 Namespace, to understand what an activity object is, or how a TurnContext object relates with an activity, etc.

 

We can finish the definition part here and If you want to play around with bots, you can start creating bots, and try understanding how they work. Assuming that you have an active Azure Subscription, you can deploy your bot to Azure or alternatively you can use our "Bot Framework Emulator" tool, to debug to bots locally. For the latter, I can give you a recipe below, to start with:

 

#1 - Clone the Bot Builder samples repo to get all available samples. In my posts, I will mostly use "dotnet core" based samples, since I am more used to work with that language. But we have other SDK's available and associated samples with these SDK's as well.

 

#2 - Once you clone the samples repo, you can locate to the easiest sample, which is "02.echo-bot" which just echoes back, whatever you write to the bot. In the GitHub article, "To try this sample" section defines how to build and run this sample.

Inside all the bot samples, you will find a folder called "Bots" which contains the bot classes, that are derived from ActivityHandler classes. These classes are injected as a dependency in the "Startup.cs" file. Once you find your bot class you can try putting a breakpoint to "OnMessageActivityAsync()" function which represent the bots turn.

 

#3- After you run the sample, you can go to "Bot Framework Emulator" and start communicating with your bot. you can visit this article here, if you want to understand how you can define your bot endpoint and connect to your bot using the bot framework emulator. Once you connect, you should be observing that your breakpoint is hit. You can check the contents of "TurnContext" object with your debugger, and try understanding the structure of an activity.

 

mertozturk_1-1603785045795.png

 

If you check more complex samples, you can see that the bot classes also implement other methods for activity handler class. Ie. one of my favorites "21.corebot-app-insights" sample also implement "OnTurnAsync" method of activity handler class. As you see, my ultimate recommendation for a bot SDK developer in this blogpost is: get more familiar with the samples, since they represent many different use cases for bot development. 

 

What do you think can be the next step? That's right, you can now consider deploying your bot code to Azure, and start discovering the endless opportunities of cloud technologies :) Here is our standard documentation on deploying your bot to Azure. I think that is all for today. Hope you enjoyed the read.

 

Stay tuned for the next blogpost,

See you soon,

Mert