You are on page 1of 7

Table of Contents

About This E-Book 2


Title Page 3
Copyright Page 4
Dedication Page 6
Table of Contents 8
Introduction 15
Who should read this book 15
Assumptions 15
This book might not be for you if…. 15
Organization of this book 16
Conventions and features in this book 17
System requirements 17
Downloads: Code samples 17
Installing the code samples 18
Using the code samples 18
Acknowledgments 18
Errata, updates, & book support 19
Free ebooks from Microsoft Press 19
We want to hear from you 19
Stay in touch 19
Part I Getting Started 20
Chapter 1 Exploring Bot Framework Architecture 21
What Is a Chatbot? 21
Defining a Chatbot 21
Why Conversation? 22
Chatbot Benefits 23
To Bot or Not 25
Bot Framework Architecture 26
Visualizing Chatbots, Connector, and Channels 26
Overview of Channels 27
Bot Connector Services 28
Characteristics of a Chatbot 30
Chatbot Communications 31
Summary 32
Chapter 2 Setting Up a Project 34

794
Steps to Building a Chatbot 34
Creating a Bot Framework Project 35
Installing the Project Template 35
Starting a New Project 36
Examining the Default Code 37
Assembly References 37
Folder and File Layout 40
The Default Chatbot 41
Initial Testing with the Emulator 46
Installing the Bot Emulator 46
Configuring the Chatbot 47
Communicating with the Chatbot 50
Publishing and Registering a Chatbot 51
Publishing the Chatbot 52
Registering a Chatbot 57
Summary 61
Chapter 3 Building Conversations: The Essentials 62
The Rock, Paper, Scissors Game Bot 62
The PlayType Enum 62
The Game Class 63
The MessagesController Class 67
Conversation State Management 69
Elements of a Conversation 69
Saving and Retrieving State 72
Participating in Conversations 85
Responding to Conversations 86
Building a Custom Message Activity 86
Using a Custom Message Activity 88
Summary 89
Chapter 4 Fine-Tuning Your Chatbot 91
Reviewing Bot Emulator Details 91
Handling Activities 92
The Activity Class 92
The ActivityType Class 94
Code Design Overview 95
Sending Activities with the Bot Emulator 99
Relationship Changes 99
Conversation Updates 100
Deleting User Data 103

795
Pinging 103
Typing Indications 104
Advanced Conversation Messages 105
Sending Typing Activities 105
Sending Independent Messages 109
Summary 116
Part II Bot Builder 117
Chapter 5 Building Dialogs 118
Introducing WineBot 118
Using the Wine.com API 119
Implementing a Dialog 127
Creating a Dialog Class 131
Dialog Initialization and Workflow 132
Examining IDialogContext 133
Dialog Conversation Flow 134
Dialog Prompt Options 137
Performing the Search 145
Calling a Dialog 146
Summary 148
Chapter 6 Using FormFlow 149
Out-of-the-Box Features 149
A Basic FormFlow Chatbot 154
The Wine API Interface 154
WineForm: A FormFlow Form 155
Using WineForm as a Dialog 160
Enhancing FormFlow Conversations 164
The Describe Attribute 165
The Numeric Attribute 166
The Optional Attribute 167
The Pattern Attribute 167
The Prompt Attribute 168
The Terms Attribute 168
Advanced Templates and Patterns 170
Pattern Language 170
Basic Templates 172
Template Usage 172
Template Options 180
Summary 185
Chapter 7 Customizing FormFlow 187

796
Understanding the FormFlow Fluent Interface 187
The Configuration Property 188
Configuring Responses 190
Configuring Templates 192
Configuring Commands 195
The Message Method and Common Parameters 197
The condition Parameter 199
The dependencies Parameter 199
The prompt Parameter 201
The generateMessage Parameter 201
The Confirm Method 202
Working with Fields 204
Dynamic Field Definition 208
Field Validation 210
The AddRemainingFields Method 212
The HasField Method 212
The OnCompletion Method 213
The Build Method 215
Initializing FormFlow 216
Summary 218
Chapter 8 Using Natural Language Processing (NLP) with LUIS 220
Learning Essential LUIS Concepts 220
Setting up LUIS and Training Models 221
Creating Models 222
Building Intents 224
Specifying Entities 225
Training and Deploying 227
Using LUIS in Your Chatbots 231
Introducing WineBotLuis 231
Adding Intents 234
Handling Entities 235
Continuous LUIS Model Improvement 239
Summary 241
Chapter 9 Managing Advanced Conversation 243
Managing the Dialog Stack 243
What is the Dialog Stack? 243
Navigating to Other Dialogs 244
Navigating via Forward 247
Navigating via Call 249

797
Finishing a Dialog 251
Managing Conversations with Chaining 254
The WineBotChain Program 255
Chain.From 261
Chain.Loop 262
Chain.Switch 263
Chain.ContinueWith 266
An Assortment of Posting and Waiting Chain methods 266
LINQ to Dialog 268
Handling Interruptions with IScorable 269
Formatting Text Output 274
Summary 277
Part III Channels and Gui 278
Chapter 10 Attaching Cards 279
Music Chatbot Overview 279
The Groove API 279
The Root Dialog 285
The Profile Dialog 287
The Browse Dialog 288
The Playlist Dialog 290
The Search Dialog 290
Building Blocks 291
Presenting Suggested Actions 291
Working with Attachments 296
Displaying Cards 305
Implementing BrowseDialog 306
Implementing PlaylistDialog 312
Adaptive Cards 317
Layout with Containers 322
Using Controls 324
Handling Actions 325
Summary 327
Chapter 11 Configuring Channels 329
Channel Overview 329
The Channel Configuration Page 330
Chatbot Analytics 330
Configuring Teams 335
Channel Setup 336
Using the Chatbot 338

798
Configuring Bing 339
Channel Setup 340
Using in Search 341
The Channel Inspector 341
Summary 342
Chapter 12 Creating Email, SMS, and Web Chatbots 344
Emailing Chatbot Conversations 344
Creating the Email Account 344
Configuring the Email Channel 346
Texting a Chatbot 348
Embedding the Webchat Control 349
Adding the Webchat IFrame Placeholder 349
Client-Side Coding 351
Handling the Server Request 352
Summary 355
Part IV Apis, Integrations, and Voice 357
Chapter 13 Coding Custom Channels with the Direct Line API 358
Overview of the Console Channel 358
Console Channel Components 358
Examining Console Channel Code 360
Starting a Conversation 363
Listening for New Activities 365
Keeping the Conversation Open 371
Sending Activities 373
Ending Conversations 374
Examining CancellationTokenSource and CancellationToken 375
Handling User Exits 376
Summary 377
Chapter 14 Integrating Cognitive Services 378
Searching with Bing 378
Interpreting an Image 389
Translating Text 391
Building FAQ Chatbots with QnA Maker 400
Summary 405
Chapter 15 Adding Voice Services 407
Adding Speech to Activities 407
Adding Speech with SayAsync 410
Adding Speech to PromptDialog 413
Specifying Input Hints 417

799
Setting up Cortana 419
Summary 425
Index 427
Code Snippets 453

800

You might also like