Introduction

Microsoft first introduced the Bot Framework on March 30th 2016, during their annual Build developer conference. Essentially, the Bot Framework lets developers build apps, called chatbots, that surface in common messaging apps. To get started, you can open your favorite messaging app, such as Messenger, Skype, or Slack and add chatbots to your friends list. You can then interact with the chatbot with buttons, cards, or text for nearly any type of application. The difference is that the chatbot excels at conversational communication, rather than graphical, which can be very efficient. Developers can also write one chatbot with the Bot Framework and target a growing list of platforms, called channels. I’ve already mentioned a few messaging channels and you can literally surface the same chatbot anywhere, including web pages, SMS text, and Cortana Skills. There’s even a Direct Line API that lets you create your own channels. Combining the power of conversation, multiple-channels, and voice, developers have a powerful tool to bring their applications through chatbots to anyone anywhere.

Programming the Microsoft Bot Framework: A Multiplatform Approach to Building Chatbots tells the story of the Bot Framework from a high-level architecture to managing conversations with dialogs and on to natural language processing and voice communications. Each step of the way, you learn the core principles of why a subject is important and how it applies to the work you need to do. While chatbots exist for a myriad of enterprise applications and industries, this book focuses on three primary examples: a game, a storefront, and entertainment. The examples and explanations are designed to not only give you ideas for your own chatbots, but put you on solid footing to start building your own chatbots right away.

Who should read this book

This book is for C# developers who want to learn about what chatbots are and what they can do for you. If you can write code and are able to read C# syntax, you can probably keep up. Though it is developer focused, Architects should find this to be a useful reference for how the Bot Framework operates and the considerations affecting integrations and systems design.

Assumptions

At a minimum, you should be able to read C# code. Any experienced C# developer won’t have a problem. Knowledge of ASP.NET MVC Web API is helpful because that’s the project type for all of the examples. Even if you’re new to ASP.NET, you shouldn’t have a problem because the book explains many of the details of how the Bot Framework handles web related subject material.

This book might not be for you if…

This book might not be for you if you’re a brand new programmer who doesn’t know how to write code. Although the Bot Framwork has a Node.js SDK, and could potentially support other languages in the future, this book uses C# exclusively. When people hear the term “bot,” they often think of physical robots and autonomous machines, and this book is neither of these things. It’s a book on how to write software for conversational user interfaces, which is another reason I use the term “chatbot.” There are other chatbot platforms available, but this book only covers the Microsoft Bot Framework. That said, if you’re a C# developer who’s excited about chatbots and other Microsoft AI technologies, then don’t hesitate to buy this book right now.

Organization of this book

This book has 15 chapters, divided into four parts. Part I, Getting Started, sets up the fundamentals that you need for the rest of the book. The first chapter provides a bird’s eye view of the Bot Framework architecture, which is important because many of the decisions you make depend on knowing how the pieces fit together. After learning how to set up a project, Chapter 2 and Chapter 3 introduce the core parts of a conversation, explaining messages and conversation state. In Chapter 4, you learn how to use the Bot Emulator for testing, different types of information a chatbot can handle, and ways a chatbot communicates with a user.

Part II covers different types of dialogs. In Chapter 5, you’ll learn about tools for managing user interaction and how to transition from one question to another. Chapter 6 introduces FormFlow—a way to build question and answer forms with a small amount of code. FormFlow is simple, yet powerful, and Chapter 7 continues with more techniques in customizing FormFlow. Chatbots come alive with natural language processing (NLP) and Chapter 8 shows how Microsoft’s Language Understanding Intelligence Service (LUIS) lets you easily add NLP to a chatbot with a special dialog type. You’ll learn even more advanced conversation management in Chapter 9, which covers how Bot Framework manages communication with a dialog stack. Chapter 9 also covers chaining, including LINQ to Dialog, and shows how to handle situations where a user changes subjects in the middle of a conversation.

Part III discusses channels and the graphical user interface (GUI). Although chatbots are primarily conversational, Chapter 10 shows how the Bot Frameworks supports various types of cards, allowing users to interact with GUI controls. Multi-platform support is so important that there are two chapters dedicated to channels. Chapter 11 provides a channel overview, explains how to configure analytics, and shows how to configure Bing and Team channels. There’s a growing list of channels and these are general examples of how you approach the task of configuring channels. Chapter 12 covers how to configure email, SMS, and web chatbots, showing how to add a chatbot to something other than a messaging app channel. The explanation also shows how to add the Webchat control to a page in a secure manner.

The last 3 chapters in Part IV show how to add custom channels, intelligence, and use voice services. The Bot Framework has a powerful Direct Line API that lets you create your own channel, discussed in Chapter 13. Essentially, this lets you surface a chatbot on any platform. You can write sophisticated chatbots without artificial intelligence (AI), but AI can make them better. That’s why Chapter 14 shows you how to leverage Microsoft Cognitive Services to add AI to your chatbot. Finally, Chapter 15 introduces one of the most compelling and exciting techologies that we have to work forward to by surfacing a chatbot as a Cortana Skill. For all the discussion of what an intuitive user interface is, what is more intuitive than the ability to use your voice and talk to a computer?

