# Rasa integration with website

**URL:** <https://forum.rasa.com/t/rasa-integration-with-website/53253>\
**Category:** Rasa Open Source\
**Created:** [May 18, 2022, 5:58am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253 "2022-05-18T05:58:01Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![SUMANA](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@SUMANA](https://forum.rasa.com/u/SUMANA)\
**Post date:** [May 18, 2022, 5:58am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/1 "2022-05-18T05:58:01Z")

</div>

Hi, How can use the web address of the Rasa webchat (HTML page) to scrape information from this HTML ? or is there any way to get (collect) information from the rasa conversation?

---

<div class="post-metadata">

**Author:** ![vio\_lovis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/vio_lovis/32/17910_2.png) [@vio\_lovis](https://forum.rasa.com/u/vio_lovis)\
**Post date:** [May 18, 2022, 6:34am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/2 "2022-05-18T06:34:08Z")

</div>

Hi,  
what kind of information do you want to collect? The conversations are stored and you can review them for instance by using Rasa X. If you are looking to extract very specific informations you can use a form, fill the slots and write them into a Google Sheet.  
Could you provide some more information on what you are trying to achieve?  
Ciao, Vio

---

<div class="post-metadata">

**Author:** ![v\_kostis](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@v\_kostis](https://forum.rasa.com/u/v_kostis)\
**Post date:** [May 18, 2022, 5:53pm UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/3 "2022-05-18T17:53:02Z")

</div>

Hi @SUMANA,

**I’m guessing that you want to search the html after a specific question of the user.** You can use a custom action for that. Specify the intent, and then define a custom action to parse the html. I usually use BeautifulSoup to parse html pages.

You can just use rasa open source. You do not need to use rasa x.

Below is some code from on of my recent projects. Note that this code is not from the actions.py file, since I have a separate py file to parse the desired html page.

```auto
from bs4 import BeautifulSoup
import requests

def ParseHTML():
	url = f"your_url_here"
	page = requests.get(url)
	status = page.status_code
	valid = 0
	if status == 200:
		soup = BeautifulSoup(page.text, 'html.parser')
		delivered = soup.find_all(class_="name_of_a_desired_class_in_html")
		if delivered:
			valid = 1
		else:
			valid = 0
	else:
		valid = -2
	return valid

```

Hope it helps.

Thanks!

---

<div class="post-metadata">

**Author:** ![SUMANA](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@SUMANA](https://forum.rasa.com/u/SUMANA)\
**Post date:** [May 19, 2022, 12:33am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/4 "2022-05-19T00:33:54Z")

</div>

Hi Violetta, Thanks for your response. My project is, to integrate RASA with an external Python code. In elaboration, in the integration, the RASA command will be used as an input in the python code.

As an example, in the conversation, I asked RASA to change the value of apple to 3. The RASA command is: The value of an apple is 3. And this “value of apple” is the input of the Python code. From the RASA command, it will take the value which is 3 in that case, and run the algorithm (Python code).

In that case, I made a rasa webchat for the conversation and tried to apply a python code to get the specific information for example the value of the apple. However, when I am using the web address of the webchat (HTML page) in the python code as shown below, it’s giving me an error. Code: import requests

url = “file:///C:…index.html”

print(url)

r = requests.get(url)

Error: InvalidSchema: No connection adapters were found for “file:///C:…index.html”

I am new in Rasa and not sure whether I am heading the right way or not.

---

<div class="post-metadata">

**Author:** ![SUMANA](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@SUMANA](https://forum.rasa.com/u/SUMANA)\
**Post date:** [May 19, 2022, 3:57am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/5 "2022-05-19T03:57:25Z")

</div>

Hi Kostis,  
Thanks for your response and the code. Yes, I want to search the HTML after a specific question of the user. However, still, I am unable to get the information from the HTML page (rasa webchat).

---

<div class="post-metadata">

**Author:** ![vio\_lovis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/vio_lovis/32/17910_2.png) [@vio\_lovis](https://forum.rasa.com/u/vio_lovis)\
**Post date:** [May 19, 2022, 7:56am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/6 "2022-05-19T07:56:02Z")

</div>

Hi @SUMANA,  
I am sorry, I am still not sure, I got you correctly. 🤷‍♀️ But couldn’t you set a slot for value of the apple? And then write a custom action, that gets you that slot and writes it into a file from where you can access it? The Sara Demo Bot [here](https://github.com/RasaHQ/rasa-demo/blob/master/actions/actions.py#L31) collects the slots and writes them into a Google Sheets.   
Hope the example might help you!  
Ciao

---

<div class="post-metadata">

**Author:** ![v\_kostis](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@v\_kostis](https://forum.rasa.com/u/v_kostis)\
**Post date:** [May 19, 2022, 8:12am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/7 "2022-05-19T08:12:33Z")

</div>

Hi @SUMANA ,

The ‘requests’ library I mentioned in my previous post is an HTTP library. Since you have an html file locally, you can open and read the file.

```auto
f = open("file:///C:…index.html", "r")
print(f.read())

```

This will print the content of your file.

Afterwards, I agree with Violetta. The “value of apple” shold be stored in a slot. Afterwards, you can create a custom action to do anything you want with it, such as store it in Google Sheets, write it to a file, or anything else you want.

---

<div class="post-metadata">

**Author:** ![SUMANA](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@SUMANA](https://forum.rasa.com/u/SUMANA)\
**Post date:** [May 24, 2022, 1:55am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/8 "2022-05-24T01:55:12Z")

</div>

Hi,

Thanks @v_kostis for showing me the right track. I have one more query, can I use an external python code as a custom action and the output of the code will be the rasa command (bot uttered)?

---

<div class="post-metadata">

**Author:** ![SUMANA](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@SUMANA](https://forum.rasa.com/u/SUMANA)\
**Post date:** [May 24, 2022, 1:56am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/9 "2022-05-24T01:56:16Z")

</div>

Thanks for your suggestions.

---

<div class="post-metadata">

**Author:** ![v\_kostis](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@v\_kostis](https://forum.rasa.com/u/v_kostis)\
**Post date:** [May 24, 2022, 9:29pm UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/10 "2022-05-24T21:29:25Z")

</div>

Hi @SUMANA, it is possible, but I **personally** think that you could/ should include your external python code in your custom action. Nevertheless, you can call an external python file if required. The command for python 3.X is presented below:

First, import the .py file in actions.py file

> import your\_python\_file.py

Afterwards, in your custom action, you can call the below command:

> exec(open(“your\_python\_code.py”).read())

You can sane the above command to a variable, and then utter the variable.

Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![SUMANA](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@SUMANA](https://forum.rasa.com/u/SUMANA)\
**Post date:** [June 2, 2022, 12:19am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/11 "2022-06-02T00:19:47Z")

</div>

## Hi Kostis, Thank you so much. However, still I can’t solve the problem. Below is my action.py code

from typing import Any, Text, Dict, List

from rasa\_sdk import Action, Tracker

from rasa\_sdk.executor import CollectingDispatcher

import CV.py

class ActionHelloWorld(Action):

```
def name(self) -> Text:
     return "action_hello_world"

def run(self, dispatcher: CollectingDispatcher,
         tracker: Tracker,
         domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

    mu_rate = tracker.get_slot("mutation")
    co_rate = tracker.get_slot("crossover")

    print(mu_rate)
    print(co_rate)
    
    result=exec(open(CV.py).read())
    
    message = “The output score is = {}”.format(result)

    dispatcher.utter_message(text=message)

    return [AllSlotsReset ()]

```

* * *

I need the value of the two variables “mu\_rate” and “co\_rate” to execute the CV.py code wherein the CV.py code I define: m=mu\_rate and c=co\_rate But it’s not working. Do I need a Followup action in this case.

It will be highly appreciated if you kindly help me.

---

<div class="post-metadata">

**Author:** ![v\_kostis](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@v\_kostis](https://forum.rasa.com/u/v_kostis)\
**Post date:** [June 2, 2022, 3:48pm UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/12 "2022-06-02T15:48:17Z")

</div>

Hi @SUMANA,

Could you please elaborate on the below?

> [@SUMANA](#):
>
> I need the value of the two variables “mu\_rate” and “co\_rate” to execute the CV.py code wherein the CV.py code I define: m=mu\_rate and c=co\_rate

You mean that CV.py take as arguments “mu\_rate” and “co\_rate”? Meaning those variables can change the outcome of the CV.py?

---

<div class="post-metadata">

**Author:** ![SUMANA](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@SUMANA](https://forum.rasa.com/u/SUMANA)\
**Post date:** [June 3, 2022, 1:17am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/13 "2022-06-03T01:17:48Z")

</div>

Yes, you are right.

---

<div class="post-metadata">

**Author:** ![SUMANA](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@SUMANA](https://forum.rasa.com/u/SUMANA)\
**Post date:** [June 6, 2022, 4:57am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/14 "2022-06-06T04:57:59Z")

</div>

Hi All, I need help. My stories (“parameter tuning path”) are not working properly. My codes are below:

nlu.yml: version: “3.1”

nlu:

- intent: greet

- intent: goodbye

- intent: affirm

- intent: deny

- intent: mood\_great

- intent: mood\_unhappy

- intent: parameter\_tuning\_mu

- intent: crossover\_parameter\_tuning

- intent: bot\_challenge

Domain.yml: version: “3.1”

intents:

- greet
- goodbye
- affirm
- deny
- mood\_great
- mood\_unhappy
- bot\_challenge
- parameter\_tuning\_mu
- crossover\_parameter\_tuning

entities:

- parameter
- value

slots:

parameter:

```
type: float

mappings:

- type: from_entity

  entity: parameter

```

value:

```
type: float

mappings:

- type: from_entity

  entity: value

```

actions:

- action\_hello\_world

responses:

utter\_greet:

- text: “Hey! How are you?”

utter\_cheer\_up:

- text: “Here is something to cheer you up:”

utter\_did\_that\_help:

- text: “Did that help you?”

utter\_happy:

- text: “Great, carry on!”

utter\_goodbye:

- text: “Bye”

utter\_ask\_mutation\_rate:

- text: “What will be the next parameter?”

utter\_ask\_crossover\_rate:

- text: “What will be the next value?”

utter\_next:

- text: “ok, what is next?”

utter\_iamabot:

- text: “I am a bot, powered by Rasa.”

session\_config:

session\_expiration\_time: 60

carry\_over\_slots\_to\_new\_session: true

**Stories.yml:** version: “3.1”

stories:

- story: happy path

- story: sad path 1

- story: sad path 2

- story: parameter tuning path

action.py: from typing import Any, Text, Dict, List

from rasa\_sdk.events import SlotSet

from rasa\_sdk import Action, Tracker

from rasa\_sdk.executor import CollectingDispatcher

class ActionHelloWorld(Action):

```
def name(self) -> Text:

     return "action_hello_world"

def run(self, dispatcher: CollectingDispatcher,

         tracker: Tracker,

         domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

    mutation = tracker.get_slot("parameter")

    crossover = tracker.get_slot("value")

     

    print(mutation)

    print(crossover)

    dispatcher.utter_message(text="All done")

    return [SlotSet()]

```

* * *

Bot response stopped when I asked something from the intent parameter\_tuning\_mu.

Bot response: Bot loaded. Type a message and press enter (use ‘/stop’ to exit): Your input → hello  
Hey! How are you? Your input → so good  
Great, carry on! Your input → set the mutation  
Your input →

* * *

Your help is highly appreciated.

---

<div class="post-metadata">

**Author:** ![SUMANA](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@SUMANA](https://forum.rasa.com/u/SUMANA)\
**Post date:** [June 21, 2022, 12:52am UTC](https://forum.rasa.com/t/rasa-integration-with-website/53253/15 "2022-06-21T00:52:38Z")

</div>

Hi Kostis, it will be highly appreciated if you kindly help me to solve the problem. The slot value only taking ‘None’. I went through several discussion in Rasa forum. However, can’t solve my problem. I put my queries in Rasa forum but did not get any response yet. I have tried all possibility to fix it but nothing working. I am not sure what I am missing.

* * *

Slots in domain file: entities:

- parameter

slots:

parameter:

```
type: float

min_value: 0.00

max_value: 1.00

mappings:

- type: from_entity

  entity: parameter

```

* * *

Stories:

- story: parameter tuning path

* * *

action.py: from typing import Any, Text, Dict, List

from rasa\_sdk.events import SlotSet

from rasa\_sdk import Action, Tracker

from rasa\_sdk.executor import CollectingDispatcher

class ActionAskParameter(Action):

```
def name(self) -> Text:

     return "action_ask_parameter"

def run(self, dispatcher: CollectingDispatcher,

         tracker: Tracker,

         domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

    parameter = tracker.get_slot("parameter")

    float_parameter = parameter

    print(float_parameter)

    type(float_parameter)

    if float_parameter is not None:

       

       parameter = ("parameter", parameter)

       
 
   

    return []

```

* * *

## 022-06-20 11:58:59 DEBUG rasa.core.processor - Policy prediction ended with events ‘[\<rasa.shared.core.events.DefinePrevUserUtteredFeaturization object at 0x0000027255ACD128\>]’. 2022-06-20 11:58:59 DEBUG rasa.core.processor - Action ‘action\_ask\_parameter’ ended with events ‘’. 2022-06-20 11:58:59 DEBUG rasa.core.processor - Current slot values: parameter: None session\_started\_metadata: None

Please help me.
