Greeting I am working on RASA chatbot. I am handling Custom actions for a particular intent using below code. In the custom action I want to get current intent value. SO i dont know that line of code which can give me value of current intent
#this file will be used to all custom actions
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import requests
import json
from zeep import Client
from random import randint
from rasa_core.actions.action import Action
from rasa_core.events import SlotSet
class ActionWeather(Action):
RANDOMIZE = False
@staticmethod
def required_fields():
return [
EntityFormField("period", "period"),
EntityFormField("product", "product")
]
def name(self):
return 'action_weather'
def run(self,dispatcher, tracker, domain):
#Get Slot values
loc = tracker.get_slot('period')
pro = tracker.get_slot('product')
custname= tracker.get_slot('custName')
#Here I want to get Intent Values as well same like slot value in above code
# So what is code for getting intent value
#make json
data = {}
data['period'] = loc
data['product'] = pro
json_data = json.dumps(data)
jsonobj= json.loads(json_data)
#code for SOAP
client = Client('my webservice URL/testsoap?wsdl')
result = client.service.getData(json_data)
print('**********************')
print(result)
print('#######################')
jsonobj= json.loads(result)
#print(response.content)
#json_response = response.json()
#print (json_response)
result1=jsonobj[0]['result']
#result1=randint(1, 100)
#result='X'
response = """sale is {} """.format(result1)
dispatcher.utter_message(response)
#return [SlotSet('location',loc)]
return []
I want to get current and last value of intent in RASA Core in same way as we can get slots value product = tracker.get_slot('product')
in python custom action code. Please help.
This works for me:
def run(self,dispatcher, tracker, domain):
intent = tracker.latest_message['intent'].get('name')
rasa-core 0.11.12
rasa-core-sdk 0.11.5
rasa-nlu 0.13.7
intent = json.dumps(tracker.latest_message.intent)
print(intent)
#particular intent name
print(json.loads(intent)['intent']['name'])
outcome (u'{"confidence": 0.9092543377510975, "name": "greet"}')
or try this
intent = json.dumps(tracker.latest_message.__dict__)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With