Looking for a basic database connection working example

Hello!

I have been playing around with the RASA stack and I understand the basics. I have also realised the power of custom actions. I am able to make API calls for my bot. Can anybody point me in the right direction here, I am trying to connect my bot to a basic database where I can fetch information the user is trying to retrieve from the bot. I am not sure how that is integrating with RASA, will that be another custom action?

hey @samarth12,as a suggestion, you can create a api to get data from you database which user requested. :sweat_smile:

Hello,

Like @JiteshGaikwad suggested, API is the best way to connect to a database rather than directly accesing it. We use MongoDB with our RASA bot. We use APIs to connect.

Thank you guys! Would you rather suggest using Flask-PyMongo/Flask-MongoAlchemy kind of libraries to do that job? My question is using these libraries directly in my custom action would run and connect RASA to the database?

hey @samarth12 you can use mysql directly into your custom action :

https://www.w3schools.com/python/python_mysql_select.asp

Yes, you could use both of them if you want to directly connect to your database. I use APIs fro RASA but for my other applications I often use Flask-PyMongo. The answer to your second question is yes, you will be able to directly connect to your DB from the custom actions.

Hello all,

Can you please help me to create a custom action in rasa core ?

I have tried but getting some exceptions when trying to train rasa core . Please find the below details i have modified -

ActionTest.py

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

from rasa_core.actions.action import Action
class ActionTest(Action):
    def name(self):
        return 'action_get_weather'

    def run(self, dispatcher, tracker, domain):

        dispatcher.utter_message('We did not find any weather information for Search by a city name.')
        return

domain.yml

..
actions:
# templates (as they are reply actions),
# also custom actions if any
 - utter_greet
 - utter_answer_31_days
 - utter_answer_30_days
 - utter_answer_28_days
 - utter_bye
 - actions.ActionTest

stories.md

## story6
* greet
  - action_test

During training am getting the below error -

  domains action list. If you recently removed an action, don't worry about this warning. It should stop appearing after a while. 
2018-12-22 20:35:09 WARNING  rasa_core.domain  - Failed to use action 'action_test' in history. Please make sure all actions are listed in the domains action list. If you recently removed an action, don't worry about this warning. It should stop appearing after a while. 
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/rasa_core/domain.py", line 314, in index_for_action
    return self.action_names.index(action_name)
ValueError: 'action_test' is not in list

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/site-packages/rasa_core/train.py", line 358, in <module>
    additional_args)
  File "/usr/local/lib/python3.6/site-packages/rasa_core/train.py", line 273, in do_default_training
    kwargs=additional_arguments)
  File "/usr/local/lib/python3.6/site-packages/rasa_core/train.py", line 197, in train_dialogue_model
    agent.train(training_data, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rasa_core/agent.py", line 536, in train
    **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rasa_core/policies/ensemble.py", line 67, in train
    policy.train(training_trackers, domain, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rasa_core/policies/keras_policy.py", line 154, in train
    **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rasa_core/policies/policy.py", line 74, in featurize_for_training
    domain)
  File "/usr/local/lib/python3.6/site-packages/rasa_core/featurizers.py", line 406, in featurize_trackers
    y = self._featurize_labels(trackers_as_actions, domain)
  File "/usr/local/lib/python3.6/site-packages/rasa_core/featurizers.py", line 373, in _featurize_labels
    for action in tracker_actions]
  File "/usr/local/lib/python3.6/site-packages/rasa_core/featurizers.py", line 373, in <listcomp>
    for action in tracker_actions]
  File "/usr/local/lib/python3.6/site-packages/rasa_core/featurizers.py", line 62, in action_as_one_hot
    y[domain.index_for_action(action)] = 1
  File "/usr/local/lib/python3.6/site-packages/rasa_core/domain.py", line 316, in index_for_action
    self._raise_action_not_found_exception(action_name)
  File "/usr/local/lib/python3.6/site-packages/rasa_core/domain.py", line 325, in _raise_action_not_found_exception
    "".format(action_name, action_names))
NameError: Cannot access action 'action_test', as that name is not a registered action for this domain. Available actions are: 
	 - action_listen
	 - action_restart
	 - action_default_fallback
	 - action_deactivate_form
	 - utter_greet
	 - utter_answer_31_days
	 - utter_answer_30_days
	 - utter_answer_28_days
	 - utter_bye
	 - actions.ActionTest

Can someone help me ? Thanks in advance

Hi @sandeepkumarsahoo, you’ve named your ActionTest class action as ‘action_get_weather’. Use that name to refer your action in the domain and story file.

Just replace actions.ActionTest in domain.yml and action_test is stories.md by ‘action_get_weather’.

@samarth12 yes that was the issue.,and also I forgot to add action_endpoints in endpoints.yml file. Thanks