Connect rasa to a web site

hello rasa friends, i have a issue, i need to connect a chatbot in a web site, so the problem it`s in the docs no have a really satisfactory response, i try with the 2 methods with the 2 plataform and i no have signal to the chat bot so i need the help

thanks your answers

hey @Robert14 checkout my github repo, it might help you…

GitHub - JiteshGaikwad/RASA-Chatbot-UI: A chat widget easy to connect to RASA core bot to custom channel

Hi Jitesh I went through your repository, I think you might be able to help me solve one of my problems. Can you have a look at Issue #1519 on rasa core repository. I am have trouble getting a response back for my custom actions.

hey @samarth12 can you show me your custom action file ?

Hey @JiteshGaikwad, below is my custom action file. It has two actions both making API calls to external APIs. I would like to remind you, assuming you have had a look at the issue on github that these actions are working perfectly fine on the cmdline. But I have made no extra changes to these actions for the RestInput.

from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet

class ActionWeather(Action):
	def name(self):
		return 'action_weather'
		
	def run(self, dispatcher, tracker, domain):
		from apixu.client import ApixuClient
		api_key = '166346e9c078430e8be180449183010' #your apixu key
		client = ApixuClient(api_key)
		
		loc = tracker.get_slot('location')
		current = client.getCurrentWeather(q=loc)
		
		country = current['location']['country']
		city = current['location']['name']
		condition = current['current']['condition']['text']
		temperature_c = current['current']['temp_c']
		humidity = current['current']['humidity']
		wind_mph = current['current']['wind_mph']

		response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format(condition, city, temperature_c, humidity, wind_mph)
						
		dispatcher.utter_message(response)
		return [SlotSet('location',loc)]

class Wolfram(Action):
	def name(self):
		return 'wolfram_alpha'
		
	def run(self, dispatcher, tracker, domain):
		import wolframalpha
		app_id = "GY456T-KJ5RKTA4W9"
		input = tracker.latest_message["text"]
		print(input)
		client = wolframalpha.Client(app_id)
		res = client.query(input)
		answer = next(res.results).text
		response = answer
		dispatcher.utter_message(response)
		return

Let me know if you need any other details. Thanks!

hey @samarth12 i think so error occors in the Wolfram class, might be error occurs while u import the wolframalpha or some error while you call the api from Wolfram class, can you do one thing when ever face the error while running the bot, can u send me the logs of actions sdk server? might be it help for checking the issue :sweat_smile:

@JiteshGaikwad I don’t think it has something to do with the Wolfram API. That is doing its job perfectly fine when it is called. And I get the same error, nothing is returned even when I call the weather API which is picked up from a RASA example video. I will post my action sdk server and localhost server logs below.

Actions sdk just returns a 404 error whenever the APIs need to be called, the thing I do not get is that works perfectly fine on the cmdline.

INFO:__main__:Starting action endpoint server...
INFO:rasa_core_sdk.executor:Registered function for 'action_weather'.
INFO:rasa_core_sdk.executor:Registered function for 'wolfram_alpha'.
INFO:__main__:Action endpoint is up and running. on ('0.0.0.0', 5055)
127.0.0.1 - - [2019-01-01 12:00:27] "POST /webhook/ HTTP/1.1" 404 342 0.009915
127.0.0.1 - - [2019-01-01 12:00:53] "POST /webhook/ HTTP/1.1" 404 342 0.001687

Here is my localhost logs

2019-01-01 12:00:27 ERROR    rasa_core.actions.action  - Failed to run custom action 'action_weather'. Action server responded with a non 200 status code of 404. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 404 Client Error: NOT FOUND for url: http://localhost:5055/webhook/
2019-01-01 12:00:27 ERROR    rasa_core.processor  - Encountered an exception while running action 'action_weather'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
127.0.0.1 - - [2019-01-01 12:00:27] "POST /webhooks/rest/webhook HTTP/1.1" 200 142 0.077290
2019-01-01 12:00:53 WARNING  py.warnings  - /anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
  if diff:

2019-01-01 12:00:53 ERROR    rasa_core.actions.action  - Failed to run custom action 'wolfram_alpha'. Action server responded with a non 200 status code of 404. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 404 Client Error: NOT FOUND for url: http://localhost:5055/webhook/
2019-01-01 12:00:53 ERROR    rasa_core.processor  - Encountered an exception while running action 'wolfram_alpha'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
127.0.0.1 - - [2019-01-01 12:00:53] "POST /webhooks/rest/webhook HTTP/1.1" 200 142 0.073290

You can see I tried calling both the APIs and get the same error. Also if I didn’t mention before, everything other than API calls is returning a response on postman like it should.

Here are more detailed logs. My first input is: “Hello my name is Mark”. I get a response back, my next input is:“Who is the president of US?” where it should call the wolfram api. The same thing happens with weather api if I change my input to: “What is the weather in London?”

2019-01-01 12:18:44 INFO     root  - Rasa Core server is up and running on http://localhost:5005
Bot loaded. Type a message and press enter (use '/stop' to exit): 
2019-01-01 12:18:57 DEBUG    rasa_core.tracker_store  - Creating a new tracker for id 'Rasa'.
2019-01-01 12:18:57 WARNING  py.warnings  - /anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
  if diff:

2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Received user message 'Hello my name is Mark' with intent '{'name': 'greet', 'confidence': 0.5992243649211548}' and entities '[{'start': 17, 'end': 21, 'value': 'mark', 'entity': 'PERSON', 'confidence': 0.6440988744205052, 'extractor': 'ner_crf'}]'
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Logged UserUtterance - tracker now has 3 events
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Current slot values: 
	PERSON: mark
	location: None
2019-01-01 12:18:57 DEBUG    rasa_core.policies.memoization  - Current tracker state [None, None, None, {}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:18:57 DEBUG    rasa_core.policies.memoization  - There is no memorised next action
2019-01-01 12:18:57 DEBUG    rasa_core.policies.ensemble  - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Predicted next action 'utter_greet' with prob 0.30.
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Action 'utter_greet' ended with events '[]'
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Bot utterance 'BotUttered(text: Hello mark! How can I help?, data: {
  "elements": null,
  "buttons": null,
  "attachment": null
})'
2019-01-01 12:18:57 DEBUG    rasa_core.policies.memoization  - Current tracker state [None, None, {}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'prev_utter_greet': 1.0, 'entity_PERSON': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:18:57 DEBUG    rasa_core.policies.memoization  - There is no memorised next action
2019-01-01 12:18:57 DEBUG    rasa_core.policies.ensemble  - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Predicted next action 'action_listen' with prob 0.87.
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Action 'action_listen' ended with events '[]'
127.0.0.1 - - [2019-01-01 12:18:57] "POST /webhooks/rest/webhook HTTP/1.1" 200 203 0.257879
2019-01-01 12:19:51 DEBUG    rasa_core.tracker_store  - Recreating tracker for id 'Rasa'
2019-01-01 12:19:52 WARNING  py.warnings  - /anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
  if diff:

2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Received user message 'Who is the president of US' with intent '{'name': 'information', 'confidence': 0.6909834200535575}' and entities '[]'
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Logged UserUtterance - tracker now has 7 events
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Current slot values: 
	PERSON: mark
	location: None
2019-01-01 12:19:52 DEBUG    rasa_core.policies.memoization  - Current tracker state [None, {}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'prev_utter_greet': 1.0, 'entity_PERSON': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'intent_information': 1.0, 'prev_action_listen': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:19:52 DEBUG    rasa_core.policies.memoization  - There is no memorised next action
2019-01-01 12:19:52 DEBUG    rasa_core.policies.ensemble  - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Predicted next action 'wolfram_alpha' with prob 0.70.
2019-01-01 12:19:52 DEBUG    rasa_core.actions.action  - Calling action endpoint to run action 'wolfram_alpha'.
2019-01-01 12:19:52 ERROR    rasa_core.actions.action  - Failed to run custom action 'wolfram_alpha'. Action server responded with a non 200 status code of 404. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 404 Client Error: NOT FOUND for url: http://localhost:5055/webhook/
2019-01-01 12:19:52 ERROR    rasa_core.processor  - Encountered an exception while running action 'wolfram_alpha'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Failed to execute custom action.
Traceback (most recent call last):
  File "/anaconda3/lib/python3.6/site-packages/rasa_core/actions/action.py", line 338, in run
    response.raise_for_status()
  File "/anaconda3/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: NOT FOUND for url: http://localhost:5055/webhook/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/anaconda3/lib/python3.6/site-packages/rasa_core/processor.py", line 351, in _run_action
    events = action.run(dispatcher, tracker, self.domain)
  File "/anaconda3/lib/python3.6/site-packages/rasa_core/actions/action.py", line 358, in run
    raise Exception("Failed to execute custom action.")
Exception: Failed to execute custom action.
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Action 'wolfram_alpha' ended with events '[]'
2019-01-01 12:19:52 DEBUG    rasa_core.policies.memoization  - Current tracker state [{}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'prev_utter_greet': 1.0, 'entity_PERSON': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'intent_information': 1.0, 'prev_action_listen': 1.0, 'slot_PERSON_0': 1.0}, {'intent_information': 1.0, 'prev_wolfram_alpha': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:19:52 DEBUG    rasa_core.policies.memoization  - There is no memorised next action
2019-01-01 12:19:52 DEBUG    rasa_core.policies.ensemble  - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Predicted next action 'action_listen' with prob 0.98.
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Action 'action_listen' ended with events '[]'
127.0.0.1 - - [2019-01-01 12:19:52] "POST /webhooks/rest/webhook HTTP/1.1" 200 142 0.094410

@JiteshGaikwad hi there jitesh i really appreciate you git hub post i`m going to test it and i write any question what i have,

