How to return json response from custom action/custom action server


(Susheelks) #1

Hello RASA Community,

I have two similar questions and appreciate your comments/suggestions.

  • How to return a json from custom action. currently I am doing using below converting json to string and using utter_message to return the response but I believe that’s not the best efficient way

class ActionSearchTrackingID(Action): def name(self): # define the name of the action which can then be included in training stories return “action_search_trackingID”

def run(self, dispatcher, tracker, domain):
    # what your action should do
    query = 'field:' + tracker.get_slot('ID')
    request = requests.get('http://localhost:8983/solr/coll/select?indent=on&q=' + query + '&wt=json').text #make an apie call
    dispatcher.utter_message(request) #send the message back to the user
    return []
  • If you Action server is outside python, I am able to call and there also how to return the json response. Currently I am using below text field to put String json but again that may not be the best way

{ “events”: [], “responses”: [ {“text”: “json as string”} ] }


(Susheelks) #2

Hello, can anyone suggest how to return json part of response from Action server that consumer can consumer it


(Susheelks) #3

Hello,

Can anyone tell me how to return a json data from custom action server outside python.

Thnx


(noman) #4

Did you find the answer? as i am facing the same problem


(Susheelks) #5

No, couldn’t and then i changed my plan to use NLU intent then core directly