Monday, May 25
Shadow

How to integrate API in Rasa chatbot for the user

Technology is everywhere…? Technology is everything…? Technology is with everyone…? In this generation where technology is everywhere and it is so important that the competition is at its peak. So in this huge competition we must know how to grab the audience attention so that the user will choose your technology (Rasa chatbot for now) over any other technology. To learn and understand these ways to grab the audience attention we need to attract the audience first with the best UI that we can offer to the our user. To understand this I have come up with this and the upcoming posts to make you learn different ways to attract and grab the Audience to your technology (Rasa chatbot for now).

In this post you will learn how to add the custom links to your Rasa chatbot so as to provide another way to interact with the user and to add extra features to the chatbot like the one that you will learn here is href links to redirect to the URLs.

Introduction

Link or we can also call it as hyperlink is an icon, graphic or text that links to the other webpage or URL. We have two ways of doing this, one is to directly display the link to the user to use further or to use it as the hyperlink and set any keyword as a reference to that link and that will hide the link from user. We will cover both the ways in this post and I’m sure you will love it when you will use it with your Rasa chatbot. Now let’s understand what actually happens when you add the links in your Rasa chatbot.

Working

When you add the links to your rasa chatbot what happens is rasa in the backend use it’s configuration file which we have with us as config.yml where there is a configuration for the regular function that checks wheather the specified text is a link or not if that part is a link then it will be highlighted and will be treated as a hyperlink just like you may have done in the html where we use the <a href= “link-to-the-webpage”> tag to create a link. By default if you don’t specify the keywork for the link then the complete link is treated as a keyword otherwise the key is used as a reference to the link.

To learn the practical implementation of this over video the check out this video session and be an expert in this topic.

Let’s learn how to implement it in Rasa. Before starting let’s keep one thing clear in our mind that what we are going to do in this post. For now let’s assume that chatbot(as waiter) and the user(as customer) is having a conversation to place the order and suddenly the customer asked the waiter that i would like to know more about your restaurant so the basic information a waiter can weasily give but to have a good impact for the restaurant the waiter decided to tell the customer about their restaurant’s official website so that the customer can check himself and get to know more and detailed about the restaurant. So, here is a small conversation for that that I’d like to add to my chat bot.

User: I would like to know more about your restaurant.

Chatbot: Here is a link for you to know more about our restaurant: “http://www.innovateyourself.in/

So, this is a small chat that we will add to our existing rasa chatbot that we have created till now from our previous post. From this above chat now you may have a basic idea that where we have to make futher changer for this chat to be implemented in our rasa chatbot. So, for this we will make changes in the nlu.md, domain.yml and stories.md file.

For the user text we have to create a new intent in the nlu.md file so that our rasa chatbot can understand the text said by us and for the text said by chatbot we have to make changes in the domain.yml file. For this conversation to work we have to add a new story to the existing story so that our chatbot and give response accordingly.

nlu.md file after adding the changes:

## intent: more_info
- i want to know about your website
- tell me more about your site
- what about your website
## intent:what_do_you_have
- what can i get here?
- what can i have to eat?
- what can i get for the lunch?
- what is this place famous for ?
## intent:vegetarian
- vegetarian
- pure veg
- pure veggie
- i want vegetarian food
## intent:non_veg
- non-veg
- non-vegetarian
- pure non-veg
## intent:order_name_veg
- get me 1 mix veg and paneer butter masala
- i want 1 mix veg and masala mushroom
- i want green salad
## intent:order_name_non_veg
- get me 1 egg curry and chicken butter masala
- i want 1 egg fry and fish curry
- i want 5 boiled eggs
## intent:greet
- hey
- hello
- hi
- good morning
- good evening
- hey there
## intent:goodbye
- bye
- goodbye
- see you around
- see you later
## intent:affirm
- yes
- indeed
- of course
- that sounds good
- correct
## intent:deny
- no
- never
- I don't think so
- don't like that
- no way
- not really
## intent:mood_great
- perfect
- very good
- great
- amazing
- wonderful
- I am feeling very good
- I am great
- I'm good
## intent:mood_unhappy
- sad
- very sad
- unhappy
- bad
- very bad
- awful
- terrible
- not very good
- extremely sad
- so sad
## intent:bot_challenge
- are you a bot?
- are you a human?
- am I talking to a bot?
- am I talking to a human?

stories.md file after adding the changes :

## happy veg path
* greet
  - utter_botgreet
* what_do_you_have
  - utter_veg_non_veg
* vegetarian
  - utter_veg
* order_name_veg
  - utter_anthingelse
* deny
  - utter_thanks
  
## happy non vegetarian path
* greet
  - utter_botgreet
* what_do_you_have
  - utter_veg_non_veg
* non_veg
  - utter_non_veg
* order_name_non_veg
  - utter_anthingelse
* deny
  - utter_thanks
## happy info path
* more_info
  - utter_info

Here I have added a seperate story for this conversation phrase so that it won’t create any interference with the other stories.

domain.yml file after adding the changes:

intents:
- greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge
- what_do_you_have
- vegetarian
- non_veg
- order_name_veg
- order_name_non_veg
- more_info
templates:
  utter_info:
  - text: “Here is the link to our website: http://www.innovateyourself.in/”
  utter_botgreet:
  - text: How can i help you sir?
  utter_veg_non_veg:
  - text: 'what would you prefer:'
    buttons:
    - title: Vegetarian
      payload: /vegetarian
    - title: Non-Vegetarian
      payload: /non_veg
  utter_veg:
  - text: 'Here are the meals for you:'
    image: https://youtu.be/qJDlttqmiXk
  utter_non_veg:
  - text: 'Here are the meals for you:'
    image: https://media-cdn.tripadvisor.com/media/photo-s/12/3e/7c/5f/non-veg-starters-menu.jpg
  utter_anthingelse:
  - text: Is there any thing else sir?
  utter_thanks:
  - text: Thanks. We will get your order shortly.
  utter_greet:
  - text: Hey! How are you?
  utter_cheer_up:
  - text: 'Here is something to cheer you up:'
    image: https://i.imgur.com/nGF1K8f.jpg
  utter_did_that_help:
  - text: Did that help you?
  utter_happy:
  - text: Great, carry on!
  utter_goodbye:
  - text: Bye
  utter_iamabot:
  - text: I am a bot, powered by Rasa.
actions:
- utter_greet
- utter_cheer_up
- utter_did_that_help
- utter_happy
- utter_goodbye
- utter_iamabot
- utter_botgreet
- utter_veg_non_veg
- utter_veg
- utter_non_veg
- utter_anthingelse
- utter_thanks
- utter_info

With this changes in the domain.yml file we will get the output like this:

and if the utter_info is written like this

utter_info:
  - text: Here is the link to our [website](http://www.innovateyourself.in/)

then your bot will give output like this:


So, these are the two ways how you can create or add the links in your rasa chatbot.

When you are done with this just train your model with the following code and run you chatbot in the terminal by typing the commands.

$ rasa train

$ rasa x

Output without hyperlink
Output with hyperlink

This is how your chatbot will work when you will run rasa x with your trained model. These are the images with and without the hyperlink.

I hope it was really helpful blog for you. But still if there are some queries related to the topic then leave a comment below in the comment section. Also provide your valuable feedback if you have like this post.

For any doubts or queries related to the topic, feel free to leave a comment below in the comment section. Also do comment your valuable feedback in the feedback so as to appreciate or improve ourselves.

Till then stay tuned and Enjoy learning.

Leave a Reply

Your email address will not be published. Required fields are marked *