greeting :wink:

thanks @Robert14

@JiteshGaikwad hi dude i have a issue i am testing the chat and everything is awesome but when i tried to check te button don`t appear

greetings :wink:

hey @Robert14 i haven’t wrote the js code to handle the buttons soon i will add that too

1 Like

oh, ok @JiteshGaikwad, i love the chat, i will be checking while your finish the js, i really appreciate your answer, thank you a lot

greetings :wink:

Hi @JiteshGaikwad I’m using your chatbot-UI when I use payload buttons for example:

utter_did_that_help:

  • text: “Did that help you?” buttons:
    • title: “Yes” payload: “/utter_happy”
    • title: “No” payload: “/utter_goodbye”

utter_happy:

  • text: “Great, carry on!” utter_goodbye:
  • text: “Bye”

If I select Yes in UI the payload will be “/utter_happy” but the response of the BOT is invalid. It’s going to default. I can see to select the payload on click of suggestions you have added:

// on click of suggestions, get the value and send to rasa $(document).on(“click”, “.menu .menuChips”, function () { var text = this.innerText; var payload = this.getAttribute(‘data-payload’); console.log(“payload: “, this.getAttribute(‘data-payload’)) setUserResponse(text); send(payload); //delete the suggestions once user click on it $(”.suggestions”).remove(); });

Can you please take a look into this?

Thanks

The payload should be your intent not the utterance. So if you don’t have an utter_happy intent, you will have an error.

yes, thank you for pointing that out. it’s working now

Please ! i need your help