I think I founded an way using default-actions
I create a custom action to event listen
This action check the slot is_auth
If not authentication the action check if user can see this intent, defined in show_without_authentication
In this case, the user don’t need to make login to see help_login
intent
If not authenticate AND not can see the intent, the action send “utter_please_make_login”
action.py
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SessionStarted,UserUtteranceReverted,ConversationPaused,ConversationResumed
class ActionActionListen(Action):
def name(self) -> Text:
return "action_listen"
async def run(
self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]
) -> List[Dict[Text, Any]]:
print('---- CUSTOM action_action_listen ----')
is_auth = tracker.get_slot('is_auth')
show_without_authentication = ['help_login']
if not is_auth:
_response = None
current_intent = tracker.latest_message['intent'].get('name')
if current_intent in show_without_authentication:
_response = current_intent
else:
_response = "utter_please_make_login"
dispatcher.utter_message(response=_response)
return []
return [dispatcher, tracker, domain]
The rules:
I didn’t find any way to cancel rules action in python action.
Need to use condition to check the slot
rules.yml
version: "2.0"
rules:
- rule: Say goodbye anytime the user says goodbye
condition:
- slot_was_set:
- is_auth: True
steps:
- intent: goodbye
- action: utter_goodbye
- rule: Say 'I am a bot' anytime the user challenges
condition:
- slot_was_set:
- is_auth: True
steps:
- intent: bot_challenge
- action: utter_iamabot
- rule: Say 'I am a bot' anytime the user challenges
condition:
- slot_was_set:
- is_auth: False
steps:
- intent: help_login
- action: utter_help_login
my domain.yml
version: "2.0"
intents:
- greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge
- help_login
slots:
is_auth:
type: bool
initial_value: False
auto_fill: False
influence_conversation: true
responses:
utter_greet:
- text: "Hey! How are you?"
utter_cheer_up:
- text: "Here is something to cheer you up:"
image: "https://i.imgur.com/nGF1K8f.jpg"
utter_did_that_help:
- text: "Did that help you?"
utter_happy:
- text: "Great, carry on!"
utter_goodbye:
- text: "Bye"
utter_please_make_login:
- text: "Please make login. type **help** for more informations"
utter_iamabot:
- text: "I am a bot, powered by Rasa."
utter_help_login:
- text: 'type login true to make the login'
actions:
- action_listen
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
config.yml
# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: en
pipeline:
policies:
- name: RulePolicy
I zip my project to test and make this way better
I’m using rasa 2.8.27
Use rasa train --force
rasa2-8.zip (10.5 KB)
References:
---- Edit -----
when i set Policies the solution stop to working
policies:
- name: MemoizationPolicy
- name: TEDPolicy
max_history: 5
epochs: 200
- name: RulePolicy