C, C++, C#, Java bad practices: learn how to make a good code by bad example

Chatbots, and how will Microsoft help us with this?

This overview article is devoted to the study of a trend which is growing rapidly in popularity in the IT industry – chatbots, and the role of Microsoft in their development process. The article will cover the history of chatbots, peculiar properties of bots, the main, and also some unexpected spheres of their application, perspectives and technology limits.

We have deliberately chosen Microsoft as the main platform for comparative research. The company does a lot of work in the field of promotion and development of intelligent bots. One of the main steps in this direction is a framework for creation of custom bots Microsoft Bot Framework platform – independent and open source; Microsoft presented it at the Build 2016 exhibition.

Introduction

Generally, a chatbot is a program that can imitate a meaningful dialogue with the user via text or speech in the language known to the user. The goal of such a dialogue, is often to answer the user requests and execute bot commands. Not being something substantially new, chatbots however, are positioned in the marketplace as a sort of know-how activity. Of course, the fuss created around such bots as smart and often an indispensable assistant for the users, plays a huge role.

Chat bots won’t let you get bored while interacting with other users of Messenger, entertaining with a fresh joke or game; they can send the current weather forecast; help with ordering pizza; advise about healthy eating in response to a message about your weight and blood pressure; dialogue with you on legal services websites, simulating a real interlocutor; can ask you in a pleasant voice about your mood and, based on analysis of your response, select a musical composition on your smartphone; can easily cope with the role of a support service specialist of any service by e-mail. These are just a few small examples of what smart bots can do. There is also a separate group of corporate bots, solving important corporate tasks.

Like any new technology, chatbots are a logical development of the more familiar methods of communication with, and conveying of information to, an end-user: web sites, applications, push notifications, etc. This technology is attractive, first of all, due its end-user focus, integration into the final platform, ease of use, intellectualism, and friendliness.

Major IT players (primarily on the market of online communications) have already evaluated the potential and possible benefits of using chatbots in their solutions a long time ago. Bots in one form or another are used extensively in all popular messengers, Internet platforms, and mobile devices.

Microsoft is actively involved in the development, working in several directions: mobile assistant Cortana; not a very successful, but certainly an interesting experiment with a female bot. Tay on Twitter; a more successful experiment in China with a female bot Xiaoice (Saois); bots for Skype; and finally, the Microsoft Bot Framework for creation and integration of its own bots into various platforms.

A little bit of history

The first chat-program is thought to be ELIZA, created in 1964 by a professor at the Massachusetts Institute of Technology by the name of Joseph Weizenbaum. The program tried to imitate the communication of a user with a psychotherapist, and often could confuse patients with astoundingly realistic behaviour and phrases like: “Would you like to talk about that?”.

After that a lot of attempts were made to create similar virtual chatter, but all of them were very simple, and the person easily recognized that he was dealing with a machine.

The term ‘chatbot’ was supposedly introduced by a developer Michael Molding, who created Julia in 1994 – a programme for communication, and he called it a chatbot. The program wasn’t a very sophisticated one, but nevertheless, it was able to carry out a more or less meaningful talk, and had a self – learning function.

In the late 1990’s and early 2000’s, simple chatbots were actively used, for example, in IRC and IM-programs, to make the dialogues more lively, and to moderate chats. And, of course, enthusiasts and researchers from all over the world have never given up on the idea of creating a truly ‘smart’ program to carry out a meaningful dialogue with users.

All this, as well as the natural evolution of technology, has led to significant progress in the area of creating intelligent chatbots. A chat program has already been created, which was able to pass the Turing test. On the 8 June 2014 at one of the events organized by the Redding British University, a program created in Saint-Petersburg successfully imitated communication with a real person and managed to mislead some of the examiners.

At the same time, the DeepQA program, which is based on the IBM Watson supercomputer, is able to process incoming commands in natural language. The technology ‘Nuance Communications’, which was used for it, was also implemented in the development of Siri, which works on Apple devices.

Modern chatbots have reached heights that were completely impossible for pioneer programs like ELIZA. They use up-to-date research in the sphere of natural language analysis, have advanced algorithms of artificial intelligence, and are able to educate themselves.

Application field

