How to integrate Dynamic links in Rasa chatbot

In this era where technology is advancing every second where lagging behind means your life stuck at this stage. So being static is like being a stone that doesn’t move itself.

To be the part of this era and to be the one to be known and to be successful, you have to be dynamic so as our inventions too. For this specific reason you are here to learn how to be dynamic and to do dynamic inventions.

In this post, you will learn all about the actions in Rasa and also how to use the actions file with Rasa chatbot. Also, you will learn how to modify it in the domain and the stories file to make it work and how to add the dynamic links to the Rasa chatbot so as to update it in real-time, unlike the static links.

To watch this full tutorial and it’s working in action the do check out this session to know more.

Introduction

Dynamic Links are links that work the way you want, on multiple platforms, and whether or not your app is already installed. With Dynamic Links, your users get the best available experience for the platform they open your link on.

In this post, you will understand how to update the rasa chatbot files to get this task done. For this task, we have to add the actions.py file and also to start the actions server to get this part done.

Now what is actions in rasa and how to use it here?

Actions are the things your bot runs in response to user input. There are four kinds of actions in Rasa:

  • Utterance actions: start with utter_ and send a specific message to the user
  • Retrieval actions: start with respond_ and send a message selected by a retrieval model
  • Custom actions: run arbitrary code and send any number of messages (or none).
  • Default actions: e.g. action_listen, action_restart, action_default_fallback

Working

In the previous posts, we may have seen how to use the actions in response to the user’s input for example utter_greet. So this was one of the actions that we have set for the bot to reply in response to the user’s input. Similarly, there are other actions as well that we will see in today’s post as well as in the upcoming posts. In this post, we will learn how to use the custom actions for the bot’s response. An example of the custom actions is actions_hello_world.

Now to create a custom action we have to add the custom python script and also to update the stories as per the actions created in the actions.py fil. Domain file will also be updated to add the dynamic link to make th change in the bot’s response in real time.

Firstly, we will update the actions.py file that was created during the initialization of the project. For the first time when you will see your actions.py file, you will notice that all the lines have been commented and there is nothing that will work. So to make it work we will update the actions.py file and for now, add the following lines of code in the actions.py file:

from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
class ActionHelloWorld(Action):
def name(self) -> Text:
return "action_dynamic_link"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
Link="http://www.innovateyourself.in/"
# dispatcher.utter_message(text="Hello World!")
print("Link: ",tracker.get_slot('LINK'))
text=tracker.latest_message['text']
print(text)
dispatcher.utter_template("utter_info",tracker,link=Link)
return []

and along with this, you have to update the endpoints.yml file to make this action file sun and also to start the action server. In the endpointys.yml file uncomment the following lines and save the file:

action_endpoint:
url: "http://localhost:5055/webhook"

If you are not food at python and don’t wanna miss this amazing topic then I have a good news for you. Here is a link for you to learn python on your own so that you will miss any topic of this amazing session. To learn python programming check out this link:

Now when you have created the actions in the actions.py file now update the domain.yml file as per the actions created. Add the following lines in the actions block in the domain.yml file:

actions:
- action_dynamic_link

Also, you have to update the utter_ template where you want to add the dynamic link that will make changes in real-time

templates:
utter_info:
- text: Here is the link to our website {link}

When the domain file is updated it’s time to update the stories as per the actions specified and updated. As per our conversation between the bot we have to make changes in the stories.md file in such a way:

## happy info path
* more_info
- action_dynamic_link

As this story was a separate part of the complete conversational flow so this story was created separately without conflicting the other stories.

In this way, we have updated the complete rasa chatbot. Now it’s time to train the model and to check its working in real-time.

$ rasa train
$ rasa x

The output for the above changes will look something like this:

So this was it for this post I hope every this was very clear to you but still if you are having any doubts or queries related to the topic, feel free to leave a comment below in the comment section. Also, do comment on your valuable feedback in the comment section so as to appreciate/improve ourselves. For any further information or queries, you can also WhatsApp me at +91 8209829808.

Till then stay tuned and happy learning 🤗

Leave a Reply

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