Conventions and features in this book

This book presents information using conventions designed to make the information readable and easy to follow.

Images Boxed elements with labels such as “Note” provide additional information or alternative methods for completing a step successfully.

Images Text that you type (apart from code blocks) appears in bold.

Images A plus sign (+) between two key names means that you must press those keys at the same time. For example, “Press Alt+Tab” means that you hold down the Alt key while you press the Tab key.

Images For long lines of code in listings, the code line will break and align flush left.

Images A vertical bar or greater than sign between two or more menu items (e.g. File | Close or File > Close), means that you should select the first menu or menu item, then the next, and so on.

System requirements

You will need the following hardware and software to complete the practice exercises in this book:

Images One of Windows 10, Windows 8.1, Windows 8, Windows 7 SP 1, Windows Server 2012 R2, Windows Server 2012, or Windows Server 2008 R2 SP1

Images Visual Studio 2015—any edition (works fine with Visual Studio 2017, but tested and verified to be compatible with Visual Studio 2015)

Images Computer that has a 1.6 GHz or faster processor

Images 1 GB of RAM (1.5 GB if running on a virtual machine)

Images 4 GB of available hard disk space

Images 5400 RPM hard disk drive

Images DirectX 9 capable video card running at 1024 x 768 or higher-resolution display

Images Internet connection to download software, refresh NuGet packages, or chapter examples

Depending on your Windows configuration, you might require Local Administrator rights to install or configure Visual Studio 2015.

Downloads: Code samples

Most of the chapters in this book include exercises that let you interactively try out new material learned in the main text. All sample projects, in both their pre-exercise and post-exercise formats, can be downloaded from the following page:

https://aka.ms/ProgBotFramework/downloads


Images Note

In addition to the code samples, your system should have Visual Studio 2015 (or Visual Studio 2017) installed.


Installing the code samples

Follow these steps to install the code samples on your computer so that you can use them with the exercises in this book.

1. If you downloaded the code, unzip the MSBotFrameworkBook-master.zip file that you downloaded from the book’s website (name a specific directory along with directions to create it, if necessary).

2. Locate the file with the chapter name you want to see and open the *.sln file for that chapter.

Using the code samples

The code is organized into 15 folders with the pattern ChapterXX, where XX holds the chapter numbers 01 through 15. Chapter 01 doesn’t have code because that’s an architectural overview chapter. Each folder contains a ChapterXX.sln file you can double click in File Explorer to open in Visual Studio. Other folder contents are the project and other files for the code in that chapter.

Each chapter folder has a packages folder for NuGet assemblies. If you have trouble building the solution, delete the packages folder and rebuild. This restores NuGet packages for a successful build.

Acknowledgments

The first person I’d like to thank is my wife, May. Writing a book takes a significant amount of time and I sincerely appreciate her love and support throughout the process. Thanks to the rest of my family for their patience in my absence.

Thanks to the editing team. Devon Musgrave brought me into the project. Trina Fletcher MacDonald was my Aquisitions Editor and I sincerely appreciate her advice, patience, and how she kept the project on track. This is the third project I’ve done with Songlin Qiu as Development Editor, who provided insight that continuously improved the organization and quality of the work-another excellent experience. Our copy editor, Christina Rudloff, smoothed out my choppy grammar and helped me stay within the guidelines. Troy Mott expertly managed the copyediting, layout and composition,
proofreading, and indexing of chapters. There are many other people who contributed that I haven’t worked with individually, but I am grateful for their contributions.

We had a couple of excellent technical editors: Ankit Sinha and Shahed Chowdhuri. I can’t count how many times these guys identified areas for improvement that made significant differences in the quality of the work. Thanks a lot and I really appreciate everything you’ve done.

Errata, updates, & book support

We’ve made every effort to ensure the accuracy of this book and its companion content. You can access updates to this book—in the form of a list of submitted errata and their related corrections—at:

https://aka.ms/ProgBotFramework/errata

If you discover an error that is not already listed, please submit it to us at the same page.

If you need additional support, email Microsoft Press Book Support at [email protected].

Please note that product support for Microsoft software and hardware is not offered through the previous addresses. For help with Microsoft software or hardware, go to https://support.microsoft.com/.

Free ebooks from Microsoft Press

From technical overviews to in-depth information on special topics, the free ebooks from Microsoft Press cover a wide range of topics. These ebooks are available in PDF, EPUB, and Mobi for Kindle formats, ready for you to download at:

https://aka.ms/mspressfree

Check back often to see what is new!

We want to hear from you

At Microsoft Press, your satisfaction is our top priority, and your feedback our most valuable asset. Please tell us what you think of this book at:

https://aka.ms/tellpress

We know you’re busy, so we’ve kept it short with just a few questions. Your answers go directly to the editors at Microsoft Press. (No personal information will be requested.) Thanks in advance for your input!

Stay in touch

Let’s keep the conversation going! We’re on Twitter: http://twitter.com/MicrosoftPress

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.63.87