Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Chatbot project report, Summaries of Computer Science

Chatbot project report python programming

Typology: Summaries

2022/2023

Uploaded on 05/11/2023

aayush-tiwari-3
aayush-tiwari-3 🇮🇳

2 documents

1 / 38

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The Chatbot 1
CHAPTER 1
INTRODUTION
The purpose of this project is to showcase the power of chatbots and how they can be an
alternative to using an application or even a website. The chatbots should be easy to use,
respond in a timely fashion and be all round user friendly. The bots should make the users
interaction as easy and fast as possible to ensure that the users time is not wasted and that they
get what they want without any difficulty or misunderstanding from the bot. The conversation
should flow and always keep the user in control of the conversation. Users should come away
from their experience with the chatbot and think that it was a fun, easy to use and
straightforward interaction that would encourage them to come back without any hesitation.
With messaging platforms being the most used type of application in the world, businesses will
be looking to take advantage of this and start to develop their own chatbots to work along with
their social media pages. For example, a person calling a restaurant to see what time they open at
or what is the special today, the customer can simply message the page on Facebook and the bot
will respond accordingly. This frees up time for real employees to do other work and allows the
chatbot to handle the simple tasks. Since users will already have a messaging app installed on
their mobile device, there is no need to download a separate application to use the chatbot. This
can turn a lot of users away as nowadays there is an plethora of applications available and most
users will be fed up of having to download an application that they may only use once or twice.
1.2 Technologies
This application will be developed using one of Microsoft’s newest frameworks; Microsoft Bot
Framework. This framework allows for the bots to be built and deployed using Microsoft Azure.
Once the bots are hosted on Azure they can be then hosted on various other platforms such as
Facebook Messenger, Skype, Slack and more. For the purpose of this project, I will be mainly
using Facebook Messenger as a platform to showcase the bots I’ve developed as it is easily
available with the Messenger application and allows for easy testing.
The bots themselves are developed using C# using the Microsoft Bot Builder packages.
Microsoft’s LUIS is a language understanding and interpretation service that I’ve used to
process the data which the catbot receives and derive the intent from the users message. LUIS
works by taking the users input and scoring it against its database of intents and then performing
the function of the highest scoring intent. Users can have multiple ways of expressing a single
intent and LUIS is there to figure out what the user wants to do. Multiple packages and APIs
have been used in the development of this application including:
SendGrid Allows the sending of feedback emails entirely within the catbot.
Microsoft QnA Maker Allows me to host a FAQ database that a chatbot can then pull
information from and use it to answer the users questions.
Microsoft Computer Vision API Image analysis tool used to determine what content is in a
photo and return it to the user. This can be used to identify images and products.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Partial preview of the text

Download Chatbot project report and more Summaries Computer Science in PDF only on Docsity!

CHAPTER 1

INTRODUTION

The purpose of this project is to showcase the power of chatbots and how they can be an alternative to using an application or even a website. The chatbots should be easy to use, respond in a timely fashion and be all round user friendly. The bots should make the users interaction as easy and fast as possible to ensure that the users time is not wasted and that they get what they want without any difficulty or misunderstanding from the bot. The conversation should flow and always keep the user in control of the conversation. Users should come away from their experience with the chatbot and think that it was a fun, easy to use and straightforward interaction that would encourage them to come back without any hesitation. With messaging platforms being the most used type of application in the world, businesses will be looking to take advantage of this and start to develop their own chatbots to work along with their social media pages. For example, a person calling a restaurant to see what time they open at or what is the special today, the customer can simply message the page on Facebook and the bot will respond accordingly. This frees up time for real employees to do other work and allows the chatbot to handle the simple tasks. Since users will already have a messaging app installed on their mobile device, there is no need to download a separate application to use the chatbot. This can turn a lot of users away as nowadays there is an plethora of applications available and most users will be fed up of having to download an application that they may only use once or twice.

1.2 Technologies

