31,19 €
Bots help users to use the language as a UI and interact with the applications from any platform. This book teaches you how to develop real-world bots using Microsoft Bot Framework.
The book starts with setting up the Microsoft Bot Framework development environment and emulator, and moves on to building the first bot using Connector and Builder SDK. Explore how to register, connect, test, and publish your bot to the Slack, Skype, and Facebook Messenger platforms.
Throughout this book, you will build different types of bots from simple to complex, such as a weather bot, a natural speech and intent processing bot, an Interactive Voice Response (IVR) bot for a bank, a facial expression recognition bot, and more from scratch.
These bots were designed and developed to teach you concepts such as text detection, implementing LUIS dialogs, Cortana Intelligence Services, third-party authentication, Rich Text format, Bot State Service, and microServices so you can practice working with the standard development tools such as Visual Studio, Bot Emulator, and Azure.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 234
Veröffentlichungsjahr: 2017
BIRMINGHAM - MUMBAI
Copyright © 2017 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: May 2017
Production reference: 1310517
ISBN 978-1-78646-310-4
www.packtpub.com
Author
Kishore Gaddam
Copy Editor
Dhanya Baburaj
Reviewer
Allen ONeill
Project Coordinator
Ulhas Kambali
Commissioning Editor
Ashwin Nair
Proofreader Safis Editing
Acquisition Editor
Shweta Pant
Indexer
Mariammal Chettiyar
Content Development Editor
Onkar Wani
Graphics
Abhinash Sahu
Technical Editor
Shweta Jadhav
Production Coordinator
Shraddha Falebhai
Kishore Gaddam is the CEO and a co-founder of Astrani Technologies and is recognized as an industry expert in mobile, cloud, and bot software development. He is a forward-thinking technology leader with 17+ years of international experience in building technology organizations, strategic planning, rolling out multiple platforms/products, IT program and project management, strategy and transformation (businesses, people, processes, and technologies), and growing business units across IoT, smart cities, NLP, AI, bots, cloud, robotics, mobile, healthcare, industrial automation, financial systems, retail, procurement (EPC), travel & leisure, logistics, manufacturing, and automotive domains.
He is a champion of the technical pre-sales, architecture, and software development of enterprise Azure IoT/bot/web applications using cognitive services, microservices, Service Fabric, Azure IoT Hub, Stream Analytics, Cortana Intelligence Suit, Logic Apps, Notification Hubs, Big Data, Azure Web Apps, Azure App service, Azure API Apps, Application Insights, API Management, Machine Learning, Azure SQL databases, Cosmos DB, Data Factory, Data Lake, HD Insight, Redis Cache, Key Vault, and Azure Service Bus, and a champion of implementing DevOps using Azure, PowerShell scripts, ARM templates, and VSTS. He has huge experience in startup leadership, including building teams, and developing a Minimum Viable Product (MVP) with little to no supervision. Kishore is comfortable at all layers of the startup people stack, from individual contributor (software development, product management) to CxO. Kishore graduated in Technology Entrepreneurship from Stanford University, CA, and is a speaker at various conferences in the USA. Kishore is the author of the popular Microsoft Technologies blog. He has a love for mentoring and a passion for sharing new tools, programming languages, and technology trends at national conferences, regional code camps, local user groups, meetups, and hackathons.
Allen ONeill is a chartered engineer with a background in enterprise systems. He is a fellow of the Brisith Computing Society, a Microsoft MVP (most valued professional) and writes for CodeProject, C-Sharp Corner and DZone. His core technology interests are Big Data engineering and machine learning, in particular using Data Science to create intelligent bots/agents for the web. He is also a ball throwing slave to his family dogs.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.comand as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at http://www.amazon.in/dp/1786463105.
If you'd like to join our team of regular reviewers, you can e-mail us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
Setting up Microsoft Bot Framework Dev Environment
Conversation as a Service (CaaS)
Your bot
The Bot Connector
The Bot Directory
Setting up the development environment
Prerequisites
Setting up the Bot Framework Connector SDK .NET
Messages
Basic format
Rich text
Skype emoticons
Welcome messages
Pictures and videos
Cards and buttons
Hero card
Thumbnail card
Carousel
Images
Buttons
Actions
Sign in
Receipt
Groups
Calling
Summary
Developing Your First Bot Using the Connector and Builder SDK
Bots are evolving
Bots use cases
Developing your first bot
Creating our first bot
Building a bot using the C# SDK
AssemblyInfo.cs
References
Microsoft Bot Builder
Microsoft Bot Connector
WebApiConfig.cs
MessageController.cs
Default.htm
Global.asax
Packages.config
Web.config
Post method
BotID
Microsoft App ID
MicrosoftAppPassword
How to deploy and run the bot application in the Bot Framework emulator locally
How to use dialogs in bot applications
How to use FormFlow in the bot application
Summary
Developing WeatherBot Using Dialogs and LUIS
Language Understanding Intelligent Service (LUIS)
Intents and Entities
Training your bot using utterances
Testing your LUIS app
Development of WeatherBot code
Calling LUIS from the bot
Calling the Weather API
Using cards
Natural speech and Intent processing bot using Microsoft Cognitive Services
Identifying the name of a person, place, and company using LUIS
Training your app
Calling LUIS from the bot
Summary
Natural Speech and Intent Processing Bot Using Microsoft Cognitive Services
Microsoft Cognitive Services
Signing up for Microsoft Cognitive Services
Building a bot application using Cognitive Services APIs
Analyzer's results
Identifying the name of a person, place, and company using LUIS
Training your app using utterances
Calling LUIS from the bot
Summary
Developing Bots Using LUIS Prompt Dialogs with State and Nearby Bot Using Custom APIs
Employee Enroll bot using LUIS prompt dialogs
Training the service
Training and publishing
Creating the C# class for LUIS response
Creating the bot application
Bot state service
Creating a state client
Get/SetProperty methods
Updating your Post method
Updating your QueryLUIS method
Developing a Nearby Bot using custom APIs
Summary
Developing an IVR Bot for a Bank Using Advanced Microsoft Bot Framework Technologies
High-level architectural diagram
Let's start coding
Creating an account with the bot
Storing the bot conversation (new account info) data in an Azure SQL database
Checking your savings account balance using the bot
Checking your current account balance using the bot
Paying your credit card bill using the bot
Deleting an account using the bot
Summary
Intelligent Bots with Microsoft Bot Framework and Service Fabric
Getting started using stateless microservices
Setting up your development environment for Service Fabric
Prerequisites
Installing the SDK and tools
Enabling PowerShell script execution
Creating a stateless Service Fabric web API
Publishing a Service Fabric project in Azure
Create Key Vault
Adding certificates to the Key Vault
Creating a cluster in the Azure portal
Summary
Developing Intelligent Facial Expression Identification Bot for IoT Using Azure and Power BI
Before getting started
Configuring Raspberry Pi and sensors
Prerequisites
Hardware
Software
Setting up sensors
Schematic diagram
Device identity and registry with IoT Hub
Using Device Explorer
Face API
Emotion API
Sign Up Microsoft Cognitive Services
Development of facial expressions identification bot
Let's code to know the emotions
Registering your Bot in Bot Framework
Publish and test your bot
Configure Direct Line Channel
Develop an UWP app for Raspberry Pi device
Create an UWP App project
How to detect the motion of the object using PIR Sensor and How to define the LED states
Initializing camera on detection of motion
How to send picture file to Facial Expression Bot and receive reply from it
Send Picture to Bot
Deploy Code in to Raspberry Pi
Show facial analytics data in Power BI
Set up Azure Stream Analytics to send IoT Hub data to Power BI
Set up Power BI
Summary
Publishing a Bot to Skype, Slack, Facebook, and the GroupMe Channel
Publishing bots to various channels
Publishing your bot application to Microsoft Azure web app
Registering your bot with Microsoft Bot Framework
Configuration
Testing the connection to your bot
Configuring channels
Configuring your bot with Slack
Configuring your bot with Skype
Configuring your bot with Facebook Messenger
Configuring your bot with GroupMe
Summary
This is a book for those who want to build fully functional and scalable Natural Language Processing Bots using Microsoft Bot Framework. Its learn-while-doing approach delivers the practical knowledge and experience a reader needs to design and build real-world bots. We explain concepts when needed to develop a bot, so that programming knowledge and experience grow together.
This book will take you from software installation to developing a fully-functional bot that is deployed and run in Azure. This book leads the reader through the essential programming tools and techniques for developing bots for various conversation platforms, such as Skype, Slack, web chat, and so on. In each chapter, the reader will learn Microsoft Bot Framework programming concepts and apply them immediately, as you build a bot or enhance one from a previous chapter.
These bots have been designed and developed to teach the associated concepts and to provide practice working with the standard development tools, such as Visual Studio, the bot emulator, and Azure. Many of the discussions in the book will be clarified to make some of the more complex topics easier to understand. All of the projects have been built from scratch using Microsoft Bot Framework.
Chapter 1, Setting up the Microsoft Bot Framework Dev Environment, introduces the reader to what Microsoft Bot Framework is and how it helps in the development of bots. It walks the reader through on how to set up development environment, emulator, and the tools needed for programming. Reader gets to set up their development environment and install all the software required for getting started with programming a bot. The reader is also introduced to all the programming concepts involved in the development of bots.
Chapter 2, Developing Your First Bot Using the Connector and Builder SDK, this chapter introduces the reader to bot programming by building and locally deploying a simple Hello World bot application. The readers will get their feet wet with Visual Studio, C# .NET, Bot Framework, and the related technologies, along with all the steps required to create projects. This chapter includes a discussion of Bot Emulator and how it relates to bot development.
Chapter 3, Developing a WeatherBot Using Dialogs and LUIS, guides the reader through developing a fully functional weather bot. This bot communicates the current weather in a given city. Readers will interact with this bot on Skype or any other channel to find out the current weather at a given location.
Chapter 4, Natural Speech and Intent Processing Bot using Microsoft Cognitive Services, introduces the reader to the RichText Message technology, as well as Cortana Intelligence Services, by developing a fully functional bot. This bot identifies the concepts and actions in the text that is sent to the bot with part-of-speech tagging, finds phrases and concepts using natural language parsers, and returns all the identified intents that are created and trained in a custom LUIS app. If you say "Hi John, I am going to New York tonight," the bot will return part-of-speech tagging, as well as parsing data for natural speech and intent processing to find out the name, location, and so on.
Name: John
Place: New York
Whether you're mining customer feedback, interpreting user commands, or consuming web text, understanding the structure of the text is a critical first step and this chapter teaches that.
Chapter 5, Developing Bots Using LUIS Prompt Dialogs with State and Nearby Bot Using Custom APIs, is about how we can integrate APIs into bot development. Currently, every enterprise has web and mobile applications built on top of their APIs, which contain business functionality. Now, it would be natural to extend those APIs so that they can be used for bots as well. This chapter introduces readers to how to use Microsoft Bot Framework to develop a Nearby bot using APIs. This Nearby bot will provide the reader with all the available places near their location, with details for each and every one of them. This bot helps you to easily find nearby banks, clubs, restaurants, hotels, museums, pharmacies, hospitals, or any other place you want to search for.
Chapter 6, Developing an IVR Bot for a Bank using Advanced Microsoft Bot Framework Technologies, includes a real-world project that we will build from the ground up, so that readers can learn the concept as well as relate it to real-world scenarios. The following topics are explained in this chapter:
Building
Interactive Voice Response
(
IVR
) solutions
Learning how to build bots using dialogs, third-party authentication, Rich Text Format, and Bot State Service.
Learning how to use Form Builder while developing bots
Learning how to program using prompt dialogs
Learning how to implement Buttons in buttons
Third-party authentication
Bot State Service
Chapter 7, Intelligent Bots with Microsoft Bot Framework and Service Fabric, introduces the reader to the concept of microservices and how microservices can be used in bot development. They get to learn about and work on microservices development, as well as learn to program a bot using microservices, and will get to learn how to use this microservice-based bot and publish it to various channels.
Chapter 8, Developing an Intelligent Facial Expression Identification Bot for IoT using Azure and Power BI, introduces the reader to IoT and how bots can help in IoT development. Here, the reader will develop an IoT project and connect it to a bot for automation. Power BI is used to show report from bots. The reader will learn to develop, deploy, and connect an IoT project to a bot. They will get to learn how IoT, bots, Azure, and Power BI fit together in an enterprise application development scenario.
Chapter 9, Publishing a Bot to Skype, Slack, Facebook, and the GroupMe Channel, guides the reader on how to publish the Hello World bot we developed in a previous chapter to the Slack, Skype, and Facebook Messenger platforms. In this chapter readers will learn the following:
Registering bot
:Once registered, the reader uses the dashboard to test their bot to ensure that it is talking to the connector service. They can also use the web chat control, an auto-configured channel, to experience what their users will experience when conversing with the bot.
Connecting to channels
: Connect your bot to conversation channels such as Skype, Slack, and Facebook Messenger using the channel configuration page.
Testing the bot
:The reader gets to test their bot's connection to the Bot Framework and try it out using web chat controls.
Publishing the bot
:The reader gets to publish the bot.
Analyzing the bot
: The reader gets to learn how to link their bot to Azure Application Insights analytics directly from the bot dashboard of the Bot Framework website.
Managing a bot
: Once registered and connected to channels, you can manage your bot via your bot's dashboard in the Bot Framework Developer Portal.
Visual Studio 2015 or higher
Internet access
Microsoft Azure trial subscription
This book is for developers who are keen on building powerful services with a great interactive bot interface. Experience with C# is needed.
Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
Log in or register to our website using your e-mail address and password.
Hover the mouse pointer on the
SUPPORT
tab at the top.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box.
Select the book for which you're looking to download the code files.
Choose from the drop-down menu where you purchased this book from.
Click on
Code Download
.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Building-Bots-with-Microsoft-Bot-Framework. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/BuildingBotswithMicrosoftBotFramework_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at [email protected] with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.
In the past several decades, the corporate, government, and business world has experienced several waves of IT architecture foundations, moving from mainframes, to minicomputers, to distributed PCs, to the Internet, to social media / mobile, and now to the Cloud / Internet of Things (IoT) stack. We call this the sixth wave of corporate IT, and like its predecessors, cloud and IoT technologies are causing significant disruption and displacement, even while they drive new levels of productivity. Each architecture focuses on key business processes and supports killer technology applications to drive new levels of value. Very soon we will be looking at an enormous networked interconnection of everyday machines to one another, as well as to humans.
Lets have a look at the fifth wave of corporate IT:
The machine-to-machine-to-human connectivity will have a profound impact on the consumer and corporate IT experience. As these machines become social and talk to us, we have an enormous opportunity to greatly enhance their value proposition through improved product quality, customer experience, and lowered cost of operations. A heightened consumer expectation for more personal and real-time interactions is driving business to holistically embrace the next wave of technology innovation such as cloud, IoT, and bots to boost business performance. In this age of billions of connected devices, there is a need for such a technology where our apps, such as bots, could talk back. Bots that have specific purposes and talk to any device or any app or to anyone, live in the cloud, we can talk to via any communication channel such as e-mail, text, voice, chat, and many others, can go where no apps have gone before when it comes to the machine-to-machine-to-human connectivity. In order to make this happen, we will need a whole new platform, aplatform for conversations.
Messaging apps in general are becoming a second home screen for many people, acting as their entry point to the Internet; where the "youngins" are, the brands will follow. Companies are coming up with messaging apps as bots and apps that offer everything from customer service to online shopping and banking.
Conversations are shaping up to be the next major human-computer interface. Thanks to advances in natural language processing and machine learning, the technology is finally getting faster and accurate enough to be viable. Imagine a platform where language is the new UI layer. When we talk about conversation as a platform, there are three parts:
There are people talking to people. The Skype translator is an example where people can communicate across languages.
Then, there is the opportunity to enhance a conversation by the ability to be present and interact remotely.
Then, there are personal assistants and the bots.
The following screenshot shows the Conversation as a Service:
Think of bots as the new mechanism that you can converse with. Instead of looking through multiple mobile apps or pages of websites, you can call on any application as a bot within the conversational canvas. Bots are the new apps, and digital assistants are the meta-apps. This way, intelligence is infused into all our interactions.
This leads us to the Microsoft Bot Framework, which is a comprehensive offering from Microsoft to build and deploy high quality bots for your users to interact using Conversation as a Platform (CaaP). This is a framework that lets you build and connect intelligent bots. The idea is that they interact naturally wherever your users are talking, such as Skype, Slack, Facebook Messenger, text/SMS, and others. Basically, with any kind of channel that you use today as a human being to talk to other people, you will be able to use them to talk to bots, all using natural language:
The Microsoft Bot Framework is a Microsoft operated CaaP service and an open source SDK. The Microsoft Bot Framework is one of the many tools that Microsoft is offering for building a complete bot. Other tools include Language Understanding Intelligent Service (LUIS), Speech APIs, Microsoft Azure, Cortana Intelligence Suit, and many more.
The Microsoft Bot Builder SDK is one of three main components of the Microsoft Bot Framework. First, you have to build your bot. Your bot lives in the cloud and you host it yourself. You write it just like a web service component using Node.js or C#, like the ASP.NET Web API component. The Microsoft Bot Builder SDK is open source, so it will support more languages and web stacks over time. Your bot will have its own logic, but you also need a conversation logic using dialogs to model a conversation. The Bot Builder SDK gives you facilities for this, and there are many types of dialogs that are included, from simple yes or no questions, to full LUIS, which is one of the APIs provided by Microsoft Cognitive Services. This is what