You may see chatbots on practically every platform, whether it is a messenger, a web-portal or a smartphone. They are used to meet the needs of a customer, performing specific scenarios.

The chatbots are usually grouped in the following way according to the scenario they perform:

Technical support.

Searchingby the specified parameters;

Consumption of content and entertainment;

Purchases.

Technical support. Many service companies have long and successfully been using voice chatbots and text bots via e-mail for technical support. Some of these companies state that they save up to 40% of the cost that was previously spent on human technical support. The main advantage of chatbots in this case is the ability to work without taking any breaks, and at night, as well with a large number of clients simultaneously. The disadvantages are typically is the lack of intelligence of such bots. In complex cases the operator should get involved in the dialogue too.

Searching by the specified parameters. Using chatbots to search the Internet, in my opinion, is still not as convenient when compared with classical methods. Of course, if you’re using a bot that is embedded in your smartphone or your messenger, you won’t have to switch to another application to start the search. Still, you will need to somehow formulate your question, and then, perhaps, answer some additional questions from the bot in order to achieve the result. During this time any search engine would already have given you the result. An article by Ariel Werber is exactly about this – he compares the usability of a search bot and Google.

Consumption of content and entertainment. This area is more developed in the question of bot – development, but here we may also have some previously described problems. Nevertheless, bots downloading content through subscription make the situation slightly better. Usually such content is news and articles. The bot does not only deliver the required content, but also filters it by topic, content relevancy, and so on. Also, the bot can analyze the user history and recommend more content. A lot of large information portals and news aggregators are actively using their own bots to simplify access to their materials. We can also include all sorts of bot-assistants, game, and entertainment chatbots. It is no secret that one of the most popular aims, for bots in Messenger Telegram, is dating.

Purchases. Perhaps the most interesting area of chatbot usage, is allowing connection of a virtual-assistant and real world objects; the imitation of a real dialogue, and the focus on particular users brings the bots and people together, in a way. However, unfortunately, this usage scenario is now the least developed one. The reasons are quite varied: this is the absence of the ability to produce the payment directly through the bot interface and inadaptability of this interface for such operations. Such a bot could be useful in choosing a specific product. But working with a wide assortment and complex trading options are too hard for it. In this case, the functionality of a virtual bot-trader limits to a search bot.

The development of chatbots is still on going. New application areas emerge, and the old scenarios get better. For example, ‘Kik Messenger’, that is especially popular among teenagers in North America, allows adding of a bot to the chat by scanning a QR-Code with a smartphone. Thus, you can talk for example, with a virtual waiter at a cafe and make an order before you see a real waiter. In China the purchase function is successfully implemented in the WeChat messenger: currently internet trade is actively developing, also by means of chatbots.

Chat bots market

Today messengers confidently hold the leadership in chatbot usage. And it is not surprising, because the applications for instant messaging and content exchange between users is the most suitable place for chatbots. It was the active development of messengers that gave a significant boost to chatbot usage. Activate company brings the statistics which shows that there is at least one Messenger per 2.5 billion people. The leaders are Facebook Messenger and WhatsApp. Experts predict that in the next 2-3 years, more than half the Earth’s population will be users of messengers, which will become more popular than social networks over time.

The additional factor of chatbot promotion in messengers is support of large business. The majority of companies gradually come to the understanding of how much more profitable it can be to create and integrate specialized bots for customized promotion of goods and services in messengers, in comparison with the development of complex internet portals and applications. Besides that, according to analysts, the interest of users to new applications steadily declines. Most people are too used to using their proven set of messengers, social networks, and programs installed on their devices.

Nowadays a lot of people are involved in the creation of chatbots: these are usual users who do it for their own interest, and industrial giants, aiming to attract new audience and to promote their services. This direction is quite well promoted already. You may find a great number of exhaustive manuals on the creation and promotion of chatbots of any functionality and complexity. Here is an example of a good article on this topic.

One of the pioneers of the creation and promotion of chatbots is Telegram. In June 2015, Pavel Durov’s company was one of the first to launch the platform ‘Bot API’, and a shop to download bots. At this point there are more than 100 thousand different bots in the Telegram messenger. Now there is also an improved version of API to create a custom Telegram bot Bot API 2.0. You can use practically any language to create the bots: PHP, Python, Java, C#, Ruby. You can also create your own Telegram bot yourself, without having any skills in programming. You can use service account @BotFather to register a new bot and obtain a unique id, and then through the @Paquebot account you will be able to bind its bot to @Paquebot and start sending messages to all subscribers of your new bot.