This application will be developed using one of Microsoft’s newest frameworks; Microsoft Bot Framework. This framework allows for the bots to be built and deployed using Microsoft Azure. Once the bots are hosted on Azure they can be then hosted on various other platforms such as Facebook Messenger, Skype, Slack and more. For the purpose of this project, I will be mainly using Facebook Messenger as a platform to showcase the bots I’ve developed as it is easily available with the Messenger application and allows for easy testing. The bots themselves are developed using C# using the Microsoft Bot Builder packages. Microsoft’s LUIS is a language understanding and interpretation service that I’ve used to process the data which the catbot receives and derive the intent from the users message. LUIS works by taking the users input and scoring it against its database of intents and then performing the function of the highest scoring intent. Users can have multiple ways of expressing a single intent and LUIS is there to figure out what the user wants to do. Multiple packages and APIs have been used in the development of this application including: SendGrid – Allows the sending of feedback emails entirely within the catbot. Microsoft QnA Maker – Allows me to host a FAQ database that a chatbot can then pull information from and use it to answer the users questions. Microsoft Computer Vision API – Image analysis tool used to determine what content is in a photo and return it to the user. This can be used to identify images and products.

Facebook API – My bots are available with their own Facebook page. These can be accessed by anyone with a Facebook account. According to my research most users will already have a Messenger account with the app downloaded on their mobile device.

1. 3 Chatbots

A chatbot is an AI agent that can participate in a conversation with a user. Most are equipped with a messenger type interface with an input from a user and an output from the chatbot. The chatbot processes the users input and outputs a reply based on what the user has just sent. It could be a greeting, conversation topic, or even an image. Most basic chatbots work by matching an users input with a predefined set of dialog. For example, a user saying “Thank you” will result in the chatbot saying “You’re Welcome”. The predefined set of dialogs can be set up to imitate a normal conversation between two people. Problems can arise when a user says something the chatbot does not recognize, an example could be the user meaning to say “Thank you”, but instead says “Thanks a lot”, this can confuse the chatbotas it will be looking to match the “Thank you” input with “Welcome”. This leads to a lot of manual work by trying to define every combination of a user saying “Thanks”. Modern chatbots are more complex and feature natural language processing that can learn from user inputs. They can access APIs to get information users such as news, weather, time etc. They can even process orders and make bookings entirely through a chatbot interface. Chatbots are well suited for mobile devices as messaging is at the heart of a mobile phone. Messaging has come a long way since SMS messages became popularized in the 2000s and is now on the decline. From the years 2011-2015 the usage of SMS in Ireland has dropped by 44%. 3 billion texts in 2011 compared to 1.7 billion texts in 2015. [John Hargan, killbiller.com 2015] Although SMS is experiencing a decline, this doesn’t mean that people aren’t sending messages anymore, it just means they are using different services. It is fast becoming the norm where a chatbot is easier to use than an application, and businesses are taking advantage of this. With automation looking to takeover manual labour and factory type jobs, chatbots are starting to make their way into the customer service sector. Call centre and customer service jobs whereby a human worker will work off a script and a set of answers to generic customer queries will soon be replaced by chatbots. Chatbots can be trained and equipped to deal with the everyday needs of a customer, and they can do so at a very little cost. It is also worth mentioning that chatbots can run 24/7 365, giving customers what they need even during the Christmas and public holidays. With the cost of the development of a chatbot ranging anywhere from $3,000 to $10,000, it would be a no-brainer for a company to implement chatbot services to their customer service department. [Oswalt, 2017] Inevitably, there will be situations where a chatbot will not suffice and a customer will have to be redirected to a human representative, but it is still a step forward in cutting down costs and automation. Another aspect of chatbots that should not be overlooked is the data they can collect. Chatbots are just another stream of data that companies can exploit benefit from.

1.5 Facebook Messenger

