Creating a Chatbot-Based Reservation System with Pandorabots

Posted 4 months ago by Petr Bednar

Pandorabots logo

If you’ve ever shopped online, created a playlist with Spotify, or tried to learn a new language with Duolingo, or chatted on WhatsApp, you’ve interacted with a chatbot. In addition to being used by industries as wide ranging as news sites, retail, and real estate, chatbots have also become quite popular. According to a recent survey by Forbes, 62% of consumers in the U.S. like using chatbots. 

Given the prevalence of chatbots and our love of technology, we decided to create a bot-based system, using natural language processing (NLP) to automate a familiar and person-to-person task — a bot-based reservation system. In addition to creating a system that provides value by saving time and money, we also wanted to create something that could create a positive customer experience and potentially boost customer satisfaction.

Because we are advocates and users of open standards, we used Pandorabots, an AI company that provides a free, online web service for building and implementing chatbots using AIML (Artificial Intelligence Markup Language). With more than 275k registered developers, Pandorabots (PB) is one of the oldest chatbot hosting services in the world. The platform provides a web user interface for creating AIML files and structures, test environments, logs, statistics, and many other features, such as APIs for manipulation or communication with the bot. 

In order to work with PB’s API, you need to activate a Developer or Pro account, which you can use in a 14-day, free trial. To understand AIML structure, Pandorabots offers free AIML courses on Udemy.com. In addition, their documentation is well-written, and we always found everything we needed, including how to work with their API. We found that the courses on Udemy.com were very clean and helpful.

Our Approach to Implementation

As illustrated in the following diagram, example technologies for implementation include PB with AIML for creating a chatbot, Google Calendar API for getting and creating events, and a Flask-RESTful framework as a BE service for communication with both APIs and for resending messages to end-users:

Architecture our application

AIML is an XML-based markup language which defines the personality of a chatbot. AIML is easy to understand and to maintain. It took me around 3 hours to understand the basic structures I needed.

Example of the AIML

We used Flask with the extension of a Flask-RESTful framework, which let us quickly build a REST API.

Why did we choose this approach?

Because the Pandorabots architecture lets us implement the integration BE (backend system) service as stateless for the client communication session, we don’t need to store the context, because all data is stored on their side. Data from user input, like a date or the name of an appointment is also stored in each user’s chat session, so each chat room is independent of others. Another reason was that we needed a simple solution that solves AIML, that is developer-friendly for a faster understanding of the general structure of AIML.

Architecture

We wanted to fully utilize the possibilities of the AIML for communication between the client and the bot, as well as for communication between the bot and the BE. For that, we added custom AIML tags to the answers from Pandorabots, like XXGE, XXGR, XXCE, and so on. We listened to these tags on the BE and triggered specific actions in Google Calendar, as shown in the following sequence diagram:

For example, if the BE receives XXCE in a PB response, it will call the Google Calendar API to create a new event in the calendar. If the event is created successfully, our BE will talk to PB again with tag XXCEOK, and forward the preformatted response back to the client when something fails our BE return XXCEFAIL. This tag will be sent to PB again, and will return the relevant answer for this tag. If BE gets tag XXGE, it will ask the Google Calendar API for data, and replace the tag in message with returned data and forward response. Here is an excerpt of the AIML and Flask API code: 

<category>
      <pattern>^ BOOK ^ APPOINTMENT ^ TODAY ^</pattern>
      <template>Available time slots <set name="year">
            <date
format="%Y"/></set>.<set name="month">
            <date
format="%m"/></set>.<set name="day">
            <date format="%d"/></set> are:XXGE{"day":"
            <get name="day"/>","month":"
            <get name="month"/>","year":"
            <get name="year"/>"}Select time 
      </template>
  </category>
  <category>
      <pattern>XXGEFAIL</pattern>
      <template>Something is wrong, try it again.</template>
  </category>
  <category>
      <pattern>XXDATEFAIL</pattern>
      <template>At this time, we are closed.</template>
  </category>
  <category>
      <pattern>^ CREATE ^ APPOINTMENT ^ TODAY ^</pattern>
      <template><srai>BOOK APPOINTMENT TODAY</srai></template>
  </category>
  <category>
      <pattern>^ CREATE ^ RESERVATION ^ TODAY ^</pattern>
      <template><srai>BOOK APPOINTMENT TODAY</srai></template>
  </category>
  <category>
      <pattern>^ MAKE ^ RESERVATION ^ TODAY ^</pattern>
      <template><srai>BOOK APPOINTMENT TODAY</srai></template>
  </category>

AIML structure


Flask API code

Advantages and Disadvantages of Our Approach

Our approach has specific advantages, but also disadvantages. One advantage is good maintenance. This is easy, because PB logs all activities. Also, adding any communication platform as a client should be simple with our REST API. 

AIML capabilities allow acceptance of several, different inputs, such as “Create an appointment for me,” “Make a reservation for me,” and “Book a visit for me,” that will be redirected to a single, specific action in Google Calendar. Several AIML files are publicly available and can be used to extend our conversation bot. This lets us easily extend the bot’s general conversation capabilities. Furthermore, when we need to update any response, it is really easy to do so.

As for disadvantages, the time response of PB API, which is between 600–2400 ms. For example, consider a user request which triggers two calls to the PB API, as well as calls to Google Calendar API. This may cause increased latency time. This is probably not a big deal, as people are used to waiting for an answer during the usual conversions on messaging platforms.

As the number of clients increases, monthly costs also will be higher. It also causes a restriction of the number of messages per month. If you are considering a high load, you probably could invest in your own implementation of AIML, using available Python libraries. 

Potential Improvements/Features

Extending our project in the future is possible with many features. One of the most important improvements can be working with multiple customers on our BE, as we are currently working with only one customer. After adding the aforementioned feature, we can consider adding a UI for customers that could include allowing access and authentication with Google Calendar, setting up open hours, adding to a messaging platform, and so on.

Also, we didn’t implement a connection with any communication platforms like Facebook Messenger or Slack. However, each platform that offers communication via an API should be simple to add, as mentioned above. We also could add additional reservation platforms, instead only using Google Calendar.

Another idea to improve the product is better time management. For example, to set up opening hours and the length of the booking, as bookings are currently only in 60 minute intervals. We could change bookings to intervals of every 30 or 15 minutes.

The following images show the communication between client and bot. The first one shows communication between client and bot on the left side and backend communication in Pandorabots on the right. You can see a more complex client – bot communication on the second image:

Conclusion

After exploring the options, we decided to use PB with AIML to build a chatbot that integrates with the Google Calendar. Working with PB and AIML was pretty intuitive. Machine learning could be an alternative. In order to create a chatbot based on ML, we would need a huge dataset, training, and advanced knowledge. It won’t be as easily customizable as with AIML. Also, performance is on the AIML side, because with increasing robust latency, time will be constant.

Even though this was my first experience with PB, I was able to ramp up pretty quickly, and intuitively navigate the PB UI and the developer documentation. The AIML structure was also easy to understand. As a result, I was able to quickly create and adjust the chatbot.

Petr Bednar

Leave a Reply

Related articles

Contact us now

Your message has been sent. Thank you!