Other instant messengers also try not to fall behind. Facebook also announced a platform for creating bots in its messenger in March, 2015. The ability to create bots has become a part of the service Messenger Platform that allows the integration of Facebook chat into other applications. “API for sending and receiving messages is more than enough. But if you want to create a more complex bot, use our Bot Engine”, – said David Marcus, Facebook vice-president. As noted, the Bot Engine will ‘teach’ bots to behave in different ways depending on the situation. Unlike competitors, Facebook already allows users to send not just plain text, but interactive ‘cards’ with images, links, buttons, and other elements, with which you can interact. Talking with the robot, the user can instantly book a table at a restaurant, or buy a product at any time, leafing through the product catalog.

The development of custom services to create chatbots, and integration of bots into instant messengers and other platforms have long become more than just a nice addition to the program, theyt have become a vital necessity. A great many services around the world are actively promoting the idea of using bots. Search engines: American Google and Russian Yandex; messengers: Chinese WeChat, Japanese Line, South Korean Kakao Talk, Canadian Kik, etc.

Smartphone makers are not sitting by idly either. The voice assistants Siri from Apple, and Cortana from Microsoft, use voice interface to handle user requests. Amazon’s American company also has a voice assistant.

According to experts, in the near future, we may expect even greater integration of chatbots into existing platforms, as well as increased monetization of this direction.

Microsoft contribution

In March 2016 the Microsoft specialists launched a Twitter chatbot named Tay (@TayandYou). Tay could also be added to the list of contacts in Kik messenger or GroupMe social network. Initially, the developers communicated with the program themselves, teaching it using large amounts of data from social networks. A small group of people also participated in the training. According to the authors’ idea, Tay, who was imitating a teenage girl, had to continue learning from the users after she was introduced to the public. The idea worked, but in less than 24 hours after communication with the users, Tay turned into a Nazi, anti-Semite, and a man-hater. The program successfully learnt everything that it was taught. Unfortunately, the creators of Tay weren’t able to program in the ability to distinguish the good from the bad. For some time Microsoft tried to control the behavior of Tay, editing some particularly insulting sayings. But very soon the experiment was claimed as finished and Tay was turned off. However, in the course of this event, Microsoft got a nice promotion boost, and fuelled interest in the sphere of artificial intelligence and chatbots.

Another similar experiment involving Microsoft turned out to be more successful. On the Chinese equivalent of Twitter (Weibo) a bot named Xiaoice (literally: “Microsoft Little Ice”) was launched. The bot imitates the behavior of a 17-year old teenager girl, can hold a meaningful dialogue, can express some sympathy, and is quite often very unpredictable, like a usual person. Apparently,working on Xiaoice, the creators took into account the previous negative experience with Tay. Millions of Chinese teenagers spend hours chatting with Xiaoice, calling her ‘a sympathetic and caring girl’.

On the 30th March, at the Build 2016 exhibition Microsoft presented its platform Microsoft Bot Framework for creating audio and video bots for Skype, Slack, Facebook Messenger, Kik, Office 365 e-mail service and other popular services. The platform consists of three main parts:

Builder SDK bot: a set of open source tools (Node.js, .NET or REST available for development) for building and testing the chatbots;

Bot Directory: a collection of bots, created with Bot Framework, and registered in the Developer Portal, designed for downloading and checking bots and exchanging the experience.

The main advantages of the Bot Framework platform are the absence of binding to a particular platform, the open SDK code, developed tools for debugging and testing, built-in means of communication and management of web-applications, support of automatic translation into more than 30 languages, and community support. At the same time the platform Microsoft Bot Framework continues actively developing.

Other announcements were made at the Build 2016 conference – a new version of Skype with the support of bots for Windows, Android, iPhone and iPad, and the opening of SDK and API for Skype Bot Platform. You can use the bot catalog to add a bot to the contact list of Skype, Slack or Telegram. In the new Skype version for iOS and Android, the search of bots is already built in the application.