Facebook Messenger is the most used messaging application in the world. With 1.2 billion users, it surpasses WhatsApp to be the most used messaging platform in the world. This is one of the reasons why I chose Messenger as my main social media platform to develop my bots on, another reason being that WhatsApp doesn’t have an official API for chatbots to take advantage of. Since Facebook owns WhatsApp it may not be long before we see this introduced. FIGURE : MESSENGER USERS [TECH CRUNCH, 2017

1.6 API.AI

Before I decided to work with Bot Framework, I also explored what other frameworks were out there. One of them was API.AI, which was recently acquired by Google. API.AI boasts a wide range of features with support for chatbots, wearables, apps, smart homes and even smart TVs. I started work using the framework but I soon discovered that a lot of the features available with it such as knowledge bases and API packages, were locked behind a paywall. I felt that it was more geared towards a development team and not really catering for a solo developer like myself. As I was just learning about chatbots and looking at my options I chose to stay away from API.AI mainly due to the premium only features. I also found that the documentation was not as easy to read as Microsofts Bot Framework.

FIGURE 2 API.AI FEATURES

Figure 2 above shows some of the features of their framework. They offer prebuilt bots that you can configure to your needs which would be useful but they are in fact locked behind a paywall. I also felt that it would kind of take away the fun of working on a project as everything is already defined for you with this framework.

1.7 Wit.AI

Like API.AI, Wit.AI is another framework I explored before deciding to use Bot Framework for my project. Wit.AI was acquired by Facebook, you can start to see the trend with all the major companies getting on board with Artificial Intelligence and language processing. Wit.AI works similar to the way Microsofts LUIS works by extracting the intent from a user’s message. This seems to be the direction most natural language processing entities are heading. With users seeking to use a chatbot solely for function instead of a conversation, deriving the intents of the user is the chatbots utmost priority. As well as API.AI, Wit.AI features support for bots, apps, smart homes, wearable devices and even robots. Wit.AI mainly focuses on users building their bots within their web client, a feature which I was trying to stay away from as I would prefer to actually write the code needed. As well as the web client, they offer documentation for development using Node.Js, Python and Ruby. All of which I am not too familiar with so this pushed me away from this framework and left me with Bot Framework. Bot Framework also supports Node.js but it has support for C#, a language I am familiar with and have used to develop many college projects throughout the years.

2.4 The chatbot must work on a web client: This requirement requires the chatbot to

work on a web client. From my market research, it was noted that although the majority would prefer a mobile client, there was a number of people who would also like to see a web client for the bots. The bots need to be configured on the Bot Framework platform to allow webchat embedding. This is achieved by hosting the bots on my website located at: http://karlfyp.azurewebsites.net

2.5 The chatbot must work on a mobile device (Facebook Messenger): This

requirement requires the chatbot to function on a mobile device, in this case, using the Facebook Messenger application. It is required to work on both Android and iOS. This allows mobile users to avail of the chatbots services.

2.6 The chatbot must work with LUIS: This requirement requires the chatbot to be

configured with a LUIS account subscription. This handles the natural language processing of the bot and the routing of the dialogs. Once a LUIS account is set up and a language model is defined with intents and utterances, the model ID and subscription key can be entered into the RootLUISDialog class. This allows the bot to function using the services of LUIS. Code Segment FIGURE 5 REQ 5 CODE SEGMENT

2.7 The chatbot must work with Computer Vision API: This requires the chatbot to

have a valid Computer Vision API key. This can be obtained from Microsoft Azure Service, once acquired it can be added to the Web.config file so it can be referenced by other classes. This allows the chatbot to access the Computer Vision API and make use of its services.

Code Segment FIGURE 6 REQ 6 CODE SEGMENT

2.8 The chatbot must work with SendGrid Email API: This requirement allows the

chatbot to make use of SendGrid email API to let the users give feedback within the chatbot. The bot must have a valid API key for SendGrid. Once acquired it can be added to the Web.config file where it can then be referenced by other classes. This requirement allows users to give feedback and also give their email to receive a response to their feedback.

CHAPTER 3

USE OF CHATBOT

The main usability requirement is that the chatbot and website are user friendly. The chatbot, in its own nature is user friendly since it is a simple chat interface. Everyone knows how a chatbot works as it is simply like a conversation with their friends. The messages come in on the main screen and there is a text box at the bottom to type in and a send button. Users must feel comfortable in the conversation and feel in control. To guide the users through the conversations, help messages should be in place to aid the user if they so happen to get stuck or are unsure of what to do. An example of this can be seen with the Pizza bot. If a user types “help”, the following message will be displayed: FIGURE 9 PIZZA BOT HELP MESSAGE This allows the user to view information about the option they are currently at and how they can answer. It tells the user how they can go back, quit, view the status or switch to another option. This more than meets the requirement of letting the user be in control of the conversation. Inexperienced or low skilled users will easily be able to navigate the Pizza bot with the help of the help menu. To ensure that users know about this feature, I’ve added it to the welcome message shown below.

FIGURE 10 PIZZA BOT WELCOME

As with the Pizza Bot, the NCI bot also has some usability features. Users will be greeted with a welcome message as and also how to cancel the current dialog if they get stuck. The website needs to be user friendly in that any kind of user will be able to open it up and easily be able to navigate through the different chatbots. The website must be accessible to mobile users as well as desktop users. The site has been designed in such a way that it accommodates to both groups of users. To ensure the ease of access of the different chatbots, I have featured them across the navigation bar at the top of the web page. This is shown below. FIGURE 11 WEBSITE NAVIGATIONAL BAR Facebook Messengers UI is user friendly and easy to navigate. Users that use the chatbots on Messenger will already have a Facebook account and will be familiar with how it works.

3.2 Environmental Requirements

The chatbot must be able to run on multiple platforms and operating systems. With the bots hosted on Facebook the bot will be available to anyone with the Messenger application running on their mobile device. Anyone with a computer can access the bots via my website which support all major web browsers (Chrome, Edge, Firefox, Safari, Opera) and runs with no issues. A mobile device can run the chatbots via a mobile web browser but I’ve found that it does not run as smoothly as in an application or on a computer. I would recommend that users use the application in either Facebook Messenger application or on my website with a computer to get the best experience.

CHAPTER 4

DESIGN AND ARCHITECTURE

This section outlines the design and architecture of the chatbots. The bots are developed using Microsoft Visual Studio 2015. The bots are constructed using Microsoft bot template. The main components of the application are the MessagesController.cs, Web.config, and the Dialog files. The dialog files will vary from bot to bot but they all provide a similar function; to support the dialogs of the application.

4.2 Architecture Overview

FIGURE 12 ARCHITECTURE OVERVIEW

Shown above is a diagram of the architecture overview of a chatbot. The bots are developed in C# using Visual Studio 2015 with the Bot Builder Source Development Kit.

From there it is pushed up to GitHub and processed my Microsoft Bot Service. This is where it interacts with the various APIs, services and chat channels used in the project.

4.3 Use Case Diagram

This diagram demonstrates the typical use of a bot. It shows what the user can do and what the chatbot does to respond.

CHAPTER 5

PACKAGES AND MAIN METHODS

LUIS is used for natural language processing. It is a language understanding service developed by Microsoft that works be finding the intent of the user. I have incorporated LUIS into the majority of my chatbots as it allows me to figure out what the user intends to do and point them towards the right dialog/method. It allows users to express their intent in a multitude of different ways and still be understood by the chatbot. I feel that this is what makes the chatbotsintelligent, they are able to figure out what the user wants no matter how the user phrases it. Below is a sample of a LUIS dialog, in this case, the RootLUISDialog class. What’s happening here with [LUISIntent(“Timetable”)], means that when LUIS detects that a users intent is to view a timetable, it will execute the StartTimetableDialog method, which then initiates the TimetableDialog class which holds the information and images of the timetables. It also has handler so if they botdoesn’t understand the users input, it will send “Sorry I didn’t understand.” FIGURE 14 ROOTLUISDIALOG CLASS Also in Figure 14, it shows the LUIS intent for Faq. This works the same as the timetable intent, where it initiates the QnADialog class that I will explain later on in this report.

5.2 General Response Dialog

This class is used to handle all of the generic parts of a conversation, from hello/goodbye to thankyou/you’re welcome. Below I have shown a sample of the class. It works using the BestMatchDialog which function by having an array of user messages and a reply based on what the user has sent. In the first method seen below, you can see a variety of ways the user can say “Hello”, all of these messages will still get the same response; “Hi there”. This prevents the bot from getting confused if the user means to say hello but phrases it differently. The threshold parameter gives some leeway for spelling mistakes and allows for some slight difference in the phrasing. FIGURE 15 GENERAL RESPONSE DIALOG

5.3 Global Message Handling

Global message handling allows me to reset the bot and return it to its initial startup state. This is useful when the bot is using multiple dialogs and it can be hard to navigate through them back to the start. By setting up global messaging handling I was able to assign a key word, in this case “Cancel” that returns the bot to its startup dialog. This works by setting the bot to check every message for the keyword “Cancel” before processing the methods that are in place in the current dialog. In the pizza ordering bot, this is very useful as if the user makes a mistake while submitting their order they can simply type cancel to reset their order and continue from the start. In order to do this, I needed to set up a Cancel class, which looks at user’s messages for the keyword “Cancel”, and resets the dialog. As with the GeneralResponseDialog and QnA dialog, there is a Score method that allows you to set a threshold for the keyword. In this case I do not want the bot to be making a guess at what the user wanted to do so I’ve set it to 1.0 to avoid any

5.4 Security

As a cyber security student, I felt that it was fitting that I touch on the security aspects of this project. Unfortunately, there is not very much to cover as since the bots are hosted online with 3 rd^ parties, the security side of things is taken away from me. One feature I did implement was on the chatbot website I created. I added a “RequireHttps” attribute to the Home controller which handles all the bots hosted on the site. This ensures that users have a secure connection when chatting with the bots on the site and can prevent the conversation data from being view or even intercepted. Although I couldn’t implement many security features to this project I did consider the privacy policy of Facebooks Messenger. Users wishing to use chatbots on Messenger will have to be aware that their conversations data may be being used for research purposes or even to generate an advertising profile of the user. For example with the Pizza bot chatbot, Facebook will store information such as delivery address and payment information. Shown below is an extract from their privacy policy page. FIGURE 17 FACEBOOK PRIVACY POLICY

Also shown in this extract is that Facebook tracks device information and even your location. It is important that users understand that they are handing their data over to Facebook when they make use of the chatbots hosted on their site.

5.5 Implementation

Implementation was the hardest part of this project. I was working with a Framework that I never used before and was still in development. It took me a lot of trial and error and a lot of reading to really understand Microsofts Bot Framework. Once I had a bot set up and ready to be worked on one of the hardest things I found was trying to control the dialogs, meaning that when I started to further develop the bots to be multi- functional, I ran into difficulties with that. Working on a bot that one main function was fairly easy once I knew what I had to do. As soon as more functionality was added some issues started to arise. Some of the issues included bots getting stuck on the same dialog, or sometimes even just getting into a loop of saying “Sorry I couldn’t understand you.” An example of this issue is with the NCI bot. I could implement the FAQ part fine and that caused no issues but the bot would get confused when the user was looking for something other than the FAQ, even something as simple as saying “Hello” or “Goodbye” could sometimes cause the bot to get stuck and crash.To overcome this, in the Messages Controller(Where the conversation starts off, landing pad for the user and bots conversation), as soon as a conversation is initiated I send the welcome message (Figure 16), FIGURE 18 WELCOME MESSAGE The conversation then heads towards the RootLUISDialog class. (Figure 18) FIGURE 19 SEND TO ROOT