Building a Bot as an Alternative to Classic User Interface. Why is it better?
Tags: azure, azurebotservices, cloud, nasa
Published: 2021-03-22 09:39:34

---
title: Building a Bot as an Alternative to Classic User Interface. Why is it better?
published: true
description: Creating a Bot with NASA API and Azure Bot Services, including Language Recognition. Part1.
tags: Azure, AzureBotServices, Cloud, NASA
cover_image: https://miro.medium.com/max/3000/1*VHVNYcPoYkPVq02SgyBn2A.jpeg
---
My team and I were working on an open-source customer project in the aerospace domain that provided scientific data for students and university data scientists. After several attempts to build a classic Web UI application, we moved to a simplified Bot Flow. And this is why and how.

![alt text](https://miro.medium.com/max/875/1*4pGojA07FY195Ldyfsx_RQ.jpeg "nasa-bot")

The project has a short and straightforward data response. It contains only essential data like:

- Coordinates.
- Event time frames.
- Source type, etc.

However, some messages have links to the detailed report that is a classic Web UI. Having a chat with a bot is more natural as you feel like you are communicating with a person.

## Azure Healthcare Bot

Here is another good example of how bot service can be convenient in our daily life. Recently Microsoft has launched the Healthcare Bot Service.

- [Overview of the Healthcare Bot service.](https://www.microsoft.com/en-us/research/project/health-bot/)
- [Technical documentation that includes architecture overview, how to build it, and service concepts.](https://docs.microsoft.com/en-us/azure/health-bot/)

![alt text](https://miro.medium.com/max/875/1*wnbMVJ1SJuCY3BuPgFQpyw.png "nasa-bot")


## Introduction

In this article, I build a simplified version of a Bot that aggregates data from NASA API and provides the user with a simple workflow and short data feedback. Also, I use Azure Language Recognition (LUIS) service to improve and simplify the conversation flow.

The NASA Bot contains the following functions:

- Gather data from the NASA API.
- Aggregate and simplify data payload.
- Recognize the user input with Azure Language Recognition (LUIS). We will go into the LUIS below.

Before we dive deep into the details, let’s examine why the Bot is better than a classic UI.

Using the bot approach may significantly improve the user experience if you have:

- Simplified and short data payload.
- Intuitive user interaction flow that looks like a Q&A dialog.
- No complex UI.
- Focus on content.

UI is better than a Bot if you have:

- Complex data payload.
- Complex UI forms (Admin Portals, Editors, Maps, News Portals, Calendars).
- Complex data visualization (Dashboards, Charts).

The best option may be to combine both approaches and use all benefits from a Bot and a classic UI.

## Why NASA API?

I have chosen NASA API because of:

- A granular and quite simple API design.
- Well-documented API calls.
- Easy and fast registration process.
- API key request.

![alt text](https://miro.medium.com/max/875/1*Kf4KVcUskCmviWHy1CDkCg.jpeg "nasa-bot")

NASA API is divided into categories or sub APIs, like:

- Space Weather Database Of Notifications, Knowledge, Information (DONKI)
- Mars Weather Service API
- Two-line element data earth-orbiting objects at a given point in time (TLE API)
- Satellite Situation Center

[NASA API with other calls.]("https://api.nasa.gov/") 

# Why Azure Bot Service?

Azure Bot Service, alongside the Bot Framework, provides you with an opportunity to build, test, store your Bot. Bot Framework includes tools, SDK, AI services, and templates that allow you to make a bot quite quickly.

In my case, I have created a project with Visual Studio using the template and installed a toolset, SDK, and templates. I have used .NET Core and C#. However, this framework also allows using JavaScript and Python.

## What is LUIS?

LUIS is a language understanding service that allows you to build and train your Bot to understand a natural language. I have included LUIS in my Bot to provide people with information from NASA API using different natural language construction.

- [More information about LUIS.](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-luis?view=azure-bot-service-4.0&tabs=csharp)

For the current project, I have trained LUIS manually using the LUIS Portal. Below you can see that I added language sentences to train the LUIS to recognize user feedback and set the score. The LUIS portal also contains an option that allows you to test your data set and deploy it to different stages.

![nasabot](https://miro.medium.com/max/875/1*LmBZPKWNLxUe1GtDkNGI5A.jpeg "nasabot")

![nasabot](https://miro.medium.com/max/875/1*E7GYXDqGDcImX0OVt8ImGA.jpeg "nasabot")

Of course, a manually trained model is suitable for small and middle-level bot projects. You should consider using pre-trained models that you quickly find in JSON format or set up for the production application.

You can also improve language understanding by adding [QnA (Question and Answers)](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-qna?view=azure-bot-service-4.0&tabs=cs) and [language generation templates](https://docs.microsoft.com/en-us/azure/bot-service/language-generation/bot-builder-howto-use-lg-templates?view=azure-bot-service-4.0&tabs=cs). 

# NASA Bot Architecture Overview

The NASA Bot architecture represents an N-tire structure based on an MVC pattern. The Bot includes API Controllers, Models, and Services.

![nasabot](https://miro.medium.com/max/875/1*njOoajhI3IRGXNIlrYvBhA.jpeg "nasabot")

The NASA bot consists of the following main components.

1. Nasa bot class is a component that contains the conversation flow event handlers like: MembersAdded and MessageActivity. And it also serves as an entry point to start a conversation flow.
2. External API aggregation service joins logic related to language recognition and fetches data from NASA API.
3. NasaApi library subproject is a wrapper of Nasa API calls. It contains logic to obtain, parse data from API and build a proper response for the business layer.

You can find [code examples and the NASA Bot project here.](https://itnext.io/building-a-bot-as-an-alternative-to-classic-user-interface-why-is-it-better-6ce4fd6fdabb)

Below is the list of other bot components with a link to the GIT repository:

- API (and BotController) is an endpoint to the Bot, and when you create your Bot with Visual Studio or VS Code, it creates a project that looks almost like a Web API project. The Web API is based on an MVC pattern.
- LanguageRecognitionService connects the Bot to the LUIS API and triggers the language recognition process.
- ObservationTypeModel contains all fields related to LUIS Response, including maximum intent score calculation logic.

## Conversation workflow

Below, I have added several screenshots that demonstrate an interaction with the Bot. As you see, here I used Bot Framework Emulator. 

![nasabot](https://miro.medium.com/max/875/1*1IA_zfMKn0K2Qb9ZoNhhUQ.jpeg "nasabot")

![nasabot](https://miro.medium.com/max/875/1*xQ5xo9qYd2G_JsHXEkw_JQ.jpeg "nasabot")

## Conclusion

The article demonstrates the main advantages that bot services can bring in comparison to UI interfaces. In the next article, I will extend the Bot by adding more advanced features.

The [link to the git repository](https://github.com/Boriszn/NASAbot) where you can clone the project.

## What is next

In the next article, I will upgrade the Bot by adding:

- QnA maker and models
- Unit Tests
- Other APIs
- Improved language recognition (Involve language generation)
- Bot deployment across multiple channels (Telegram, Slack)

Please feel free to suggest your ideas on what else should be added to the Bot or covered in the next article. Looking forward to hearing from you in the comments.