Microsoft claims that in the near future we will be able to talk with the chatbot in natural language via an audio or video call (Skype Video Bots). The bot will have a 3-D graphical representation and an advanced Artificial Intelligence. The Microsoft corporation is sure that the use of bots for the automation of simple user actions, and voice control will change the usual ways of communication, games, purchases, and so on.

A fly in the ointment

But do bots really have such a huge potential, that they will soon be able to replace usual applications, search engines and human-assistants? Will they become an irritating or even a dangerous factor over time? There are various opinions on this topic.

One such point of view: chatbots are no more than a new mechanism of interaction with a user. This is logical continuation: sites-applications-chatbots. For this communication, there is no need for the bots to have developed intelligence. The bot just needs to have a well-thought out set of commands. The usefulness of such a bot is our question.

Another point of view is that bots are, in fact, just an extra way of getting information. We already have enough of everything. To download a new issue of a favorite magazine or an application from an App Store, it’s not really necessary to start a messenger, look for a chatbot, talk to it, answering 2-3 questions and only then get what you need. The existing applications are still there, they are very convenient and always on hand. Only bots that are taking part in the correspondence process: translators, analysts and statisticians, can be useful.

Even now, it is not yet possible to create a chatbot that could effectively promote products. Not just to offer the person the thing that he has already chosen, but to persuade a person to buy something. Of course, the experiments we already see in the field of creation of clever chatbots are very impressive. But they still have room for improvement. Quite an illustrative example could be the comparison of a chatbot with an ATM. Yes, the ATM will do the usual routine actions with less errors and will interact with the user. But the ATM will never be able to persuade a person to get credit.

We can definitely tell that the issue of chatbots being so convenient, intelligent, and even irreplacable is overheated, and kept in such a state by the manufacturers of messengers (which is the main location for bots), and the owners of the main platforms. And often, only the owners of large platforms can afford to create a really intelligent chatbot, that would combine advanced artificial intelligence, as well as an extensive set of functionality.

Right now you can create a bot using quite varied means. You can create a bot without writing a single line of source code, using a special service provided by the messenger platform. You can use a third-party service, such as Chatfuel for example. There are free development tools available, such as Microsoft Bot Framework. Finally, you can purchase tools for creating a bot via the Gupshup. But will your bot be intelligent enough, that it could fully compete with applications already familiar to the user? Will your bot fit into the environment, so that it becomes irreplacable? Or it will join a large pack of quite decent, but fairly similar virtual assistants?

Most likely, the industry of chatbots will go on the same scenario as mobile internet-applications. In the end, only the “smartest” bots, those that are of higher demand and most fitting into this specific environment, will survive.

Conclusion

The original idea of this article was that at the end of it, we would tell about the bugs found in the source code of Microsoft Bot Builder (available in GitHub) with the help of PVS-Studio. However, it turned out that the Bot Builder contains a total of 50 thousand lines of code in C#, available for analysis (the remaining source code was developed using Node.js and REST). In addition, the code has proven to be of very high quality, which is not surprising for Microsoft. During the analysis of the Bot Builder solution, we didn’t manage to find a large number of bugs, except a couple of suspicious constructions, which aren’t very critical, but nevertheless, requiring some attention. It definitely wasn’t enough to write a full article about the project check as we usually do. It happens. Nevertheless, the Bot Builder is still actively developing, and in the future I will repeat this experiment in the hope of finding more interesting bugs in the code of this platform, and will tell the readers about that. Now I will just give a short description of those bugs we managed to find. Both errors are connected to the potential access by a null-reference.

The given code fragment will work properly, until the step variable will have the type FieldInfo or PropertyInfo. Otherwise we may have an access by the null-reference, as there is no additional verification against null for the prop variable.

PVS-Studio warning: V3105 The ‘parts’ variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. JwtTokenExtractor.cs 60

In the next code fragment the author supposes that the variable authorizationHeader can be null. In this case the variable parts will also be initialized with null. However, later the variable parts is used without the necessary check, which can lead to the exception NullReferenceException:

In conclusion, I would like to point out that the topic of creation and promotion of chat bots is quite interesting. This direction will continue developing, and in the future we expect new interesting experiments with chatbots, as well as the use of Artificial Intelligence.

Create your own chatbots and check their source code with the help of PVS-Studio analyzer.